Просмотр исходного кода

Root CMakeLists.txt generation with jinja

mag1str0 1 год назад
Родитель
Сommit
4e5c31d161

+ 11 - 2
build/export_generators/hardcoded-cmake/generator.toml

@@ -1,5 +1,8 @@
 [root]
-
+templates=[
+    { path="root_cmake_lists.jinja", dest="CMakeLists.txt" },
+    { path="root_global_vars.jinja", dest="cmake/global_vars.cmake" },
+]
 copy=[
 	"cmake/global_flags.compiler.gnu.cmake",
     "cmake/global_flags.compiler.msvc.cmake",
@@ -9,7 +12,13 @@ copy=[
 ]
 
 [attrs.root]
-includes="list"
+project_name="str"
+project_language_list="list"
+use_conan="bool"
+platform_flags="list"
+platform_cmakelists="list"
+platform_vars="list"
+includes="sorted_set"
 
 [attrs.target]
 

+ 49 - 0
build/export_generators/hardcoded-cmake/root_cmake_lists.jinja

@@ -0,0 +1,49 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+cmake_minimum_required(VERSION 3.15)
+project({{project_name}} LANGUAGES{% for value in project_language_list %} {{value}}{% 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(CMAKE_JOB_POOL_LINK link_jobs)
+
+list(APPEND CMAKE_MODULE_PATH ${{ '{' }}CMAKE_BINARY_DIR{{ '}' }} ${{ '{' }}CMAKE_SOURCE_DIR{{ '}' }}/cmake)
+include_directories(${{ '{' }}CMAKE_SOURCE_DIR{{ '}' }} ${{ '{' }}CMAKE_BINARY_DIR{{ '}' }})
+list(APPEND CMAKE_CTEST_ARGUMENTS "--output-on-failure")
+enable_testing()
+
+# Disable 'empty CUDA_ARCHITECTURES not allowed' warning
+# Can't set it in cuda.cmake because of CMake policy subdirectory stack rules
+cmake_policy(SET CMP0104 OLD)
+
+include(cmake/global_flags.cmake)
+include(cmake/global_vars.cmake)
+{% for path in includes %}include({{path}})
+{%endfor%}{% if use_conan %}
+if (CMAKE_CROSSCOMPILING)
+  include(${CMAKE_BINARY_DIR}/conan_paths.cmake)
+else()
+  conan_cmake_autodetect(settings)
+  conan_cmake_install(
+    PATH_OR_REFERENCE ${CMAKE_SOURCE_DIR}
+    INSTALL_FOLDER ${CMAKE_BINARY_DIR}
+    BUILD missing
+    REMOTE conancenter
+    SETTINGS ${settings}
+      ENV "CONAN_CMAKE_GENERATOR=${CMAKE_GENERATOR}"
+      CONF "tools.cmake.cmaketoolchain:generator=${CMAKE_GENERATOR}"
+  )
+endif(){% endif %}
+{% for i in range(platform_flags|length) %}
+{% if i != 0 %}else{% endif %}if ({{ platform_flags[i] }})
+  include({{ platform_cmakelists[i] }}){%endfor%}
+{% if platform_flags|length > 0%}endif(){% endif %}

+ 12 - 0
build/export_generators/hardcoded-cmake/root_global_vars.jinja

@@ -0,0 +1,12 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+{% for i in range(platform_vars|length) %}
+if({{ platform_flags[i] }})
+{% for var in platform_vars[i] %}  set({% for arg in var %}{{arg}}{% if not loop.last %} {% endif %}{% endfor %})
+{% endfor %}endif()
+{% endfor %}