CPS: Apply imported compile and link properties

Fixes: #28198
This commit is contained in:
Vito Gamberini committed 2026-10-22 17:23:15 -04:00
1 parent 46f45a2c81
commit 111bbed7ae
6 files changed
+115

No files matched your search

+9
View File
@@ -790,6 +790,15 @@ void cmPackageInfoReader::SetTargetProperties(
AddLinkFeature(makefile, target, configuration, def);
}
// Add compile and link flags.
AppendLanguageProperties(
makefile, target, "COMPILE_OPTIONS"_s, configuration, data,
"compile_flags", [](std::string flag) -> std::string { return flag; });
for (std::string const& flag : ReadList(data, "link_flags")) {
AppendProperty(makefile, target, "LINK_OPTIONS"_s, configuration, flag);
}
// Add compile definitions.
Json::Value const& defs = data["definitions"];
DefinitionsMap definitionsMap;
+36
View File
@@ -220,6 +220,42 @@ else()
target_link_libraries(defs-test defs::defs)
endif()
###############################################################################
# Test importing of compile and link flags.
find_package(Flags CONFIG REQUIRED)
expect_property(
Flags::plain INTERFACE_COMPILE_OPTIONS
"compile flags" "-compile-flag;-second-compile-flag")
expect_property(
Flags::plain INTERFACE_LINK_OPTIONS
"link flags" "-link-flag;-second-link-flag")
expect_property(
Flags::configurations INTERFACE_COMPILE_OPTIONS
"configuration-specific compile flags"
"-base-compile;$<$<CONFIG:Debug>:-debug-compile>;$<$<CONFIG:Release>:-release-compile>")
expect_property(
Flags::configurations INTERFACE_LINK_OPTIONS
"configuration-specific link flags"
"-base-link;$<$<CONFIG:Debug>:-debug-link>;$<$<CONFIG:Release>:-release-link>")
expect_property(
Flags::configured_languages INTERFACE_COMPILE_OPTIONS
"configuration- and language-specific compile flags"
"$<$<CONFIG:Debug>:$<$<COMPILE_LANGUAGE:CXX>:-debug-cxx>>")
if(CMAKE_GENERATOR STREQUAL "Xcode" OR CMAKE_GENERATOR MATCHES "Visual Studio")
# VS/Xcode generators cannot represent different target-wide compile options
# for C and C++ sources in the same target, so split the test by language.
add_library(flags-test-c STATIC flags-test-c.c)
add_library(flags-test-cxx STATIC flags-test-cxx.cxx)
target_link_libraries(flags-test-c Flags::languages)
target_link_libraries(flags-test-cxx Flags::languages)
else()
add_library(flags-test STATIC flags-test-c.c flags-test-cxx.cxx)
target_link_libraries(flags-test Flags::languages)
endif()
###############################################################################
# Test importing and mangling of requirements (i.e. link libraries).
+42
View File
@@ -0,0 +1,42 @@
{
"cps_version": "0.13.0",
"name": "Flags",
"cps_path": "@prefix@/cps",
"components": {
"plain": {
"type": "archive",
"location": "@prefix@/lib/libfoo.a",
"compile_flags": [ "-compile-flag", "-second-compile-flag" ],
"link_flags": [ "-link-flag", "-second-link-flag" ]
},
"languages": {
"type": "interface",
"compile_flags": {
"*": [ "-DFLAGS_ALL_LANGUAGES" ],
"c": [ "-DFLAGS_ONLY_IN_C" ],
"cpp": [ "-DFLAGS_ONLY_IN_CXX" ]
}
},
"configurations": {
"type": "interface",
"compile_flags": [ "-base-compile" ],
"link_flags": [ "-base-link" ],
"configurations": {
"Debug": {
"compile_flags": [ "-debug-compile" ],
"link_flags": [ "-debug-link" ]
}
}
},
"configured_languages": {
"type": "interface",
"configurations": {
"Debug": {
"compile_flags": {
"cpp": [ "-debug-cxx" ]
}
}
}
}
}
}
@@ -0,0 +1,10 @@
{
"name": "Flags",
"configuration": "Release",
"components": {
"configurations": {
"compile_flags": [ "-release-compile" ],
"link_flags": [ "-release-link" ]
}
}
}
+9
View File
@@ -0,0 +1,9 @@
#ifndef FLAGS_ALL_LANGUAGES
# error FLAGS_ALL_LANGUAGES is not defined in C sources
#endif
#ifndef FLAGS_ONLY_IN_C
# error FLAGS_ONLY_IN_C is not defined in C sources
#endif
#ifdef FLAGS_ONLY_IN_CXX
# error FLAGS_ONLY_IN_CXX is defined in C sources
#endif
@@ -0,0 +1,9 @@
#ifndef FLAGS_ALL_LANGUAGES
# error FLAGS_ALL_LANGUAGES is not defined in C++ sources
#endif
#ifdef FLAGS_ONLY_IN_C
# error FLAGS_ONLY_IN_C is defined in C++ sources
#endif
#ifndef FLAGS_ONLY_IN_CXX
# error FLAGS_ONLY_IN_CXX is not defined in C++ sources
#endif