mirror of
https://gitlab.kitware.com/cmake/cmake.git
synced 2026-10-06 04:03:27 +03:00
CPS: Support importing "link dependent libraries".
Teach CPS import to read the `dyld_requires` attribute. Fixes: #27501
This commit is contained in:
1 parent
92a0abd164
commit
3071bc6c87
3 files changed
+66
-27
No files matched your search
@@ -250,6 +250,21 @@ void AppendProperty(cmMakefile* makefile, cmTarget* target,
|
||||
}
|
||||
}
|
||||
|
||||
void AppendImportProperty(cmMakefile* makefile, cmTarget* target,
|
||||
cm::string_view property,
|
||||
cm::string_view configuration,
|
||||
std::string const& value)
|
||||
{
|
||||
if (!configuration.empty()) {
|
||||
std::string const fullprop = cmStrCat(
|
||||
"IMPORTED_", property, '_', cmSystemTools::UpperCase(configuration));
|
||||
target->AppendProperty(fullprop, value, makefile->GetBacktrace());
|
||||
} else {
|
||||
std::string const fullprop = cmStrCat("IMPORTED_", property);
|
||||
target->AppendProperty(fullprop, value, makefile->GetBacktrace());
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Transform>
|
||||
void AppendLanguageProperties(cmMakefile* makefile, cmTarget* target,
|
||||
cm::string_view property,
|
||||
@@ -781,6 +796,11 @@ void cmPackageInfoReader::SetTargetProperties(
|
||||
AppendProperty(makefile, target, "LINK_LIBRARIES"_s, configuration, lib);
|
||||
}
|
||||
|
||||
for (std::string const& dep : ReadList(data, "dyld_requires")) {
|
||||
AppendImportProperty(makefile, target, "LINK_DEPENDENT_LIBRARIES"_s,
|
||||
configuration, NormalizeTargetName(dep, package));
|
||||
}
|
||||
|
||||
// TODO: Handle non-configuration modules
|
||||
// once IMPORTED_CXX_MODULES supports it
|
||||
if (!configuration.empty()) {
|
||||
|
||||
@@ -29,6 +29,13 @@ function(expect PACKAGE VAR OP VALUE WHAT)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(expect_property TARGET PROPERTY DESCRIPTION EXPECTED)
|
||||
get_target_property(actual ${TARGET} ${PROPERTY})
|
||||
if(NOT "${actual}" STREQUAL "${EXPECTED}")
|
||||
message(SEND_ERROR "${TARGET} has wrong ${DESCRIPTION} '${actual}' !")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(test_version PACKAGE LITERAL COUNT MAJOR MINOR PATCH TWEAK)
|
||||
if(NOT ${PACKAGE}_FOUND)
|
||||
message(SEND_ERROR "${PACKAGE} not found !")
|
||||
@@ -47,7 +54,7 @@ function(test_unparsed_version PACKAGE VERSION)
|
||||
test_version(${PACKAGE} "${VERSION}" 0 0 0 0 0)
|
||||
endfunction()
|
||||
|
||||
function(test_global TARGET VALUE)
|
||||
function(expect_global TARGET VALUE)
|
||||
get_target_property(global "${TARGET}" IMPORTED_GLOBAL)
|
||||
if((VALUE AND NOT global) OR (NOT VALUE AND global))
|
||||
message(SEND_ERROR "${TARGET} has wrong IMPORTED_GLOBAL '${global}' !")
|
||||
@@ -78,6 +85,7 @@ test_unparsed_version(CustomVersion "VII")
|
||||
|
||||
###############################################################################
|
||||
# Test finding a package whose CPS file is in the package prefix root.
|
||||
|
||||
set(RootTest_DIR "${CMAKE_CURRENT_SOURCE_DIR}/RootTest")
|
||||
find_package(RootTest)
|
||||
if(NOT RootTest_FOUND)
|
||||
@@ -166,21 +174,15 @@ elseif(NOT TARGET Foo::RelativeTest)
|
||||
elseif(NOT TARGET Foo::Empty)
|
||||
message(SEND_ERROR "Foo::Empty missing !")
|
||||
else()
|
||||
get_property(pt_includes
|
||||
TARGET Foo::PrefixTest PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
|
||||
if(NOT "${pt_includes}" STREQUAL "$<$<CONFIG:default>:${CMAKE_CURRENT_SOURCE_DIR}/include>" )
|
||||
message(SEND_ERROR "Foo::PrefixTest has wrong includes '${pt_includes}' !")
|
||||
endif()
|
||||
set(pt_includes)
|
||||
expect_property(
|
||||
Foo::PrefixTest INTERFACE_INCLUDE_DIRECTORIES "includes"
|
||||
"$<$<CONFIG:default>:${CMAKE_CURRENT_SOURCE_DIR}/include>")
|
||||
|
||||
get_property(rt_includes
|
||||
TARGET Foo::RelativeTest PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
|
||||
if(NOT "${rt_includes}" STREQUAL "$<$<CONFIG:default>:${CMAKE_CURRENT_SOURCE_DIR}/cps/../include>")
|
||||
message(SEND_ERROR "Foo::RelativeTest has wrong includes '${rt_includes}' !")
|
||||
endif()
|
||||
set(rt_includes)
|
||||
expect_property(
|
||||
Foo::RelativeTest INTERFACE_INCLUDE_DIRECTORIES "includes"
|
||||
"$<$<CONFIG:default>:${CMAKE_CURRENT_SOURCE_DIR}/cps/../include>")
|
||||
|
||||
test_global(Foo::Empty FALSE)
|
||||
expect_global(Foo::Empty FALSE)
|
||||
endif()
|
||||
|
||||
###############################################################################
|
||||
@@ -192,7 +194,7 @@ if(NOT Global_FOUND)
|
||||
elseif(NOT TARGET Global::Target)
|
||||
message(SEND_ERROR "Global::Target missing !")
|
||||
else()
|
||||
test_global(Foo::Empty FALSE)
|
||||
expect_global(Foo::Empty FALSE)
|
||||
endif()
|
||||
|
||||
###############################################################################
|
||||
@@ -223,6 +225,14 @@ target_link_libraries(requires-test RequiresTest::Indirect)
|
||||
add_executable(requires-test-compile_only requires-test.cxx)
|
||||
target_link_libraries(requires-test-compile_only RequiresTest::CompileOnly)
|
||||
|
||||
expect_property(
|
||||
RequiresTest::Other IMPORTED_LINK_DEPENDENT_LIBRARIES
|
||||
"dyld requirements (any config)" "RequiresTest::Private1")
|
||||
|
||||
expect_property(
|
||||
RequiresTest::Other IMPORTED_LINK_DEPENDENT_LIBRARIES_TEST
|
||||
"dyld requirements ('TEST' config)" "RequiresTest::Private2")
|
||||
|
||||
###############################################################################
|
||||
# Test importing of (language-specific) include paths.
|
||||
|
||||
@@ -343,16 +353,10 @@ elseif(NOT TARGET DefaultConfigurationsTest::Target1)
|
||||
elseif(NOT TARGET DefaultConfigurationsTest::Target2)
|
||||
message(SEND_ERROR "DefaultConfigurationsTest::Target2 missing !")
|
||||
else()
|
||||
get_property(dct1_configs
|
||||
TARGET DefaultConfigurationsTest::Target1 PROPERTY IMPORTED_CONFIGURATIONS)
|
||||
if(NOT "${dct1_configs}" STREQUAL "DEFAULT;TEST")
|
||||
message(SEND_ERROR "DefaultConfigurationsTest::Target1 has wrong configurations '${dct1_configs}' !")
|
||||
endif()
|
||||
get_property(dct2_configs
|
||||
TARGET DefaultConfigurationsTest::Target2 PROPERTY IMPORTED_CONFIGURATIONS)
|
||||
if(NOT "${dct2_configs}" STREQUAL "TEST")
|
||||
message(SEND_ERROR "DefaultConfigurationsTest::Target2 has wrong configurations '${dct2_configs}' !")
|
||||
endif()
|
||||
set(dct1_configs)
|
||||
set(dct2_configs)
|
||||
expect_property(
|
||||
DefaultConfigurationsTest::Target1 IMPORTED_CONFIGURATIONS
|
||||
"configurations" "DEFAULT;TEST")
|
||||
expect_property(
|
||||
DefaultConfigurationsTest::Target2 IMPORTED_CONFIGURATIONS
|
||||
"configurations" "TEST")
|
||||
endif()
|
||||
@@ -27,6 +27,21 @@
|
||||
"ANSWER": 42
|
||||
}
|
||||
}
|
||||
},
|
||||
"Private1": {
|
||||
"type": "dylib"
|
||||
},
|
||||
"Private2": {
|
||||
"type": "dylib"
|
||||
},
|
||||
"Other": {
|
||||
"type": "dylib",
|
||||
"dyld_requires": [ ":Private1" ],
|
||||
"configurations": {
|
||||
"test": {
|
||||
"dyld_requires": [ ":Private2" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user