Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMakeDeps: Variables for merged global target, even when only components #11874

Merged
merged 1 commit into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 5 additions & 6 deletions conan/tools/cmake/cmakedeps/templates/target_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ def template(self):
set({{ pkg_name }}_PACKAGE_FOLDER{{ config_suffix }} "{{ package_folder }}")
set({{ pkg_name }}_BUILD_MODULES_PATHS{{ config_suffix }} {{ global_cpp.build_modules_paths }})

{% if not has_components %}

set({{ pkg_name }}_INCLUDE_DIRS{{ config_suffix }} {{ global_cpp.include_paths }})
set({{ pkg_name }}_RES_DIRS{{ config_suffix }} {{ global_cpp.res_paths }})
Expand All @@ -104,7 +103,7 @@ def template(self):
set({{ pkg_name }}_FRAMEWORK_DIRS{{ config_suffix }} {{ global_cpp.framework_paths }})
set({{ pkg_name }}_FRAMEWORKS{{ config_suffix }} {{ global_cpp.frameworks }})
set({{ pkg_name }}_BUILD_DIRS{{ config_suffix }} {{ global_cpp.build_paths }})
{% else %}


set({{ pkg_name }}_COMPONENTS{{ config_suffix }} {{ components_names }})
{%- for comp_variable_name, comp_target_name, cpp in components_cpp %}
Expand All @@ -131,16 +130,16 @@ def template(self):
$<$<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 }}}>
)
{%- endfor %}

{%- endif %}

{%- endfor %}
""")
return ret

def _get_global_cpp_cmake(self):
global_cppinfo = self.conanfile.cpp_info.aggregated_components()
pfolder_var_name = "{}_PACKAGE_FOLDER{}".format(self.pkg_name, self.config_suffix)
return _TargetDataContext(self.conanfile.cpp_info, pfolder_var_name,
self.conanfile.package_folder)
return _TargetDataContext(global_cppinfo, pfolder_var_name, self.conanfile.package_folder)

def _get_required_components_cpp(self):
"""Returns a list of (component_name, DepsCppCMake)"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,10 @@ def package_info(self):

with open(os.path.join(client.current_folder, "hello-release-x86_64-data.cmake")) as f:
content = f.read()
# Not global variables
# https://github.com/conan-io/conan/issues/11862
# Global variables
assert 'set(hello_OBJECTS_RELEASE "${hello_PACKAGE_FOLDER_RELEASE}/mycomponent.o")' \
not in content
in content
# But component variables
assert 'set(hello_hello_say_OBJECTS_RELEASE "${hello_PACKAGE_FOLDER_RELEASE}/' \
'mycomponent.o")' in content
Expand Down
7 changes: 4 additions & 3 deletions conans/test/unittests/tools/cmake/test_cmakedeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@ def test_cpp_info_name_cmakedeps_components():
cmakedeps = CMakeDeps(conanfile)
files = cmakedeps.content
assert "TARGET GlobalPkgName1::MySuperPkg1" in files["ComplexFileName1-Target-debug.cmake"]
# No global variables for the packages
# Global variables for the packages
# https://github.com/conan-io/conan/issues/11862
assert 'set(OriginalDepName_INCLUDE_DIRS_DEBUG ' \
'"${OriginalDepName_PACKAGE_FOLDER_DEBUG}/include")' \
not in files["ComplexFileName1-debug-x64-data.cmake"]
# But components
in files["ComplexFileName1-debug-x64-data.cmake"]
# AND components
assert 'set(OriginalDepName_GlobalPkgName1_MySuperPkg1_INCLUDE_DIRS_DEBUG ' \
'"${OriginalDepName_PACKAGE_FOLDER_DEBUG}/include")' \
in files["ComplexFileName1-debug-x64-data.cmake"]
Expand Down