From 1dad4113a5888be6e350c7df68dd36e50bdc4c24 Mon Sep 17 00:00:00 2001 From: Luis Date: Fri, 22 Jul 2022 12:30:59 +0200 Subject: [PATCH 1/9] try ci --- conan/tools/cmake/cmakedeps/templates/macros.py | 11 +++++------ .../toolchains/cmake/cmakedeps/test_cmakedeps.py | 3 +-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/conan/tools/cmake/cmakedeps/templates/macros.py b/conan/tools/cmake/cmakedeps/templates/macros.py index 9d3965c0ef4..9f1fdaba659 100644 --- a/conan/tools/cmake/cmakedeps/templates/macros.py +++ b/conan/tools/cmake/cmakedeps/templates/macros.py @@ -56,15 +56,13 @@ def template(self): # Create a micro-target for each lib/a found # Allow only some characters for the target name string(REGEX REPLACE "[^A-Za-z0-9.+_-]" "_" _LIBRARY_NAME ${_LIBRARY_NAME}) - set(_LIB_NAME CONAN_LIB::${package_name}_${_LIBRARY_NAME}${config_suffix}) + set(_LIB_NAME CONAN_LIB::${package_name}_${_LIBRARY_NAME}) if(NOT TARGET ${_LIB_NAME}) # Create a micro-target for each lib/a found add_library(${_LIB_NAME} UNKNOWN IMPORTED) - set_target_properties(${_LIB_NAME} PROPERTIES IMPORTED_LOCATION ${CONAN_FOUND_LIBRARY}) - list(APPEND _CONAN_ACTUAL_TARGETS ${_LIB_NAME}) - else() - message(VERBOSE "Conan: Skipping already existing target: ${_LIB_NAME}") endif() + set_target_properties(${_LIB_NAME} PROPERTIES IMPORTED_LOCATION${config_suffix} ${CONAN_FOUND_LIBRARY}) + list(APPEND _CONAN_ACTUAL_TARGETS ${_LIB_NAME}) list(APPEND _out_libraries_target ${_LIB_NAME}) message(VERBOSE "Conan: Found: ${CONAN_FOUND_LIBRARY}") else() @@ -76,7 +74,8 @@ def template(self): # Add all dependencies to all targets string(REPLACE " " ";" deps_list "${deps}") foreach(_CONAN_ACTUAL_TARGET ${_CONAN_ACTUAL_TARGETS}) - set_property(TARGET ${_CONAN_ACTUAL_TARGET} PROPERTY INTERFACE_LINK_LIBRARIES "${deps_list}" APPEND) + set_property(TARGET ${_CONAN_ACTUAL_TARGET} PROPERTY INTERFACE_LINK_LIBRARIES + $<$:"${deps_list}"> APPEND) endforeach() set(${out_libraries} ${_out_libraries} PARENT_SCOPE) diff --git a/conans/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps.py b/conans/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps.py index eb78c4fd2f5..4cee3ad4d64 100644 --- a/conans/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps.py +++ b/conans/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps.py @@ -153,12 +153,11 @@ def package_info(self): if build_type == "Release": assert "System libs release: %s" % library_name in client.out assert "Libraries to Link release: lib1" in client.out - target_libs = "$<$:;CONAN_LIB::Test_lib1_RELEASE;sys1;>" else: assert "System libs debug: %s" % library_name in client.out assert "Libraries to Link debug: lib1" in client.out - target_libs = "$<$:;CONAN_LIB::Test_lib1_DEBUG;sys1d;>" + target_libs = "$<$:;CONAN_LIB::Test_lib1;{};>".format(build_type, library_name) assert "Target libs: %s" % target_libs in client.out From e21bef627b6e3ae9bf2f8862538c16e2cfa83814 Mon Sep 17 00:00:00 2001 From: Luis Date: Fri, 22 Jul 2022 13:48:21 +0200 Subject: [PATCH 2/9] Simplify link to deps --- conan/tools/cmake/cmakedeps/templates/macros.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/conan/tools/cmake/cmakedeps/templates/macros.py b/conan/tools/cmake/cmakedeps/templates/macros.py index 9f1fdaba659..11b1d68dff9 100644 --- a/conan/tools/cmake/cmakedeps/templates/macros.py +++ b/conan/tools/cmake/cmakedeps/templates/macros.py @@ -74,8 +74,7 @@ def template(self): # Add all dependencies to all targets string(REPLACE " " ";" deps_list "${deps}") foreach(_CONAN_ACTUAL_TARGET ${_CONAN_ACTUAL_TARGETS}) - set_property(TARGET ${_CONAN_ACTUAL_TARGET} PROPERTY INTERFACE_LINK_LIBRARIES - $<$:"${deps_list}"> APPEND) + set_property(TARGET ${_CONAN_ACTUAL_TARGET} PROPERTY INTERFACE_LINK_LIBRARIES${config_suffix} "${deps_list}" APPEND) endforeach() set(${out_libraries} ${_out_libraries} PARENT_SCOPE) From 470d6082200ea44a3ed3c275d70ab02b1a070f35 Mon Sep 17 00:00:00 2001 From: Luis Date: Fri, 22 Jul 2022 15:16:48 +0200 Subject: [PATCH 3/9] Removed dead code --- conan/tools/cmake/cmakedeps/templates/macros.py | 6 ++---- .../cmake/cmakedeps/templates/target_configuration.py | 9 ++------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/conan/tools/cmake/cmakedeps/templates/macros.py b/conan/tools/cmake/cmakedeps/templates/macros.py index 11b1d68dff9..9bef7bb6772 100644 --- a/conan/tools/cmake/cmakedeps/templates/macros.py +++ b/conan/tools/cmake/cmakedeps/templates/macros.py @@ -41,7 +41,7 @@ def template(self): endif() endmacro() - function(conan_package_library_targets libraries package_libdir deps out_libraries out_libraries_target config_suffix package_name) + function(conan_package_library_targets libraries package_libdir deps out_libraries_target config_suffix package_name) set(_out_libraries "") set(_out_libraries_target "") set(_CONAN_ACTUAL_TARGETS "") @@ -51,7 +51,6 @@ def template(self): NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH) if(CONAN_FOUND_LIBRARY) message(VERBOSE "Conan: Library ${_LIBRARY_NAME} found ${CONAN_FOUND_LIBRARY}") - list(APPEND _out_libraries ${CONAN_FOUND_LIBRARY}) # Create a micro-target for each lib/a found # Allow only some characters for the target name @@ -74,10 +73,9 @@ def template(self): # Add all dependencies to all targets string(REPLACE " " ";" deps_list "${deps}") foreach(_CONAN_ACTUAL_TARGET ${_CONAN_ACTUAL_TARGETS}) - set_property(TARGET ${_CONAN_ACTUAL_TARGET} PROPERTY INTERFACE_LINK_LIBRARIES${config_suffix} "${deps_list}" APPEND) + set_property(TARGET ${_CONAN_ACTUAL_TARGET} PROPERTY INTERFACE_LINK_LIBRARIES $<$:"${deps_list}"> APPEND) endforeach() - set(${out_libraries} ${_out_libraries} PARENT_SCOPE) set(${out_libraries_target} ${_out_libraries_target} PARENT_SCOPE) endfunction() diff --git a/conan/tools/cmake/cmakedeps/templates/target_configuration.py b/conan/tools/cmake/cmakedeps/templates/target_configuration.py index 277b5814be6..1dae0bda13e 100644 --- a/conan/tools/cmake/cmakedeps/templates/target_configuration.py +++ b/conan/tools/cmake/cmakedeps/templates/target_configuration.py @@ -63,28 +63,25 @@ def template(self): set(_{{ pkg_name }}_DEPENDENCIES{{ config_suffix }} "{{ '${' }}{{ pkg_name }}_FRAMEWORKS_FOUND{{ config_suffix }}} {{ '${' }}{{ pkg_name }}_SYSTEM_LIBS{{ config_suffix }}} {{ deps_targets_names }}") set({{ pkg_name }}_LIBRARIES_TARGETS{{ config_suffix }} "") # Will be filled later - set({{ pkg_name }}_LIBRARIES{{ config_suffix }} "") # Will be filled later conan_package_library_targets("{{ '${' }}{{ pkg_name }}_LIBS{{ config_suffix }}}" # libraries "{{ '${' }}{{ pkg_name }}_LIB_DIRS{{ config_suffix }}}" # package_libdir "{{ '${' }}_{{ pkg_name }}_DEPENDENCIES{{ config_suffix }}}" # deps - {{ pkg_name }}_LIBRARIES{{ config_suffix }} # out_libraries {{ pkg_name }}_LIBRARIES_TARGETS{{ config_suffix }} # out_libraries_targets "{{ config_suffix }}" # config_suffix "{{ pkg_name }}") # package_name foreach(_FRAMEWORK {{ '${' }}{{ pkg_name }}_FRAMEWORKS_FOUND{{ config_suffix }}}) list(APPEND {{ pkg_name }}_LIBRARIES_TARGETS{{ config_suffix }} ${_FRAMEWORK}) - list(APPEND {{ pkg_name }}_LIBRARIES{{ config_suffix }} ${_FRAMEWORK}) endforeach() foreach(_SYSTEM_LIB {{ '${' }}{{ pkg_name }}_SYSTEM_LIBS{{ config_suffix }}}) list(APPEND {{ pkg_name }}_LIBRARIES_TARGETS{{ config_suffix }} ${_SYSTEM_LIB}) - list(APPEND {{ pkg_name }}_LIBRARIES{{ config_suffix }} ${_SYSTEM_LIB}) endforeach() # We need to add our requirements too set({{ pkg_name }}_LIBRARIES_TARGETS{{ config_suffix }} {{ '"${' }}{{ pkg_name }}_LIBRARIES_TARGETS{{ config_suffix }}{{ '};' }}{{ deps_targets_names }}") - set({{ pkg_name }}_LIBRARIES{{ config_suffix }} {{ '"${' }}{{ pkg_name }}_LIBRARIES{{ config_suffix }}{{ '};' }}{{ deps_targets_names }}") + # This is a copy of the variable above + set({{ pkg_name }}_LIBRARIES{{ config_suffix }} {{ '${' }}{{ pkg_name }}_LIBRARIES_TARGETS{{ config_suffix }}}) # 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}) @@ -98,12 +95,10 @@ def template(self): 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+'}' }}") set({{ pkg_name }}_{{ comp_variable_name }}_LIB_TARGETS{{ config_suffix }} "") - set({{ pkg_name }}_{{ comp_variable_name }}_NOT_USED{{ config_suffix }} "") set({{ pkg_name }}_{{ comp_variable_name }}_LIBS_FRAMEWORKS_DEPS{{ config_suffix }} {{ '${'+pkg_name+'_'+comp_variable_name+'_FRAMEWORKS_FOUND'+config_suffix+'}' }} {{ '${'+pkg_name+'_'+comp_variable_name+'_SYSTEM_LIBS'+config_suffix+'}' }} {{ '${'+pkg_name+'_'+comp_variable_name+'_DEPENDENCIES'+config_suffix+'}' }}) 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+'_LIBS_FRAMEWORKS_DEPS'+config_suffix+'}' }}" - {{ pkg_name }}_{{ comp_variable_name }}_NOT_USED{{ config_suffix }} {{ pkg_name }}_{{ comp_variable_name }}_LIB_TARGETS{{ config_suffix }} "{{ config_suffix }}" "{{ pkg_name }}_{{ comp_variable_name }}") From fedbc2c88762117fd8c778220432745ff7301231 Mon Sep 17 00:00:00 2001 From: Luis Date: Tue, 26 Jul 2022 09:26:13 +0200 Subject: [PATCH 4/9] Fixes --- .../tools/cmake/cmakedeps/templates/macros.py | 12 +++++++++--- .../templates/target_configuration.py | 19 ++++++++++--------- .../cmake/cmakedeps/test_cmakedeps.py | 4 ++-- .../cmake/cmakedeps/test_link_order.py | 3 ++- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/conan/tools/cmake/cmakedeps/templates/macros.py b/conan/tools/cmake/cmakedeps/templates/macros.py index 9bef7bb6772..b1825afd733 100644 --- a/conan/tools/cmake/cmakedeps/templates/macros.py +++ b/conan/tools/cmake/cmakedeps/templates/macros.py @@ -41,7 +41,7 @@ def template(self): endif() endmacro() - function(conan_package_library_targets libraries package_libdir deps out_libraries_target config_suffix package_name) + function(conan_package_library_targets libraries package_libdir deps out_libraries_target config package_name) set(_out_libraries "") set(_out_libraries_target "") set(_CONAN_ACTUAL_TARGETS "") @@ -60,7 +60,7 @@ def template(self): # Create a micro-target for each lib/a found add_library(${_LIB_NAME} UNKNOWN IMPORTED) endif() - set_target_properties(${_LIB_NAME} PROPERTIES IMPORTED_LOCATION${config_suffix} ${CONAN_FOUND_LIBRARY}) + set_target_properties(${_LIB_NAME} PROPERTIES IMPORTED_LOCATION_${config} ${CONAN_FOUND_LIBRARY}) list(APPEND _CONAN_ACTUAL_TARGETS ${_LIB_NAME}) list(APPEND _out_libraries_target ${_LIB_NAME}) message(VERBOSE "Conan: Found: ${CONAN_FOUND_LIBRARY}") @@ -73,7 +73,13 @@ def template(self): # Add all dependencies to all targets string(REPLACE " " ";" deps_list "${deps}") foreach(_CONAN_ACTUAL_TARGET ${_CONAN_ACTUAL_TARGETS}) - set_property(TARGET ${_CONAN_ACTUAL_TARGET} PROPERTY INTERFACE_LINK_LIBRARIES $<$:"${deps_list}"> APPEND) + set_property(TARGET ${_CONAN_ACTUAL_TARGET} PROPERTY INTERFACE_LINK_LIBRARIES $<$:${deps_list}> APPEND) + endforeach() + + # ONLY FOR DEBUGGING PURPOSES + foreach(_CONAN_ACTUAL_TARGET ${_CONAN_ACTUAL_TARGETS}) + get_target_property(linked_libs ${_CONAN_ACTUAL_TARGET} INTERFACE_LINK_LIBRARIES) + message(VERBOSE "***********Target Properties: ${_CONAN_ACTUAL_TARGET} INTERFACE_LINK_LIBRARIES ='${linked_libs}'") endforeach() set(${out_libraries_target} ${_out_libraries_target} PARENT_SCOPE) diff --git a/conan/tools/cmake/cmakedeps/templates/target_configuration.py b/conan/tools/cmake/cmakedeps/templates/target_configuration.py index 1dae0bda13e..a59c13a2cb6 100644 --- a/conan/tools/cmake/cmakedeps/templates/target_configuration.py +++ b/conan/tools/cmake/cmakedeps/templates/target_configuration.py @@ -31,6 +31,7 @@ def context(self): return {"pkg_name": self.pkg_name, "root_target_name": self.root_target_name, "config_suffix": self.config_suffix, + "config": self.configuration.upper(), "deps_targets_names": ";".join(deps_targets_names), "components_names": components_names, "configuration": self.cmakedeps.configuration, @@ -66,22 +67,22 @@ def template(self): conan_package_library_targets("{{ '${' }}{{ pkg_name }}_LIBS{{ config_suffix }}}" # libraries "{{ '${' }}{{ pkg_name }}_LIB_DIRS{{ config_suffix }}}" # package_libdir "{{ '${' }}_{{ pkg_name }}_DEPENDENCIES{{ config_suffix }}}" # deps - {{ pkg_name }}_LIBRARIES_TARGETS{{ config_suffix }} # out_libraries_targets - "{{ config_suffix }}" # config_suffix + {{ pkg_name }}_LIBRARIES_TARGETS # out_libraries_targets + "{{ config }}" # DEBUG, RELEASE ... "{{ pkg_name }}") # package_name foreach(_FRAMEWORK {{ '${' }}{{ pkg_name }}_FRAMEWORKS_FOUND{{ config_suffix }}}) - list(APPEND {{ pkg_name }}_LIBRARIES_TARGETS{{ config_suffix }} ${_FRAMEWORK}) + list(APPEND {{ pkg_name }}_LIBRARIES_TARGETS ${_FRAMEWORK}) endforeach() foreach(_SYSTEM_LIB {{ '${' }}{{ pkg_name }}_SYSTEM_LIBS{{ config_suffix }}}) - list(APPEND {{ pkg_name }}_LIBRARIES_TARGETS{{ config_suffix }} ${_SYSTEM_LIB}) + list(APPEND {{ pkg_name }}_LIBRARIES_TARGETS ${_SYSTEM_LIB}) endforeach() # We need to add our requirements too - set({{ pkg_name }}_LIBRARIES_TARGETS{{ config_suffix }} {{ '"${' }}{{ pkg_name }}_LIBRARIES_TARGETS{{ config_suffix }}{{ '};' }}{{ deps_targets_names }}") + set({{ pkg_name }}_LIBRARIES_TARGETS {{ '"${' }}{{ pkg_name }}_LIBRARIES_TARGETS{{ '};' }}{{ deps_targets_names }}") # This is a copy of the variable above - set({{ pkg_name }}_LIBRARIES{{ config_suffix }} {{ '${' }}{{ pkg_name }}_LIBRARIES_TARGETS{{ config_suffix }}}) + set({{ pkg_name }}_LIBRARIES{{ config_suffix }} {{ '${' }}{{ pkg_name }}_LIBRARIES_TARGETS}) # 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}) @@ -100,7 +101,7 @@ def template(self): "{{ '${'+pkg_name+'_'+comp_variable_name+'_LIB_DIRS'+config_suffix+'}' }}" "{{ '${'+pkg_name+'_'+comp_variable_name+'_LIBS_FRAMEWORKS_DEPS'+config_suffix+'}' }}" {{ pkg_name }}_{{ comp_variable_name }}_LIB_TARGETS{{ config_suffix }} - "{{ config_suffix }}" + "{{ config }}" # DEBUG, RELEASE... "{{ pkg_name }}_{{ comp_variable_name }}") set({{ pkg_name }}_{{ comp_variable_name }}_LINK_LIBS{{ config_suffix }} {{ '${'+pkg_name+'_'+comp_variable_name+'_LIB_TARGETS'+config_suffix+'}' }} {{ '${'+pkg_name+'_'+comp_variable_name+'_LIBS_FRAMEWORKS_DEPS'+config_suffix+'}' }}) @@ -111,8 +112,8 @@ def template(self): ########## GLOBAL TARGET PROPERTIES {{ configuration }} ######################################## set_property(TARGET {{root_target_name}} PROPERTY INTERFACE_LINK_LIBRARIES - $<$:${{'{'}}{{pkg_name}}_OBJECTS{{config_suffix}}} - ${{'{'}}{{pkg_name}}_LIBRARIES_TARGETS{{config_suffix}}}> APPEND) + $<$:${{'{'}}{{pkg_name}}_OBJECTS{{config_suffix}}}> + ${{'{'}}{{pkg_name}}_LIBRARIES_TARGETS} APPEND) set_property(TARGET {{root_target_name}} PROPERTY INTERFACE_LINK_OPTIONS diff --git a/conans/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps.py b/conans/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps.py index 4cee3ad4d64..16201e3f8c6 100644 --- a/conans/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps.py +++ b/conans/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps.py @@ -157,8 +157,8 @@ def package_info(self): assert "System libs debug: %s" % library_name in client.out assert "Libraries to Link debug: lib1" in client.out - target_libs = "$<$:;CONAN_LIB::Test_lib1;{};>".format(build_type, library_name) - assert "Target libs: %s" % target_libs in client.out + target_libs = ";CONAN_LIB::Test_lib1;{}".format(library_name) + assert target_libs in client.out @pytest.mark.tool_cmake diff --git a/conans/test/functional/toolchains/cmake/cmakedeps/test_link_order.py b/conans/test/functional/toolchains/cmake/cmakedeps/test_link_order.py index bbfb66c3b6d..cb2718ea63b 100644 --- a/conans/test/functional/toolchains/cmake/cmakedeps/test_link_order.py +++ b/conans/test/functional/toolchains/cmake/cmakedeps/test_link_order.py @@ -302,8 +302,9 @@ def _create_find_package_project(client): def _run_and_get_lib_order(t, generator): if generator == "Xcode": t.run_command("cmake . -G Xcode -DCMAKE_VERBOSE_MAKEFILE:BOOL=True" + " -DCMAKE_CONFIGURATION_TYPES=Release" " -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake") - t.run_command("cmake --build .") + t.run_command("cmake --build .", assert_error=True) # Get the actual link order from the CMake call libs = _get_link_order_from_xcode(t.load(os.path.join('executable.xcodeproj', 'project.pbxproj'))) From cb90658d05b41272a9e15891c0babab4637d2f8d Mon Sep 17 00:00:00 2001 From: Luis Date: Tue, 26 Jul 2022 13:45:40 +0200 Subject: [PATCH 5/9] Fix tests --- .../tools/cmake/cmakedeps/templates/macros.py | 5 ++++- .../cmake/cmakedeps/test_link_order.py | 19 +++++++++++++------ .../cmake/cmakedeps/test_cmakedeps.py | 4 ++-- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/conan/tools/cmake/cmakedeps/templates/macros.py b/conan/tools/cmake/cmakedeps/templates/macros.py index b1825afd733..e5f3f3a22eb 100644 --- a/conan/tools/cmake/cmakedeps/templates/macros.py +++ b/conan/tools/cmake/cmakedeps/templates/macros.py @@ -60,6 +60,9 @@ def template(self): # Create a micro-target for each lib/a found add_library(${_LIB_NAME} UNKNOWN IMPORTED) endif() + # Enable configuration only when it is available to avoid missing configs + set_property(TARGET ${_LIB_NAME} APPEND PROPERTY IMPORTED_CONFIGURATIONS ${config}) + # Link library file set_target_properties(${_LIB_NAME} PROPERTIES IMPORTED_LOCATION_${config} ${CONAN_FOUND_LIBRARY}) list(APPEND _CONAN_ACTUAL_TARGETS ${_LIB_NAME}) list(APPEND _out_libraries_target ${_LIB_NAME}) @@ -79,7 +82,7 @@ def template(self): # ONLY FOR DEBUGGING PURPOSES foreach(_CONAN_ACTUAL_TARGET ${_CONAN_ACTUAL_TARGETS}) get_target_property(linked_libs ${_CONAN_ACTUAL_TARGET} INTERFACE_LINK_LIBRARIES) - message(VERBOSE "***********Target Properties: ${_CONAN_ACTUAL_TARGET} INTERFACE_LINK_LIBRARIES ='${linked_libs}'") + message(VERBOSE "Target Properties: ${_CONAN_ACTUAL_TARGET} INTERFACE_LINK_LIBRARIES ='${linked_libs}'") endforeach() set(${out_libraries_target} ${_out_libraries_target} PARENT_SCOPE) diff --git a/conans/test/functional/toolchains/cmake/cmakedeps/test_link_order.py b/conans/test/functional/toolchains/cmake/cmakedeps/test_link_order.py index cb2718ea63b..c2c03b96e5f 100644 --- a/conans/test/functional/toolchains/cmake/cmakedeps/test_link_order.py +++ b/conans/test/functional/toolchains/cmake/cmakedeps/test_link_order.py @@ -1,5 +1,6 @@ import os import platform +import re import textwrap import pytest @@ -257,12 +258,19 @@ def _get_link_order_from_cmake(content): def _get_link_order_from_xcode(content): libs = [] - start_key = '-headerpad_max_install_names",' + + # Find the right Release block in the XCode file + results = re.finditer('/\* Release \*/ = {', content) + for r in results: + release_section = content[r.start():].split("name = Release;", 1)[0] + if "-headerpad_max_install_names" in release_section: + break + else: + raise Exception("Cannot find the Release block linking the expected libraries") + + start_key = '-Wl,-headerpad_max_install_names' end_key = ');' - libs_content = content.split(start_key, 1)[1].split(end_key, 1)[0] - if libs_content == '"$(inherited)"': - # FIXME: Dirty hack, sometimes the library list is not at the 1 but at 2 - libs_content = content.split(start_key, 1)[2].split(end_key, 1)[0] + libs_content = release_section.split(start_key, 1)[1].split(end_key, 1)[0] libs_unstripped = libs_content.split(",") for lib in libs_unstripped: if ".a" in lib: @@ -302,7 +310,6 @@ def _create_find_package_project(client): def _run_and_get_lib_order(t, generator): if generator == "Xcode": t.run_command("cmake . -G Xcode -DCMAKE_VERBOSE_MAKEFILE:BOOL=True" - " -DCMAKE_CONFIGURATION_TYPES=Release" " -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake") t.run_command("cmake --build .", assert_error=True) # Get the actual link order from the CMake call diff --git a/conans/test/integration/toolchains/cmake/cmakedeps/test_cmakedeps.py b/conans/test/integration/toolchains/cmake/cmakedeps/test_cmakedeps.py index bd1aa44a149..1fe84e13756 100644 --- a/conans/test/integration/toolchains/cmake/cmakedeps/test_cmakedeps.py +++ b/conans/test/integration/toolchains/cmake/cmakedeps/test_cmakedeps.py @@ -109,8 +109,8 @@ def package_info(self): ${hello_hello_say_LINK_LIBS_RELEASE}> APPEND)""" in content assert """set_property(TARGET hello::hello PROPERTY INTERFACE_LINK_LIBRARIES - $<$:${hello_OBJECTS_RELEASE} - ${hello_LIBRARIES_TARGETS_RELEASE}> APPEND)""" in content + $<$:${hello_OBJECTS_RELEASE}> + ${hello_LIBRARIES_TARGETS} APPEND)""" in content with open(os.path.join(client.current_folder, "hello-release-x86_64-data.cmake")) as f: content = f.read() From 307bb66ba5bb816cdd5768288ea4e277ba7a6388 Mon Sep 17 00:00:00 2001 From: Luis Date: Wed, 27 Jul 2022 11:59:25 +0200 Subject: [PATCH 6/9] Fix generator expression for system libs and frameworks --- .../tools/cmake/cmakedeps/templates/target_configuration.py | 4 ++-- .../functional/toolchains/cmake/cmakedeps/test_link_order.py | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/conan/tools/cmake/cmakedeps/templates/target_configuration.py b/conan/tools/cmake/cmakedeps/templates/target_configuration.py index 0a8aa041b7b..34ca016dc58 100644 --- a/conan/tools/cmake/cmakedeps/templates/target_configuration.py +++ b/conan/tools/cmake/cmakedeps/templates/target_configuration.py @@ -112,8 +112,8 @@ def template(self): ########## GLOBAL TARGET PROPERTIES {{ configuration }} ######################################## set_property(TARGET {{root_target_name}} PROPERTY INTERFACE_LINK_LIBRARIES - $<$:${{'{'}}{{pkg_name}}_OBJECTS{{config_suffix}}}> - ${{'{'}}{{pkg_name}}_LIBRARIES_TARGETS} APPEND) + $<$:${{'{'}}{{pkg_name}}_OBJECTS{{config_suffix}}} + ${{'{'}}{{pkg_name}}_LIBRARIES_TARGETS}> APPEND) set_property(TARGET {{root_target_name}} PROPERTY INTERFACE_LINK_OPTIONS diff --git a/conans/test/functional/toolchains/cmake/cmakedeps/test_link_order.py b/conans/test/functional/toolchains/cmake/cmakedeps/test_link_order.py index c2c03b96e5f..07b16e74221 100644 --- a/conans/test/functional/toolchains/cmake/cmakedeps/test_link_order.py +++ b/conans/test/functional/toolchains/cmake/cmakedeps/test_link_order.py @@ -311,7 +311,10 @@ def _run_and_get_lib_order(t, generator): if generator == "Xcode": t.run_command("cmake . -G Xcode -DCMAKE_VERBOSE_MAKEFILE:BOOL=True" " -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake") - t.run_command("cmake --build .", assert_error=True) + # This is building by default the Debug configuration that contains nothing, so it works + t.run_command("cmake --build .") + # This is building the release and fails because invented system libraries are missing + t.run_command("cmake --build . --config Release", assert_error=True) # Get the actual link order from the CMake call libs = _get_link_order_from_xcode(t.load(os.path.join('executable.xcodeproj', 'project.pbxproj'))) From 91933762620e55e54bb9a9576983a162ae645f13 Mon Sep 17 00:00:00 2001 From: Luis Date: Wed, 27 Jul 2022 17:48:43 +0200 Subject: [PATCH 7/9] Refactor --- .../templates/target_configuration.py | 68 ++++++++++--------- .../cmake/cmakedeps/test_cmakedeps.py | 4 +- .../cmakedeps/test_cmakedeps_components.py | 4 +- 3 files changed, 42 insertions(+), 34 deletions(-) diff --git a/conan/tools/cmake/cmakedeps/templates/target_configuration.py b/conan/tools/cmake/cmakedeps/templates/target_configuration.py index 34ca016dc58..74220be083d 100644 --- a/conan/tools/cmake/cmakedeps/templates/target_configuration.py +++ b/conan/tools/cmake/cmakedeps/templates/target_configuration.py @@ -61,7 +61,8 @@ def template(self): conan_find_apple_frameworks({{ pkg_name }}_FRAMEWORKS_FOUND{{ config_suffix }} "{{ '${' }}{{ pkg_name }}_FRAMEWORKS{{ config_suffix }}}" "{{ '${' }}{{ pkg_name }}_FRAMEWORK_DIRS{{ config_suffix }}}") # Gather all the libraries that should be linked to the targets (do not touch existing variables) - set(_{{ pkg_name }}_DEPENDENCIES{{ config_suffix }} "{{ '${' }}{{ pkg_name }}_FRAMEWORKS_FOUND{{ config_suffix }}} {{ '${' }}{{ pkg_name }}_SYSTEM_LIBS{{ config_suffix }}} {{ deps_targets_names }}") + # FIXME: Why is needed to pass all the dependencies to link with the micro-targets? + set(_{{ pkg_name }}_DEPENDENCIES{{ config_suffix }} "{{ deps_targets_names }}") set({{ pkg_name }}_LIBRARIES_TARGETS{{ config_suffix }} "") # Will be filled later conan_package_library_targets("{{ '${' }}{{ pkg_name }}_LIBS{{ config_suffix }}}" # libraries @@ -71,49 +72,32 @@ def template(self): "{{ config }}" # DEBUG, RELEASE ... "{{ pkg_name }}") # package_name + # The XXXX_LIBRARIES_RELEASE/DEBUG is used for the module (FindXXX.cmake) foreach(_FRAMEWORK {{ '${' }}{{ pkg_name }}_FRAMEWORKS_FOUND{{ config_suffix }}}) - list(APPEND {{ pkg_name }}_LIBRARIES_TARGETS ${_FRAMEWORK}) + list(APPEND {{ pkg_name }}_LIBRARIES{{ config_suffix }} ${_FRAMEWORK}) endforeach() foreach(_SYSTEM_LIB {{ '${' }}{{ pkg_name }}_SYSTEM_LIBS{{ config_suffix }}}) - list(APPEND {{ pkg_name }}_LIBRARIES_TARGETS ${_SYSTEM_LIB}) + list(APPEND {{ pkg_name }}_LIBRARIES{{ config_suffix }} ${_SYSTEM_LIB}) endforeach() # We need to add our requirements too - set({{ pkg_name }}_LIBRARIES_TARGETS {{ '"${' }}{{ pkg_name }}_LIBRARIES_TARGETS{{ '};' }}{{ deps_targets_names }}") - # This is a copy of the variable above - set({{ pkg_name }}_LIBRARIES{{ config_suffix }} {{ '${' }}{{ pkg_name }}_LIBRARIES_TARGETS}) + list(APPEND {{ pkg_name }}_LIBRARIES{{ config_suffix }} {{ deps_targets_names }}) # 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_PREFIX_PATH {{ '${' }}{{ pkg_name }}_BUILD_DIRS{{ config_suffix }}} {{ '${' }}CMAKE_PREFIX_PATH}) - {%- for comp_variable_name, comp_target_name in components_names %} - - ########## COMPONENT {{ comp_target_name }} FIND LIBRARIES & FRAMEWORKS / DYNAMIC VARS ############# - - 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+'}' }}") - - set({{ pkg_name }}_{{ comp_variable_name }}_LIB_TARGETS{{ config_suffix }} "") - set({{ pkg_name }}_{{ comp_variable_name }}_LIBS_FRAMEWORKS_DEPS{{ config_suffix }} {{ '${'+pkg_name+'_'+comp_variable_name+'_FRAMEWORKS_FOUND'+config_suffix+'}' }} {{ '${'+pkg_name+'_'+comp_variable_name+'_SYSTEM_LIBS'+config_suffix+'}' }} {{ '${'+pkg_name+'_'+comp_variable_name+'_DEPENDENCIES'+config_suffix+'}' }}) - 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+'_LIBS_FRAMEWORKS_DEPS'+config_suffix+'}' }}" - {{ pkg_name }}_{{ comp_variable_name }}_LIB_TARGETS{{ config_suffix }} - "{{ config }}" # DEBUG, RELEASE... - "{{ pkg_name }}_{{ comp_variable_name }}") - - set({{ pkg_name }}_{{ comp_variable_name }}_LINK_LIBS{{ config_suffix }} {{ '${'+pkg_name+'_'+comp_variable_name+'_LIB_TARGETS'+config_suffix+'}' }} {{ '${'+pkg_name+'_'+comp_variable_name+'_LIBS_FRAMEWORKS_DEPS'+config_suffix+'}' }}) - {%- endfor %} - - {% if not components_names %} ########## GLOBAL TARGET PROPERTIES {{ configuration }} ######################################## set_property(TARGET {{root_target_name}} PROPERTY INTERFACE_LINK_LIBRARIES - $<$:${{'{'}}{{pkg_name}}_OBJECTS{{config_suffix}}} - ${{'{'}}{{pkg_name}}_LIBRARIES_TARGETS}> APPEND) + $<$:${{'{'}}{{pkg_name}}_OBJECTS{{config_suffix}}}> + ${{'{'}}{{pkg_name}}_LIBRARIES_TARGETS} + $<$:${{'{'}}_{{pkg_name}}_DEPENDENCIES{{config_suffix}}}> + $<$:${{'{'}}{{pkg_name}}_FRAMEWORKS_FOUND{{config_suffix}}}> + $<$:${{'{'}}{{pkg_name}}_SYSTEM_LIBS{{config_suffix}}}> + APPEND) set_property(TARGET {{root_target_name}} PROPERTY INTERFACE_LINK_OPTIONS @@ -142,10 +126,30 @@ def template(self): {%- for comp_variable_name, comp_target_name in components_names %} - ########## COMPONENT {{ comp_target_name }} TARGET PROPERTIES ###################################### - set_property(TARGET {{ comp_target_name }} PROPERTY INTERFACE_LINK_LIBRARIES - $<$:{{tvalue(pkg_name, comp_variable_name, 'OBJECTS', config_suffix)}} - {{tvalue(pkg_name, comp_variable_name, 'LINK_LIBS', config_suffix)}}> APPEND) + ########## COMPONENT {{ comp_target_name }} FIND LIBRARIES & FRAMEWORKS / DYNAMIC VARS ############# + + 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+'}' }}") + + set({{ pkg_name }}_{{ comp_variable_name }}_LIBRARIES_TARGETS "") + + 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+'_DEPENDENCIES'+config_suffix+'}' }}" + {{ pkg_name }}_{{ comp_variable_name }}_LIBRARIES_TARGETS + "{{ config }}" # DEBUG, RELEASE... + "{{ pkg_name }}_{{ comp_variable_name }}") + + ########## COMPONENT {{ comp_target_name }} TARGET PROPERTIES ##################################### + set_property(TARGET {{comp_target_name}} + PROPERTY INTERFACE_LINK_LIBRARIES + $<$:${{'{'}}{{pkg_name}}_{{comp_variable_name}}_OBJECTS{{config_suffix}}}> + ${{'{'}}{{pkg_name}}_{{comp_variable_name}}_LIBRARIES_TARGETS} + $<$:${{'{'}}{{pkg_name}}_{{comp_variable_name}}_DEPENDENCIES{{config_suffix}}}> + $<$:${{'{'}}{{pkg_name}}_{{comp_variable_name}}_FRAMEWORKS_FOUND{{config_suffix}}}> + $<$:${{'{'}}{{pkg_name}}_{{comp_variable_name}}_SYSTEM_LIBS{{config_suffix}}}> + APPEND) + set_property(TARGET {{ comp_target_name }} PROPERTY INTERFACE_LINK_OPTIONS $<$:{{tvalue(pkg_name, comp_variable_name, 'LINKER_FLAGS', config_suffix)}}> APPEND) set_property(TARGET {{ comp_target_name }} PROPERTY INTERFACE_INCLUDE_DIRECTORIES diff --git a/conans/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps.py b/conans/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps.py index 16201e3f8c6..4e4f7b9f7d3 100644 --- a/conans/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps.py +++ b/conans/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps.py @@ -157,7 +157,9 @@ def package_info(self): assert "System libs debug: %s" % library_name in client.out assert "Libraries to Link debug: lib1" in client.out - target_libs = ";CONAN_LIB::Test_lib1;{}".format(library_name) + # FIXME: This assert is ugly, empty configs comes from empty _OBJECTS, FRAMEWORKS etc + target_libs = f"$<$:>;CONAN_LIB::Test_lib1;$<$" \ + f":>;$<$:>;$<$:{library_name}>" assert target_libs in client.out diff --git a/conans/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps_components.py b/conans/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps_components.py index e2919cf0d08..e2b4a0cdc23 100644 --- a/conans/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps_components.py +++ b/conans/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps_components.py @@ -204,7 +204,9 @@ def build(self): t.save({"conanfile.py": conanfile, "CMakeLists.txt": cmakelists}) t.run("create . --build missing -s build_type=Release") - assert 'component libs: $<$:;system_lib_component>' in t.out + # FIXME: This assert is ugly, empty configs comes from empty _OBJECTS, FRAMEWORKS etc + assert 'component libs: $<$:>;$<$:>;$<$:>' \ + ';$<$:system_lib_component>' in t.out assert ('component options: ' '$<$:' '$<$,SHARED_LIBRARY>:>;' From 5f3026a8b478a6ce3159646e05b88fea5761f238 Mon Sep 17 00:00:00 2001 From: Luis Date: Wed, 27 Jul 2022 17:56:59 +0200 Subject: [PATCH 8/9] Fix test --- .../toolchains/cmake/cmakedeps/test_cmakedeps.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/conans/test/integration/toolchains/cmake/cmakedeps/test_cmakedeps.py b/conans/test/integration/toolchains/cmake/cmakedeps/test_cmakedeps.py index 41afff32af6..558c1c83fe5 100644 --- a/conans/test/integration/toolchains/cmake/cmakedeps/test_cmakedeps.py +++ b/conans/test/integration/toolchains/cmake/cmakedeps/test_cmakedeps.py @@ -104,14 +104,15 @@ def package_info(self): client.run("install hello/1.0@ -g CMakeDeps -s arch=x86_64 -s build_type=Release") with open(os.path.join(client.current_folder, "hello-Target-release.cmake")) as f: content = f.read() - assert """set_property(TARGET hello::say PROPERTY INTERFACE_LINK_LIBRARIES - $<$:${hello_hello_say_OBJECTS_RELEASE} - ${hello_hello_say_LINK_LIBS_RELEASE}> APPEND)""" in content + assert """set_property(TARGET hello::say + PROPERTY INTERFACE_LINK_LIBRARIES + $<$:${hello_hello_say_OBJECTS_RELEASE}> + ${hello_hello_say_LIBRARIES_TARGETS}""" in content # If there are componets, there is not a global cpp so this is not generated assert """set_property(TARGET hello::hello PROPERTY INTERFACE_LINK_LIBRARIES $<$:${hello_OBJECTS_RELEASE}> - ${hello_LIBRARIES_TARGETS} APPEND)""" not in content + ${hello_LIBRARIES_TARGETS}""" not in content # But the global target is linked with the targets from the components assert "target_link_libraries(hello::hello INTERFACE hello::say)" in content From 9340ce16140006491cf575da9a203faa93d44afb Mon Sep 17 00:00:00 2001 From: Luis Date: Wed, 27 Jul 2022 20:08:30 +0200 Subject: [PATCH 9/9] Fix win test? --- conan/tools/cmake/cmakedeps/templates/target_configuration.py | 1 + 1 file changed, 1 insertion(+) diff --git a/conan/tools/cmake/cmakedeps/templates/target_configuration.py b/conan/tools/cmake/cmakedeps/templates/target_configuration.py index 74220be083d..21bfa56ff35 100644 --- a/conan/tools/cmake/cmakedeps/templates/target_configuration.py +++ b/conan/tools/cmake/cmakedeps/templates/target_configuration.py @@ -82,6 +82,7 @@ def template(self): endforeach() # We need to add our requirements too + set({{ pkg_name }}_LIBRARIES{{ config_suffix }} "") list(APPEND {{ pkg_name }}_LIBRARIES{{ config_suffix }} {{ deps_targets_names }}) # FIXME: What is the result of this for multi-config? All configs adding themselves to path?