From ad0b39c228ecb6b5539fb5995c7a3e98f85c9bf9 Mon Sep 17 00:00:00 2001 From: James <james@conan.io> Date: Thu, 11 Apr 2024 14:31:52 +0200 Subject: [PATCH] Internal refactor for readability of CMakeDeps (#16040) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * cmake deps internal refactor for readability * fix * fix * fix * fix * fix * copy only if different (#16031) * allow conf in exports-sources and export (#16034) * refactor apple_min_version_flag() (#16017) * refactor apple_min_version_flag() * Refactored all the apple module and where it was being used (AutotoolsToolchain and MesonToolchain for now) * Fixed bad return * Fixing tests * Keeping legacy behavior in apple_min_version_flag function * Preventing possible breaking change --------- Co-authored-by: Francisco Ramirez de Anton <franchuti688@gmail.com> * Allow to unhide git url (#16038) * Add hide_url tests for git scm tool * Add hide_url flag to clone and fetch_commit. Resolves #15684 * Update conans/test/functional/tools/scm/test_git.py * Update conans/test/functional/tools/scm/test_git.py --------- Co-authored-by: Rubén Rincón Blanco <git@rinconblanco.es> * remove repeated non-running test (#16053) * refactor transitive_requires --------- Co-authored-by: Francisco Ramirez de Anton <franchuti688@gmail.com> Co-authored-by: Sebastian Höffner <info@sebastian-hoeffner.de> Co-authored-by: Rubén Rincón Blanco <git@rinconblanco.es> --- conan/tools/cmake/cmakedeps/cmakedeps.py | 5 ++ .../tools/cmake/cmakedeps/templates/config.py | 17 ++-- .../templates/target_configuration.py | 86 ++++++++++--------- .../cmake/cmakedeps/templates/target_data.py | 33 ++++--- 4 files changed, 78 insertions(+), 63 deletions(-) diff --git a/conan/tools/cmake/cmakedeps/cmakedeps.py b/conan/tools/cmake/cmakedeps/cmakedeps.py index 04964f18ffd..f8a9cca02f0 100644 --- a/conan/tools/cmake/cmakedeps/cmakedeps.py +++ b/conan/tools/cmake/cmakedeps/cmakedeps.py @@ -17,6 +17,7 @@ from conan.tools.files import save from conans.client.generators import relativize_generated_file from conan.errors import ConanException +from conans.model.dependencies import get_transitive_requires class CMakeDeps(object): @@ -220,3 +221,7 @@ def generate_aggregator(self): undefined=jinja2.StrictUndefined) conandeps = template.render({"configs": configs}) save(self._conanfile, "conandeps_legacy.cmake", conandeps) + + def get_transitive_requires(self, conanfile): + # Prepared to filter transitive tool-requires with visible=True + return get_transitive_requires(self._conanfile, conanfile) diff --git a/conan/tools/cmake/cmakedeps/templates/config.py b/conan/tools/cmake/cmakedeps/templates/config.py index 07b44a4a8d7..ea01844579a 100644 --- a/conan/tools/cmake/cmakedeps/templates/config.py +++ b/conan/tools/cmake/cmakedeps/templates/config.py @@ -37,6 +37,9 @@ def context(self): @property def template(self): return textwrap.dedent("""\ + {%- macro pkg_var(pkg_name, var, config_suffix) -%} + {{'${'+pkg_name+'_'+var+config_suffix+'}'}} + {%- endmacro -%} ########## MACROS ########################################################################### ############################################################################################# @@ -57,7 +60,7 @@ def template(self): check_build_type_defined() - foreach(_DEPENDENCY {{ '${' + pkg_name + '_FIND_DEPENDENCY_NAMES' + '}' }} ) + foreach(_DEPENDENCY {{ pkg_var(pkg_name, 'FIND_DEPENDENCY_NAMES', '') }} ) # Check that we have not already called a find_package with the transitive dependency if(NOT {{ '${_DEPENDENCY}' }}_FOUND) find_dependency({{ '${_DEPENDENCY}' }} REQUIRED ${${_DEPENDENCY}_FIND_MODE}) @@ -65,13 +68,13 @@ def template(self): endforeach() set({{ file_name }}_VERSION_STRING "{{ version }}") - set({{ file_name }}_INCLUDE_DIRS {{ '${' + pkg_name + '_INCLUDE_DIRS' + config_suffix + '}' }} ) - set({{ file_name }}_INCLUDE_DIR {{ '${' + pkg_name + '_INCLUDE_DIRS' + config_suffix + '}' }} ) - set({{ file_name }}_LIBRARIES {{ '${' + pkg_name + '_LIBRARIES' + config_suffix + '}' }} ) - set({{ file_name }}_DEFINITIONS {{ '${' + pkg_name + '_DEFINITIONS' + config_suffix + '}' }} ) + set({{ file_name }}_INCLUDE_DIRS {{ pkg_var(pkg_name, 'INCLUDE_DIRS', config_suffix) }} ) + set({{ file_name }}_INCLUDE_DIR {{ pkg_var(pkg_name, 'INCLUDE_DIRS', config_suffix) }} ) + set({{ file_name }}_LIBRARIES {{ pkg_var(pkg_name, 'LIBRARIES', config_suffix) }} ) + set({{ file_name }}_DEFINITIONS {{ pkg_var(pkg_name, 'DEFINITIONS', config_suffix) }} ) # Only the first installed configuration is included to avoid the collision - foreach(_BUILD_MODULE {{ '${' + pkg_name + '_BUILD_MODULES_PATHS' + config_suffix + '}' }} ) + foreach(_BUILD_MODULE {{ pkg_var(pkg_name, 'BUILD_MODULES_PATHS', config_suffix) }} ) message({% raw %}${{% endraw %}{{ file_name }}_MESSAGE_MODE} "Conan: Including build module from '${_BUILD_MODULE}'") include({{ '${_BUILD_MODULE}' }}) endforeach() @@ -80,7 +83,7 @@ def template(self): # Check that the specified components in the find_package(Foo COMPONENTS x y z) are there # This is the variable filled by CMake with the requested components in find_package if({{ file_name }}_FIND_COMPONENTS) - foreach(_FIND_COMPONENT {{ '${'+file_name+'_FIND_COMPONENTS}' }}) + foreach(_FIND_COMPONENT {{ pkg_var(file_name, 'FIND_COMPONENTS', '') }}) if (TARGET ${_FIND_COMPONENT}) message({% raw %}${{% endraw %}{{ file_name }}_MESSAGE_MODE} "Conan: Component '${_FIND_COMPONENT}' found in package '{{ pkg_name }}'") else() diff --git a/conan/tools/cmake/cmakedeps/templates/target_configuration.py b/conan/tools/cmake/cmakedeps/templates/target_configuration.py index 8a8508d37c3..932f39c9513 100644 --- a/conan/tools/cmake/cmakedeps/templates/target_configuration.py +++ b/conan/tools/cmake/cmakedeps/templates/target_configuration.py @@ -1,7 +1,6 @@ import textwrap from conan.tools.cmake.cmakedeps.templates import CMakeDepsFileTemplate -from conans.model.dependencies import get_transitive_requires """ @@ -45,14 +44,17 @@ def template(self): # Avoid multiple calls to find_package to append duplicated properties to the targets include_guard() - {%- macro tvalue(pkg_name, comp_name, var, config_suffix) -%} + {%- macro comp_var(pkg_name, comp_name, var, config_suffix) -%} {{'${'+pkg_name+'_'+comp_name+'_'+var+config_suffix+'}'}} {%- endmacro -%} + {%- macro pkg_var(pkg_name, var, config_suffix) -%} + {{'${'+pkg_name+'_'+var+config_suffix+'}'}} + {%- endmacro -%} ########### VARIABLES ####################################################################### ############################################################################################# set({{ pkg_name }}_FRAMEWORKS_FOUND{{ config_suffix }} "") # Will be filled later - conan_find_apple_frameworks({{ pkg_name }}_FRAMEWORKS_FOUND{{ config_suffix }} "{{ '${' }}{{ pkg_name }}_FRAMEWORKS{{ config_suffix }}}" "{{ '${' }}{{ pkg_name }}_FRAMEWORK_DIRS{{ config_suffix }}}") + conan_find_apple_frameworks({{ pkg_name }}_FRAMEWORKS_FOUND{{ config_suffix }} "{{ pkg_var(pkg_name, 'FRAMEWORKS', config_suffix) }}" "{{ pkg_var(pkg_name, 'FRAMEWORK_DIRS', config_suffix) }}") set({{ pkg_name }}_LIBRARIES_TARGETS "") # Will be filled later @@ -64,35 +66,35 @@ def template(self): set_property(TARGET {{ pkg_name + '_DEPS_TARGET'}} APPEND PROPERTY INTERFACE_LINK_LIBRARIES - $<$<CONFIG:{{configuration}}>:{{ '${'+pkg_name+'_FRAMEWORKS_FOUND'+config_suffix+'}' }}> - $<$<CONFIG:{{configuration}}>:{{ '${'+pkg_name+'_SYSTEM_LIBS'+config_suffix+'}' }}> + $<$<CONFIG:{{configuration}}>:{{ pkg_var(pkg_name, 'FRAMEWORKS_FOUND', config_suffix) }}> + $<$<CONFIG:{{configuration}}>:{{ pkg_var(pkg_name, 'SYSTEM_LIBS', config_suffix) }}> $<$<CONFIG:{{configuration}}>:{{ deps_targets_names }}>) ####### Find the libraries declared in cpp_info.libs, create an IMPORTED target for each one and link the ####### {{pkg_name}}_DEPS_TARGET to all of them - conan_package_library_targets("{{ '${' }}{{ pkg_name }}_LIBS{{ config_suffix }}}" # libraries - "{{ '${' }}{{ pkg_name }}_LIB_DIRS{{ config_suffix }}}" # package_libdir - "{{ '${' }}{{ pkg_name }}_BIN_DIRS{{ config_suffix }}}" # package_bindir - "{{ '${' }}{{ pkg_name }}_LIBRARY_TYPE{{ config_suffix }}}" - "{{ '${' }}{{ pkg_name }}_IS_HOST_WINDOWS{{ config_suffix }}}" + conan_package_library_targets("{{ pkg_var(pkg_name, 'LIBS', config_suffix) }}" # libraries + "{{ pkg_var(pkg_name, 'LIB_DIRS', config_suffix) }}" # package_libdir + "{{ pkg_var(pkg_name, 'BIN_DIRS', config_suffix) }}" # package_bindir + "{{ pkg_var(pkg_name, 'LIBRARY_TYPE', config_suffix) }}" + "{{ pkg_var(pkg_name, 'IS_HOST_WINDOWS', config_suffix) }}" {{ pkg_name + '_DEPS_TARGET'}} {{ pkg_name }}_LIBRARIES_TARGETS # out_libraries_targets "{{ config_suffix }}" "{{ pkg_name }}" # package_name - "{{ '${' }}{{ pkg_name }}_NO_SONAME_MODE{{ config_suffix }}}") # soname + "{{ pkg_var(pkg_name, 'NO_SONAME_MODE', config_suffix) }}") # soname # FIXME: What is the result of this for multi-config? All configs adding themselves to path? - set(CMAKE_MODULE_PATH {{ '${' }}{{ pkg_name }}_BUILD_DIRS{{ config_suffix }}} {{ '${' }}CMAKE_MODULE_PATH}) + set(CMAKE_MODULE_PATH {{ pkg_var(pkg_name, 'BUILD_DIRS', config_suffix) }} {{ '${' }}CMAKE_MODULE_PATH}) {% if not components_names %} ########## GLOBAL TARGET PROPERTIES {{ configuration }} ######################################## set_property(TARGET {{root_target_name}} APPEND PROPERTY INTERFACE_LINK_LIBRARIES - $<$<CONFIG:{{configuration}}>:{{ '${'+pkg_name+'_OBJECTS'+config_suffix+'}' }}> - $<$<CONFIG:{{configuration}}>:${{'{'}}{{pkg_name}}_LIBRARIES_TARGETS}> + $<$<CONFIG:{{configuration}}>:{{ pkg_var(pkg_name, 'OBJECTS', config_suffix) }}> + $<$<CONFIG:{{configuration}}>:{{ pkg_var(pkg_name, 'LIBRARIES_TARGETS', '') }}> ) - if("{{ '${' }}{{ pkg_name }}_LIBS{{ config_suffix }}}" STREQUAL "") + if("{{ pkg_var(pkg_name, 'LIBS', config_suffix) }}" STREQUAL "") # If the package is not declaring any "cpp_info.libs" the package deps, system libs, # frameworks etc are not linked to the imported targets and we need to do it to the # global target @@ -103,27 +105,27 @@ def template(self): set_property(TARGET {{root_target_name}} APPEND PROPERTY INTERFACE_LINK_OPTIONS - $<$<CONFIG:{{configuration}}>:${{'{'}}{{pkg_name}}_LINKER_FLAGS{{config_suffix}}}>) + $<$<CONFIG:{{configuration}}>:{{ pkg_var(pkg_name, 'LINKER_FLAGS', config_suffix) }}>) set_property(TARGET {{root_target_name}} APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES - $<$<CONFIG:{{configuration}}>:${{'{'}}{{pkg_name}}_INCLUDE_DIRS{{config_suffix}}}>) + $<$<CONFIG:{{configuration}}>:{{ pkg_var(pkg_name, 'INCLUDE_DIRS', config_suffix) }}>) # Necessary to find LINK shared libraries in Linux set_property(TARGET {{root_target_name}} APPEND PROPERTY INTERFACE_LINK_DIRECTORIES - $<$<CONFIG:{{configuration}}>:${{'{'}}{{pkg_name}}_LIB_DIRS{{config_suffix}}}>) + $<$<CONFIG:{{configuration}}>:{{ pkg_var(pkg_name, 'LIB_DIRS', config_suffix) }}>) set_property(TARGET {{root_target_name}} APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS - $<$<CONFIG:{{configuration}}>:${{'{'}}{{pkg_name}}_COMPILE_DEFINITIONS{{config_suffix}}}>) + $<$<CONFIG:{{configuration}}>:{{ pkg_var(pkg_name, 'COMPILE_DEFINITIONS', config_suffix) }}>) set_property(TARGET {{root_target_name}} APPEND PROPERTY INTERFACE_COMPILE_OPTIONS - $<$<CONFIG:{{configuration}}>:${{'{'}}{{pkg_name}}_COMPILE_OPTIONS{{config_suffix}}}>) + $<$<CONFIG:{{configuration}}>:{{ pkg_var(pkg_name, 'COMPILE_OPTIONS', config_suffix) }}>) {%- if set_interface_link_directories %} # This is only used for '#pragma comment(lib, "foo")' (automatic link) set_property(TARGET {{root_target_name}} APPEND PROPERTY INTERFACE_LINK_DIRECTORIES - $<$<CONFIG:{{configuration}}>:${{'{'}}{{pkg_name}}_LIB_DIRS{{config_suffix}}}>) + $<$<CONFIG:{{configuration}}>:{{ pkg_var(pkg_name, 'LIB_DIRS', config_suffix) }}>) {%- endif %} @@ -137,7 +139,7 @@ def template(self): ########## COMPONENT {{ comp_target_name }} ############# set({{ pkg_name }}_{{ comp_variable_name }}_FRAMEWORKS_FOUND{{ config_suffix }} "") - conan_find_apple_frameworks({{ pkg_name }}_{{ comp_variable_name }}_FRAMEWORKS_FOUND{{ config_suffix }} "{{ '${'+pkg_name+'_'+comp_variable_name+'_FRAMEWORKS'+config_suffix+'}' }}" "{{ '${'+pkg_name+'_'+comp_variable_name+'_FRAMEWORK_DIRS'+config_suffix+'}' }}") + conan_find_apple_frameworks({{ pkg_name }}_{{ comp_variable_name }}_FRAMEWORKS_FOUND{{ config_suffix }} "{{ comp_var(pkg_name, comp_variable_name, 'FRAMEWORKS', config_suffix) }}" "{{ comp_var(pkg_name, comp_variable_name, 'FRAMEWORK_DIRS', config_suffix) }}") set({{ pkg_name }}_{{ comp_variable_name }}_LIBRARIES_TARGETS "") @@ -148,33 +150,33 @@ def template(self): set_property(TARGET {{ pkg_name + '_' + comp_variable_name + '_DEPS_TARGET'}} APPEND PROPERTY INTERFACE_LINK_LIBRARIES - $<$<CONFIG:{{configuration}}>:{{ '${'+pkg_name+'_'+comp_variable_name+'_FRAMEWORKS_FOUND'+config_suffix+'}' }}> - $<$<CONFIG:{{configuration}}>:{{ '${'+pkg_name+'_'+comp_variable_name+'_SYSTEM_LIBS'+config_suffix+'}' }}> - $<$<CONFIG:{{configuration}}>:{{ '${'+pkg_name+'_'+comp_variable_name+'_DEPENDENCIES'+config_suffix+'}' }}> + $<$<CONFIG:{{configuration}}>:{{ comp_var(pkg_name, comp_variable_name, 'FRAMEWORKS_FOUND', config_suffix) }}> + $<$<CONFIG:{{configuration}}>:{{ comp_var(pkg_name, comp_variable_name, 'SYSTEM_LIBS', config_suffix) }}> + $<$<CONFIG:{{configuration}}>:{{ comp_var(pkg_name, comp_variable_name, 'DEPENDENCIES', config_suffix) }}> ) ####### Find the libraries declared in cpp_info.component["xxx"].libs, ####### create an IMPORTED target for each one and link the '{{pkg_name}}_{{comp_variable_name}}_DEPS_TARGET' to all of them - conan_package_library_targets("{{ '${'+pkg_name+'_'+comp_variable_name+'_LIBS'+config_suffix+'}' }}" - "{{ '${'+pkg_name+'_'+comp_variable_name+'_LIB_DIRS'+config_suffix+'}' }}" - "{{ '${'+pkg_name+'_'+comp_variable_name+'_BIN_DIRS'+config_suffix+'}' }}" # package_bindir - "{{ '${'+pkg_name+'_'+comp_variable_name+'_LIBRARY_TYPE'+config_suffix+'}' }}" - "{{ '${'+pkg_name+'_'+comp_variable_name+'_IS_HOST_WINDOWS'+config_suffix+'}' }}" + conan_package_library_targets("{{ comp_var(pkg_name, comp_variable_name, 'LIBS', config_suffix) }}" + "{{ comp_var(pkg_name, comp_variable_name, 'LIB_DIRS', config_suffix) }}" + "{{ comp_var(pkg_name, comp_variable_name, 'BIN_DIRS', config_suffix) }}" # package_bindir + "{{ comp_var(pkg_name, comp_variable_name, 'LIBRARY_TYPE', config_suffix) }}" + "{{ comp_var(pkg_name, comp_variable_name, 'IS_HOST_WINDOWS', config_suffix) }}" {{ pkg_name + '_' + comp_variable_name + '_DEPS_TARGET'}} - {{ pkg_name }}_{{ comp_variable_name }}_LIBRARIES_TARGETS + {{ pkg_name + '_' + comp_variable_name + '_LIBRARIES_TARGETS'}} "{{ config_suffix }}" "{{ pkg_name }}_{{ comp_variable_name }}" - "{{ '${'+pkg_name+'_'+comp_variable_name+'_NO_SONAME_MODE'+config_suffix+'}' }}") + "{{ comp_var(pkg_name, comp_variable_name, 'NO_SONAME_MODE', config_suffix) }}") ########## TARGET PROPERTIES ##################################### set_property(TARGET {{comp_target_name}} APPEND PROPERTY INTERFACE_LINK_LIBRARIES - $<$<CONFIG:{{configuration}}>:{{ '${'+pkg_name+'_'+comp_variable_name+'_OBJECTS'+config_suffix+'}' }}> - $<$<CONFIG:{{configuration}}>:${{'{'}}{{pkg_name}}_{{comp_variable_name}}_LIBRARIES_TARGETS}> + $<$<CONFIG:{{configuration}}>:{{ comp_var(pkg_name, comp_variable_name, 'OBJECTS', config_suffix) }}> + $<$<CONFIG:{{configuration}}>:{{ comp_var(pkg_name, comp_variable_name, 'LIBRARIES_TARGETS', '') }}> ) - if("{{ '${' }}{{ pkg_name }}_{{comp_variable_name}}_LIBS{{ config_suffix }}}" STREQUAL "") + if("{{ comp_var(pkg_name, comp_variable_name, 'LIBS', config_suffix) }}" STREQUAL "") # If the component is not declaring any "cpp_info.components['foo'].libs" the system, frameworks etc are not # linked to the imported targets and we need to do it to the global target set_property(TARGET {{comp_target_name}} @@ -183,20 +185,20 @@ def template(self): endif() set_property(TARGET {{ comp_target_name }} APPEND PROPERTY INTERFACE_LINK_OPTIONS - $<$<CONFIG:{{ configuration }}>:{{tvalue(pkg_name, comp_variable_name, 'LINKER_FLAGS', config_suffix)}}>) + $<$<CONFIG:{{ configuration }}>:{{ comp_var(pkg_name, comp_variable_name, 'LINKER_FLAGS', config_suffix) }}>) set_property(TARGET {{ comp_target_name }} APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES - $<$<CONFIG:{{ configuration }}>:{{tvalue(pkg_name, comp_variable_name, 'INCLUDE_DIRS', config_suffix)}}>) + $<$<CONFIG:{{ configuration }}>:{{ comp_var(pkg_name, comp_variable_name, 'INCLUDE_DIRS', config_suffix) }}>) set_property(TARGET {{comp_target_name }} APPEND PROPERTY INTERFACE_LINK_DIRECTORIES - $<$<CONFIG:{{ configuration }}>:{{tvalue(pkg_name, comp_variable_name, 'LIB_DIRS', config_suffix)}}>) + $<$<CONFIG:{{ configuration }}>:{{ comp_var(pkg_name, comp_variable_name, 'LIB_DIRS', config_suffix) }}>) set_property(TARGET {{ comp_target_name }} APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS - $<$<CONFIG:{{ configuration }}>:{{tvalue(pkg_name, comp_variable_name, 'COMPILE_DEFINITIONS', config_suffix)}}>) + $<$<CONFIG:{{ configuration }}>:{{ comp_var(pkg_name, comp_variable_name, 'COMPILE_DEFINITIONS', config_suffix) }}>) set_property(TARGET {{ comp_target_name }} APPEND PROPERTY INTERFACE_COMPILE_OPTIONS - $<$<CONFIG:{{ configuration }}>:{{tvalue(pkg_name, comp_variable_name, 'COMPILE_OPTIONS', config_suffix)}}>) + $<$<CONFIG:{{ configuration }}>:{{ comp_var(pkg_name, comp_variable_name, 'COMPILE_OPTIONS', config_suffix) }}>) {%- if set_interface_link_directories %} # This is only used for '#pragma comment(lib, "foo")' (automatic link) set_property(TARGET {{ comp_target_name }} APPEND PROPERTY INTERFACE_LINK_DIRECTORIES - $<$<CONFIG:{{ configuration }}>:{{tvalue(pkg_name, comp_variable_name, 'LIB_DIRS', config_suffix)}}>) + $<$<CONFIG:{{ configuration }}>:{{ comp_var(pkg_name, comp_variable_name, 'LIB_DIRS', config_suffix) }}>) {%- endif %} {%endfor %} @@ -235,7 +237,7 @@ def get_deps_targets_names(self): # Get a list of dependencies target names # Declared cppinfo.requires or .components[].requires - transitive_reqs = get_transitive_requires(self.cmakedeps._conanfile, self.conanfile) + transitive_reqs = self.cmakedeps.get_transitive_requires(self.conanfile) if self.conanfile.cpp_info.required_components: for dep_name, component_name in self.conanfile.cpp_info.required_components: try: diff --git a/conan/tools/cmake/cmakedeps/templates/target_data.py b/conan/tools/cmake/cmakedeps/templates/target_data.py index 1d4c8b96d3f..e86d89be409 100644 --- a/conan/tools/cmake/cmakedeps/templates/target_data.py +++ b/conan/tools/cmake/cmakedeps/templates/target_data.py @@ -5,7 +5,6 @@ FIND_MODE_BOTH from conan.tools.cmake.cmakedeps.templates import CMakeDepsFileTemplate from conan.errors import ConanException -from conans.model.dependencies import get_transitive_requires """ @@ -84,6 +83,12 @@ def is_host_windows(self): def template(self): # This will be at: XXX-release-data.cmake ret = textwrap.dedent("""\ + {%- macro comp_var(pkg_name, comp_name, var, config_suffix) -%} + {{'${'+pkg_name+'_'+comp_name+'_'+var+config_suffix+'}'}} + {%- endmacro -%} + {%- macro pkg_var(pkg_name, var, config_suffix) -%} + {{'${'+pkg_name+'_'+var+config_suffix+'}'}} + {%- endmacro -%} ########### AGGREGATED COMPONENTS AND DEPENDENCIES FOR THE MULTI CONFIG ##################### ############################################################################################# @@ -132,12 +137,12 @@ def template(self): # COMPOUND VARIABLES set({{ pkg_name }}_COMPILE_OPTIONS{{ config_suffix }} - "$<$<COMPILE_LANGUAGE:CXX>{{ ':${' }}{{ pkg_name }}_COMPILE_OPTIONS_CXX{{ config_suffix }}}>" - "$<$<COMPILE_LANGUAGE:C>{{ ':${' }}{{ pkg_name }}_COMPILE_OPTIONS_C{{ config_suffix }}}>") + "$<$<COMPILE_LANGUAGE:CXX>:{{ pkg_var(pkg_name, 'COMPILE_OPTIONS_CXX', config_suffix) }}>" + "$<$<COMPILE_LANGUAGE:C>:{{ pkg_var(pkg_name, 'COMPILE_OPTIONS_C', config_suffix) }}>") set({{ pkg_name }}_LINKER_FLAGS{{ config_suffix }} - "$<$<STREQUAL{{ ':$' }}<TARGET_PROPERTY:TYPE>,SHARED_LIBRARY>{{ ':${' }}{{ pkg_name }}_SHARED_LINK_FLAGS{{ config_suffix }}}>" - "$<$<STREQUAL{{ ':$' }}<TARGET_PROPERTY:TYPE>,MODULE_LIBRARY>{{ ':${' }}{{ pkg_name }}_SHARED_LINK_FLAGS{{ config_suffix }}}>" - "$<$<STREQUAL{{ ':$' }}<TARGET_PROPERTY:TYPE>,EXECUTABLE>{{ ':${' }}{{ pkg_name }}_EXE_LINK_FLAGS{{ config_suffix }}}>") + "$<$<STREQUAL{{ ':$' }}<TARGET_PROPERTY:TYPE>,SHARED_LIBRARY>:{{ pkg_var(pkg_name, 'SHARED_LINK_FLAGS', config_suffix) }}>" + "$<$<STREQUAL{{ ':$' }}<TARGET_PROPERTY:TYPE>,MODULE_LIBRARY>:{{ pkg_var(pkg_name, 'SHARED_LINK_FLAGS', config_suffix) }}>" + "$<$<STREQUAL{{ ':$' }}<TARGET_PROPERTY:TYPE>,EXECUTABLE>:{{ pkg_var(pkg_name, 'EXE_LINK_FLAGS', config_suffix) }}>") set({{ pkg_name }}_COMPONENTS{{ config_suffix }} {{ components_names }}) @@ -167,13 +172,13 @@ def template(self): # COMPOUND VARIABLES set({{ pkg_name }}_{{ comp_variable_name }}_LINKER_FLAGS{{ config_suffix }} - $<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,SHARED_LIBRARY>{{ ':${' }}{{ pkg_name }}_{{ comp_variable_name }}_SHARED_LINK_FLAGS{{ config_suffix }}}> - $<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,MODULE_LIBRARY>{{ ':${' }}{{ pkg_name }}_{{ comp_variable_name }}_SHARED_LINK_FLAGS{{ config_suffix }}}> - $<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>{{ ':${' }}{{ pkg_name }}_{{ comp_variable_name }}_EXE_LINK_FLAGS{{ config_suffix }}}> + $<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,SHARED_LIBRARY>:{{ comp_var(pkg_name, comp_variable_name, 'SHARED_LINK_FLAGS', config_suffix) }}> + $<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,MODULE_LIBRARY>:{{ comp_var(pkg_name, comp_variable_name, 'SHARED_LINK_FLAGS', config_suffix) }}> + $<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:{{ comp_var(pkg_name, comp_variable_name, 'EXE_LINK_FLAGS', config_suffix) }}> ) set({{ pkg_name }}_{{ comp_variable_name }}_COMPILE_OPTIONS{{ config_suffix }} - "$<$<COMPILE_LANGUAGE:CXX>{{ ':${' }}{{ pkg_name }}_{{ comp_variable_name }}_COMPILE_OPTIONS_CXX{{ config_suffix }}}>" - "$<$<COMPILE_LANGUAGE:C>{{ ':${' }}{{ pkg_name }}_{{ comp_variable_name }}_COMPILE_OPTIONS_C{{ config_suffix }}}>") + "$<$<COMPILE_LANGUAGE:CXX>:{{ comp_var(pkg_name, comp_variable_name, 'COMPILE_OPTIONS_CXX', config_suffix) }}>" + "$<$<COMPILE_LANGUAGE:C>:{{ comp_var(pkg_name, comp_variable_name, 'COMPILE_OPTIONS_C', config_suffix) }}>") {%- endfor %} """) @@ -196,7 +201,7 @@ def _get_required_components_cpp(self): ret = [] sorted_comps = self.conanfile.cpp_info.get_sorted_components() pfolder_var_name = "{}_PACKAGE_FOLDER{}".format(self.pkg_name, self.config_suffix) - transitive_requires = get_transitive_requires(self.cmakedeps._conanfile, self.conanfile) + transitive_requires = self.cmakedeps.get_transitive_requires(self.conanfile) for comp_name, comp in sorted_comps.items(): deps_cpp_cmake = _TargetDataContext(comp, pfolder_var_name, self._root_folder, self.require, self.cmake_package_type, @@ -230,7 +235,7 @@ def _get_dependency_filenames(self): if self.require.build: return [] - transitive_reqs = get_transitive_requires(self.cmakedeps._conanfile, self.conanfile) + transitive_reqs = self.cmakedeps.get_transitive_requires(self.conanfile) # Previously it was filtering here components, but not clear why the file dependency # should be skipped if components are not being required, why would it declare a # dependency to it? @@ -242,7 +247,7 @@ def _get_dependencies_find_modes(self): ret = {} if self.require.build: return ret - deps = get_transitive_requires(self.cmakedeps._conanfile, self.conanfile) + deps = self.cmakedeps.get_transitive_requires(self.conanfile) for dep in deps.values(): dep_file_name = self.cmakedeps.get_cmake_package_name(dep, self.generating_module) find_mode = self.cmakedeps.get_find_mode(dep)