Browse Source

CMake generator based on Jinja generator
99902937b544f5d8150a5c6132861e1bb52d3ced

dimdim11 10 months ago
parent
commit
efb3665db2

+ 2 - 2
build/conf/bison_lex.conf

@@ -134,7 +134,7 @@ macro USE_OLD_FLEX() {
 macro _SRC("y", SRC, SRCFLAGS...) {
     .PEERDIR=contrib/tools/bison/bison/induced
     .CMD=${tool:"contrib/tools/bison/bison"} $BISON_FLAGS --m4=${tool:"contrib/tools/bison/m4"} $_BISON_HEADER ${hide:_BISON_GEN_EXT} -o ${nopath;output;suf=$_BISON_GEN_EXT:SRC} ${input:SRC} ${SRCFLAGS} ${kv;hide:"p YC"} ${kv;hide:"pc light-green"} && $_BISON_PP
-    .SEM=target_bison_parser PRIVATE ${input:SRC} ${output;nopath;noext;hide;suf=${OBJ_SUF}.o:SRC} ${nopath;noext;output;hide:SRC.h} ${nopath;noext;output;addincl;hide:SRC.h} && set_global_flags BISON_FLAGS $BISON_FLAGS && conan_require_tool m4/1.4.19 && conan_import '"bin, m4* -> ./bin/m4/bin"' && conan_require_tool bison/3.8.2 && conan_import '"bin, bison* -> ./bin/bison/bin"' && conan_import '"res, * -> ./bin/bison/res"'
+    .SEM=target_bison_parser PRIVATE ${input:SRC} ${output;nopath;noext;hide;suf=${OBJ_SUF}.o:SRC} ${nopath;noext;output;hide:SRC.h} ${nopath;noext;output;addincl;hide:SRC.h} && set_global_flags BISON_FLAGS $BISON_FLAGS && conan_require_tool m4/1.4.19 && conan_import '"bin, m4* -> ./bin/m4/bin"' && conan_require_tool bison/3.8.2 && conan_import '"bin, bison* -> ./bin/bison/bin"' && conan_import '"res, * -> ./bin/bison/res"' && platform_vars-BISON_FLAGS ${quo:BISON_FLAGS} && conan-tool_requires m4/1.4.19 && conan-imports 'bin, m4* -> ./bin/m4/bin' && conan-tool_requires bison/3.8.2 && conan-imports 'bin, bison* -> ./bin/bison/bin' && conan-imports 'res, * -> ./bin/bison/res'
 }
 
 macro _SRC("ypp", SRC, SRCFLAGS...) {
@@ -146,7 +146,7 @@ macro _SRC("ypp", SRC, SRCFLAGS...) {
 macro _SRC("l", SRC, SRCFLAGS...) {
     .CMD=$_FLEX_TOOL $LEX_FLAGS ${SRCFLAGS} $_FLEX_HEADER ${hide:_FLEX_GEN_EXT} -o${output;suf=$_FLEX_GEN_EXT:SRC} ${output_include;hide:"util/system/compiler.h"} ${input:SRC} ${kv;hide:"p LX"} ${kv;hide:"pc yellow"}
     .ADDINCL=$_FLEX_TOOL_DIR
-    .SEM=target_flex_lexers ${tool;hide:_FLEX_TOOL} ${output;hide;suf=${OBJ_SUF}.o:SRC} ${input:SRC} && set_global_flags LEX_FLAGS $LEX_FLAGS
+    .SEM=target_flex_lexers ${tool;hide:_FLEX_TOOL} ${output;hide;suf=${OBJ_SUF}.o:SRC} ${input:SRC} && set_global_flags LEX_FLAGS $LEX_FLAGS && platform_vars-LEX_FLAGS ${quo:LEX_FLAGS}
 }
 
 # tag:src-processing

+ 1 - 1
build/conf/fbs.conf

@@ -39,7 +39,7 @@ _GO_FLATC_IMPORTS=\
 # tag:fbs tag:cpp-specific
 macro _CPP_FLATC_CMD(SRC, SRCFLAGS...) {
     .CMD=${cwd:ARCADIA_BUILD_ROOT} $YMAKE_PYTHON3 ${input:"build/scripts/cpp_flatc_wrapper.py"} ${tool:FLATC} --no-warnings --cpp --keep-prefix --gen-mutable --schema -b --yandex-maps-iter --gen-object-api --filename-suffix .fbs ${FLATC_FLAGS_VALUE} ${pre=-I :_FLATC__INCLUDE} -o ${output;main;norel:SRC.h} ${output;hide;norel:SRC.cpp} ${input:SRC} ${output;hide;noext;norel:SRC.iter.fbs.h} ${output;noauto;hide;noext;norel:SRC.bfbs} ${kv;hide:"p FL"} ${kv;hide:"pc light-green"} ${hide:FBS_FAKEID}
-    .SEM=target_fbs_source PRIVATE ${input:SRC} ${FLATC_FLAGS_VALUE} ${pre=-I :_FLATC__INCLUDE} ${output;hide;norel:SRC.h} ${output;hide;norel:SRC.cpp} ${output;hide;noext;norel:SRC.iter.fbs.h} ${output;noauto;hide;noext;norel:SRC.bfbs} ${hide;tool:FLATC} && set_global_flags FBS_CPP_FLAGS --no-warnings --cpp --keep-prefix --gen-mutable --schema -b --yandex-maps-iter --gen-object-api --filename-suffix .fbs ${input;hide:"build/scripts/cpp_flatc_wrapper.py"}
+    .SEM=target_fbs_source PRIVATE ${input:SRC} ${FLATC_FLAGS_VALUE} ${pre=-I :_FLATC__INCLUDE} ${output;hide;norel:SRC.h} ${output;hide;norel:SRC.cpp} ${output;hide;noext;norel:SRC.iter.fbs.h} ${output;noauto;hide;noext;norel:SRC.bfbs} ${hide;tool:FLATC} && set_global_flags FBS_CPP_FLAGS --no-warnings --cpp --keep-prefix --gen-mutable --schema -b --yandex-maps-iter --gen-object-api --filename-suffix .fbs && platform_vars-FBS_CPP_FLAGS "--no-warnings --cpp --keep-prefix --gen-mutable --schema -b --yandex-maps-iter --gen-object-api --filename-suffix .fbs" ${input;hide:"build/scripts/cpp_flatc_wrapper.py"}
     .PEERDIR=contrib/libs/flatbuffers
 }
 

+ 2 - 0
build/conf/proto.conf

@@ -385,6 +385,7 @@ macro YT_ORM_PROTO_YSON(OUT_OPTS[], Files...) {
 
 _SEM_CPP_PROTO_CMD=target_proto_messages PRIVATE ${input:File} $CPP_PROTO_OUTS_SEM ${output;hide;suf=${OBJ_SUF}.pb.o:File} $DEFAULT_PROTOC_TOOLS \
                    && set_global_flags COMMON_PROTOC_FLAGS \
+                   && platform_vars-COMMON_PROTOC_FLAGS "" \
                    && target_proto_outs --cpp_out=$ARCADIA_BUILD_ROOT/$PROTO_NAMESPACE $PROTOC_STYLEGUIDE_OUT \
                    && target_proto_addincls ./$PROTO_NAMESPACE $ARCADIA_ROOT/$PROTO_NAMESPACE ${_PROTO__INCLUDE} $ARCADIA_BUILD_ROOT $PROTOBUF_PATH
 
@@ -403,6 +404,7 @@ macro _CPP_VANILLA_PROTO_CMD(File) {
 
 _SEM_CPP_EV_CMD=target_ev_messages PRIVATE ${input:File} $CPP_EV_OUTS_SEM ${output;hide;suf=${OBJ_SUF}.pb.o:File} ${hide;tool:"tools/event2cpp/bin"} $DEFAULT_PROTOC_TOOLS \
                    && set_global_flags COMMON_PROTOC_FLAGS \
+                   && platform_vars-COMMON_PROTOC_FLAGS "" \
                    && target_proto_outs --cpp_out=$ARCADIA_BUILD_ROOT/$PROTO_NAMESPACE $PROTOC_STYLEGUIDE_OUT --event2cpp_out=$ARCADIA_BUILD_ROOT/$PROTO_NAMESPACE \
                    && target_proto_addincls ./$PROTO_NAMESPACE $ARCADIA_ROOT/$PROTO_NAMESPACE ${_PROTO__INCLUDE} $ARCADIA_BUILD_ROOT $PROTOBUF_PATH $ARCADIA_ROOT/library/cpp/eventlog
 

+ 0 - 10
build/export_generators/cmake/common_cmake_lists.jinja

@@ -1,10 +0,0 @@
-{% include '[generator]/disclaimer.jinja' %}
-
-{% set platforms_count = platform_names|length -%}
-{% if platforms_count > 0 -%}
-{%     for i in range(platforms_count) %}
-{%         if i != 0 %}else{% endif %}if ({{ platforms[platform_names[i]] }})
-  include(CMakeLists.{{ platform_names[i] }}.txt)
-{%-    endfor %}
-endif()
-{% endif -%}

+ 27 - 9
build/export_generators/cmake/conanfile.jinja

@@ -1,20 +1,38 @@
 [requires]
-{% for package in conan_packages -%}
+{%- if conan.requires is defined -%}
+{%-     for package in conan.requires %}
 {{ package }}
-{% endfor %}
+{%-     endfor -%}
+{%- endif %}
+
 [tool_requires]
-{% for package in conan_tool_packages -%}
+{%- if conan.tool_requires is defined -%}
+{%-     for package in conan.tool_requires %}
 {{ package }}
-{% endfor %}
+{%-     endfor -%}
+{%- endif %}
+
 [options]
-{% for option in conan_options -%}
+{%- if conan.options is defined -%}
+{%-     for option in conan.options %}
 {{ option }}
-{% endfor %}
+{%-     endfor -%}
+{%- endif %}
+
 [imports]
-{% for imp in conan_imports -%}
-{{ imp }}
-{% endfor %}
+{%- if conan.imports is defined -%}
+{%-     for import_ in conan.imports %}
+{{ import_ }}
+{%-     endfor -%}
+{%- endif %}
+
 [generators]
 cmake_find_package
 cmake_paths
+{%- if conan.generators is defined -%}
+{%-     for generator in conan.generators %}
+{{ generator }}
+{%-     endfor -%}
+{%- endif %}
 
+{%- include "[generator]/debug.jinja" ignore missing -%}

+ 25 - 0
build/export_generators/cmake/debug.jinja

@@ -0,0 +1,25 @@
+{%- if dump_sems is defined %}
+
+#[===[
+vvvvvv SEMANTICS
+{#- replace(' ', ' ') is workaround, else `split` function in C++ receive invalid input -#}
+{%-    set lines = split(dump_sems|replace(' ', ' '), '\n') -%}
+{%-    for line in lines %}
+{{ line }}
+{%-    endfor %}
+^^^^^^ SEMANTICS
+]===]
+{%- endif -%}
+
+{%- if dump_attrs is defined %}
+
+#[===[
+vvvvvv ATTRIBUTES
+{#- replace(' ', ' ') is workaround, else `split` function in C++ receive invalid input -#}
+{%-    set lines = split(dump_attrs|replace(' ', ' '), '\n') -%}
+{%-    for line in lines %}
+{{ line }}
+{%-    endfor %}
+^^^^^^ ATTRIBUTES
+]===]
+{%- endif -%}

+ 1 - 0
build/export_generators/cmake/dir_cmake_lists.jinja

@@ -38,3 +38,4 @@ add_subdirectory({{ subdir }})
 {%-     endfor -%}
 {%- endif -%}
 {%- include 'epilogue.cmake' ignore missing -%}
+{%- include "[generator]/debug.jinja" ignore missing -%}

+ 35 - 12
build/export_generators/cmake/generator.toml

@@ -42,26 +42,26 @@ copy=[
 
 [targets.EMPTY]
 template={ path="dir_cmake_lists.jinja", dest="CMakeLists{PLATFORM}.txt" }
-merge_platform_template={ path="common_cmake_lists.jinja", dest="CMakeLists.txt" }
+merge_platform_template={ path="merge_platforms_cmake_lists.jinja", dest="CMakeLists.txt" }
 
 [targets.add_executable]
 template={ path="dir_cmake_lists.jinja", dest="CMakeLists{PLATFORM}.txt" }
-merge_platform_template={ path="common_cmake_lists.jinja", dest="CMakeLists.txt" }
+merge_platform_template={ path="merge_platforms_cmake_lists.jinja", dest="CMakeLists.txt" }
 
 [targets.add_global_library_for]
 is_extra_target = true
 
 [targets.add_library]
 template={ path="dir_cmake_lists.jinja", dest="CMakeLists{PLATFORM}.txt" }
-merge_platform_template={ path="common_cmake_lists.jinja", dest="CMakeLists.txt" }
+merge_platform_template={ path="merge_platforms_cmake_lists.jinja", dest="CMakeLists.txt" }
 
 [targets.add_shared_library]
 template={ path="dir_cmake_lists.jinja", dest="CMakeLists{PLATFORM}.txt" }
-merge_platform_template={ path="common_cmake_lists.jinja", dest="CMakeLists.txt" }
+merge_platform_template={ path="merge_platforms_cmake_lists.jinja", dest="CMakeLists.txt" }
 
 [targets.add_fat_object]
 template={ path="dir_cmake_lists.jinja", dest="CMakeLists{PLATFORM}.txt" }
-merge_platform_template={ path="common_cmake_lists.jinja", dest="CMakeLists.txt" }
+merge_platform_template={ path="merge_platforms_cmake_lists.jinja", dest="CMakeLists.txt" }
 
 [targets.add_recursive_library]
 is_extra_target = true
@@ -70,12 +70,35 @@ is_extra_target = true
 is_extra_target = true
 
 [attrs.root]
-project_name="str"
-project_language_list="list"
-platform_vars="list"
-includes="sorted_set"
-use_conan="bool"
+# DEPRECATED - Skipped old hardcoded-cmake attributes
+conan_require="skip"
+conan_require_tool="skip"
+conan_import="skip"
+conan_options="skip"
+add_language="skip"
+set_global_flags="skip"
+
+# Really used attributes
+conan-requires="sorted_set"
+conan-tool_requires="sorted_set"
+conan-imports="sorted_set"
+conan-options="set"
+conan-generators="sorted_set"
+
+project_languages="set"
 vanilla_protobuf="flag"
+includes="set"
+
+[attrs.platform]
+platform_vars-FAT_OBJECT_PREFIX="str"
+platform_vars-FAT_OBJECT_SUFFIX="str"
+platform_vars-RAGEL_FLAGS="str"
+platform_vars-YASM_FLAGS="str"
+platform_vars-CMAKE_CUDA_STANDARD="str"
+platform_vars-BISON_FLAGS="str"
+platform_vars-LEX_FLAGS="str"
+platform_vars-FBS_CPP_FLAGS="str"
+platform_vars-COMMON_PROTOC_FLAGS="str"
 
 [attrs.dir]
 
@@ -111,8 +134,8 @@ attrs=[
     "conan_config_install",
     "conan_load_buildinfo",
     "conan_parse_arguments",
-    "conan_require",
-    "conan_require_tool",
+    "conan-requires",
+    "conan-tool_requires",
     "old_conan_cmake_install",
 ]
 copy=["cmake/conan.cmake"]

+ 11 - 0
build/export_generators/cmake/merge_platforms_cmake_lists.jinja

@@ -0,0 +1,11 @@
+{%  include '[generator]/disclaimer.jinja' %}
+
+{%  if platform_names|length -%}
+{%-     for platform_name in platform_names %}
+{%          if not loop.first %}else{% endif %}if ({{ platform_conditions[platform_name] }})
+  include(CMakeLists.{{ platform_name }}.txt)
+{%-     endfor %}
+endif()
+
+{%  endif -%}
+{%- include "[generator]/debug.jinja" ignore missing -%}

+ 22 - 13
build/export_generators/cmake/root_cmake_lists.jinja

@@ -1,13 +1,21 @@
 {% include '[generator]/disclaimer.jinja' %}
 
 cmake_minimum_required(VERSION 3.15)
-project({{project_name}} LANGUAGES{% for value in project_language_list %} {{value}}{% endfor %})
+project({{ project_name }} LANGUAGES
+{%- for project_language in project_languages -%}
+{%-     if project_language == "ASM" -%}
+{%          set has_asm = true %}
+{%-     else  %} {{ project_language }}
+{%-     endif  -%}
+{%-     if has_asm %} ASM
+{%-     endif  -%}
+{%- endfor -%})
 
 set(BUILD_SHARED_LIBS Off)
 set(CMAKE_CXX_STANDARD 20)
 set(CMAKE_CXX_EXTENSIONS Off)
-set({{project_name}}_MAX_LINK_JOBS 5 CACHE STRING "Maximum parallel link jobs for Ninja generator")
-set_property(GLOBAL PROPERTY JOB_POOLS link_jobs=${{ '{' }}{{project_name}}_MAX_LINK_JOBS{{ '}' }})
+set({{ project_name }}_MAX_LINK_JOBS 5 CACHE STRING "Maximum parallel link jobs for Ninja generator")
+set_property(GLOBAL PROPERTY JOB_POOLS link_jobs=${{ '{' }}{{ project_name }}_MAX_LINK_JOBS{{ '}' }})
 set(CMAKE_JOB_POOL_LINK link_jobs)
 
 list(APPEND CMAKE_MODULE_PATH ${{ '{' }}PROJECT_BINARY_DIR{{ '}' }} ${{ '{' }}PROJECT_SOURCE_DIR{{ '}' }}/cmake)
@@ -26,7 +34,7 @@ include(cmake/global_vars.cmake)
 include({{ incl }})
 {%     endfor -%}
 {% endif -%}
-{% if use_conan %}
+{% if conan.requires or conan.tool_requires %}
 if (CMAKE_CROSSCOMPILING)
   include(${PROJECT_BINARY_DIR}/conan_paths.cmake)
 else()
@@ -45,13 +53,14 @@ endif(){% endif %}
 {%- if vanilla_protobuf %}
 
 set(vanilla_protobuf "yes")
-{%- endif %}
-
-{%  set platforms_count = platform_names|length -%}
-{%  if platforms_count > 0 -%}
-{%      for i in range(platforms_count) -%}
-{%          if i != 0 %}else{% endif %}if ({{ platforms[platform_names[i]] }})
-  include(CMakeLists.{{ platform_names[i] }}.txt)
-{%      endfor -%}
+{%- endif -%}
+
+{%- if platform_names|length %}
+{%     for platform_name in platform_names %}
+{%        if not loop.first %}else{% endif %}if ({{ platform_conditions[platform_name] }})
+  include(CMakeLists.{{ platform_name }}.txt)
+{%-     endfor %}
 endif()
-{%  endif %}
+
+{% endif -%}
+{%- include "[generator]/debug.jinja" ignore missing -%}

Some files were not shown because too many files changed in this diff