CPS: Support exporting "link dependent libraries".

Teach CPS export to fill the `dyld_requires` attribute based on the
equivalent of the `IMPORTED_LINK_DEPENDENT_LIBRARIES` CMake property.
(Note that, in practice, I don't believe this can ever contain
non-targets, and CPS does not anyway support the `dyld_libraries`
attribute that those would require at this time.

Issue: #27501
This commit is contained in:
Matthew Woehlke
2026-02-09 16:59:46 -05:00
parent 93891e27cb
commit 92a0abd164
4 changed files with 49 additions and 1 deletions
+17 -1
View File
@@ -30,7 +30,7 @@
#include "cmSystemTools.h"
#include "cmTarget.h"
static std::string const kCPS_VERSION_STR = "0.14.0";
static std::string const kCPS_VERSION_STR = "0.14.1";
cmExportPackageInfoGenerator::cmExportPackageInfoGenerator(
cmPackageInfoArguments arguments)
@@ -565,6 +565,22 @@ Json::Value cmExportPackageInfoGenerator::GenerateInterfaceConfigProperties(
component["location"] = p.second;
} else if (prop == "IMPLIB") {
component["link_location"] = p.second;
} else if (prop == "LINK_DEPENDENT_LIBRARIES") {
bool result;
std::vector<std::string> libraries;
std::vector<std::string> components =
this->ExtractRequirements(cmList{ p.second }, result, libraries);
BuildArray(component, "dyld_requires", components);
if (!libraries.empty()) {
// In theory this can never happen?
this->IssueMessage(
MessageType::AUTHOR_WARNING,
cmStrCat("Package \""_s, this->GetPackageName(),
"\" has IMPORTED_LINK_DEPENDENT_LIBRARIES \""_s,
cmJoin(libraries, ";"_s), this->PackageVersionSchema,
"\". These cannot be exported. "
"Consumers may encounter link errors."_s));
}
} else if (prop == "LINK_INTERFACE_LANGUAGES") {
std::vector<std::string> languages;
for (auto const& lang : cmList{ p.second }) {
@@ -0,0 +1,15 @@
include(${CMAKE_CURRENT_LIST_DIR}/Assertions.cmake)
set(out_dir "${RunCMake_BINARY_DIR}/LinkDependentLibraries-build")
file(READ "${out_dir}/dyld.cps" content)
expect_value("${content}" "dyld" "name")
expect_value("${content}" "dylib" "components" "private" "type")
expect_value("${content}" "dylib" "components" "public" "type")
expect_array(
"${content}" 1
"components" "public" "configurations" "generic" "dyld_requires")
expect_value(
"${content}" ":private"
"components" "public" "configurations" "generic" "dyld_requires" 0)
@@ -0,0 +1,16 @@
project(dyld CXX)
get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(_isMultiConfig)
set(CMAKE_CONFIGURATION_TYPES "generic" CACHE STRING "" FORCE)
else()
set(CMAKE_BUILD_TYPE "generic" CACHE STRING "" FORCE)
endif()
add_library(private SHARED foo.cxx)
add_library(public SHARED foo.cxx)
target_link_libraries(public PRIVATE private)
install(TARGETS private public EXPORT dyld DESTINATION .)
export(PACKAGE_INFO dyld EXPORT dyld)
@@ -43,6 +43,7 @@ run_cmake(Minimal)
run_cmake(MinimalVersion)
run_cmake(LowerCaseFile)
run_cmake(Requirements)
run_cmake(LinkDependentLibraries)
run_cmake(ExportSymbolicComponent)
run_cmake(TargetTypes)
run_cmake(DependsMultiple)