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

Add IMPORTED_CONFIGURATIONS property for CMake targets #16705

Open
wants to merge 3 commits into
base: develop2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions conan/tools/cmake/cmakedeps/templates/macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ def template(self):
message(DEBUG "Created target ${_LIB_NAME} ${library_type} IMPORTED")
set_target_properties(${_LIB_NAME} PROPERTIES IMPORTED_LOCATION${config_suffix} ${CONAN_FOUND_LIBRARY} IMPORTED_NO_SONAME ${no_soname_mode})
endif()
string(REGEX REPLACE "^_" "" _CONFIG ${config_suffix})
set_target_properties(${_LIB_NAME} PROPERTIES IMPORTED_CONFIGURATIONS ${_CONFIG})
list(APPEND _out_libraries_target ${_LIB_NAME})
message(VERBOSE "Conan: Found: ${CONAN_FOUND_LIBRARY}")
else()
Expand Down
40 changes: 40 additions & 0 deletions test/functional/toolchains/cmake/cmakedeps/test_cmakedeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,46 @@ def test_error_missing_build_type(matrix_client):
assert "matrix/1.0: Hello World Release!" in client.out


@pytest.mark.tool("cmake", "3.23")
def test_imported_configurations(matrix_client):
# https://github.com/conan-io/conan/issues/11168
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is pointing to another issue? Shouldn't this be #14606 and #16688?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, copy & paste, thanks for pointing this out, I'll fix it in next commit.

client = matrix_client

conanfile = textwrap.dedent("""
[requires]
matrix/1.0
[generators]
CMakeDeps
CMakeToolchain
""")

cmakelists = textwrap.dedent("""
cmake_minimum_required(VERSION 3.15)
project(app)
find_package(matrix REQUIRED)
# The matrix::matrix is not the target defining the data, it is a package interface
get_target_property(configs matrix::matrix IMPORTED_CONFIGURATIONS)
foreach(cfg ${configs})
message(STATUS "matrix::matrix configuration found: ${cfg}!!")
endforeach()
get_target_property(configs CONAN_LIB::matrix_matrix_RELEASE IMPORTED_CONFIGURATIONS)
foreach(cfg ${configs})
message(STATUS "CONAN_LIB::matrix configuration found: ${cfg}!!")
endforeach()
""")

client.save({"conanfile.txt": conanfile,
"CMakeLists.txt": cmakelists}, clean_first=True)

client.run("install .")
client.run_command("cmake . -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake "
"-DCMAKE_BUILD_TYPE=Release")
# TODO: The matrix::matrix target does not contain the information
# this will require the new CMakeDeps generator
assert "matrix::matrix configuration found: configs-NOTFOUND!!" in client.out
assert "CONAN_LIB::matrix configuration found: RELEASE!!" in client.out


@pytest.mark.tool("cmake")
def test_map_imported_config(matrix_client):
# https://github.com/conan-io/conan/issues/12041
Expand Down