1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-14 02:08:27 +08:00

export: Do not fail generation for separate namelink only case

Update the change from commit 64690f6df0 (export: Do not fail generation
for namelink-only case, 2020-10-09, v3.19.0-rc1~7^2) to also handle
separate namelink-only and namelink-skip calls.

Fixes: #21529
This commit is contained in:
Deniz Bahadir
2020-12-01 00:25:39 +01:00
committed by Brad King
parent 5ef2364053
commit 38bcb5c0a3
8 changed files with 56 additions and 8 deletions

View File

@@ -288,6 +288,9 @@ void cmExportBuildFileGenerator::GetTargets(
if (this->ExportSet) { if (this->ExportSet) {
for (std::unique_ptr<cmTargetExport> const& te : for (std::unique_ptr<cmTargetExport> const& te :
this->ExportSet->GetTargetExports()) { this->ExportSet->GetTargetExports()) {
if (te->NamelinkOnly) {
continue;
}
targets.push_back(te->TargetName); targets.push_back(te->TargetName);
} }
return; return;

View File

@@ -42,6 +42,9 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os)
std::string sep; std::string sep;
for (std::unique_ptr<cmTargetExport> const& te : for (std::unique_ptr<cmTargetExport> const& te :
this->IEGen->GetExportSet()->GetTargetExports()) { this->IEGen->GetExportSet()->GetTargetExports()) {
if (te->NamelinkOnly) {
continue;
}
expectedTargets += sep + this->Namespace + te->Target->GetExportName(); expectedTargets += sep + this->Namespace + te->Target->GetExportName();
sep = " "; sep = " ";
if (this->ExportedTargets.insert(te->Target).second) { if (this->ExportedTargets.insert(te->Target).second) {

View File

@@ -461,6 +461,13 @@ bool HandleTargetsMode(std::vector<std::string> const& args,
std::unique_ptr<cmInstallFilesGenerator> publicHeaderGenerator; std::unique_ptr<cmInstallFilesGenerator> publicHeaderGenerator;
std::unique_ptr<cmInstallFilesGenerator> resourceGenerator; std::unique_ptr<cmInstallFilesGenerator> resourceGenerator;
// Avoid selecting default destinations for PUBLIC_HEADER and
// PRIVATE_HEADER if any artifacts are specified.
bool artifactsSpecified = false;
// Track whether this is a namelink-only rule.
bool namelinkOnly = false;
auto addTargetExport = [&]() { auto addTargetExport = [&]() {
// Add this install rule to an export if one was specified. // Add this install rule to an export if one was specified.
if (!exports.empty()) { if (!exports.empty()) {
@@ -475,20 +482,13 @@ bool HandleTargetsMode(std::vector<std::string> const& args,
te->ObjectsGenerator = objectGenerator.get(); te->ObjectsGenerator = objectGenerator.get();
te->InterfaceIncludeDirectories = te->InterfaceIncludeDirectories =
cmJoin(includesArgs.GetIncludeDirs(), ";"); cmJoin(includesArgs.GetIncludeDirs(), ";");
te->NamelinkOnly = namelinkOnly;
helper.Makefile->GetGlobalGenerator() helper.Makefile->GetGlobalGenerator()
->GetExportSets()[exports] ->GetExportSets()[exports]
.AddTargetExport(std::move(te)); .AddTargetExport(std::move(te));
} }
}; };
// Avoid selecting default destinations for PUBLIC_HEADER and
// PRIVATE_HEADER if any artifacts are specified.
bool artifactsSpecified = false;
// Track whether this is a namelink-only rule.
bool namelinkOnly = false;
switch (target.GetType()) { switch (target.GetType()) {
case cmStateEnums::SHARED_LIBRARY: { case cmStateEnums::SHARED_LIBRARY: {
// Shared libraries are handled differently on DLL and non-DLL // Shared libraries are handled differently on DLL and non-DLL
@@ -497,6 +497,7 @@ bool HandleTargetsMode(std::vector<std::string> const& args,
if (target.IsDLLPlatform()) { if (target.IsDLLPlatform()) {
// When in namelink only mode skip all libraries on Windows. // When in namelink only mode skip all libraries on Windows.
if (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly) { if (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly) {
namelinkOnly = true;
addTargetExport(); addTargetExport();
continue; continue;
} }
@@ -529,6 +530,7 @@ bool HandleTargetsMode(std::vector<std::string> const& args,
if (target.IsFrameworkOnApple()) { if (target.IsFrameworkOnApple()) {
// When in namelink only mode skip frameworks. // When in namelink only mode skip frameworks.
if (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly) { if (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly) {
namelinkOnly = true;
addTargetExport(); addTargetExport();
continue; continue;
} }
@@ -574,6 +576,7 @@ bool HandleTargetsMode(std::vector<std::string> const& args,
if (target.IsFrameworkOnApple()) { if (target.IsFrameworkOnApple()) {
// When in namelink only mode skip frameworks. // When in namelink only mode skip frameworks.
if (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly) { if (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly) {
namelinkOnly = true;
addTargetExport(); addTargetExport();
continue; continue;
} }

View File

@@ -31,4 +31,6 @@ public:
cmInstallFilesGenerator* HeaderGenerator; cmInstallFilesGenerator* HeaderGenerator;
std::string InterfaceIncludeDirectories; std::string InterfaceIncludeDirectories;
///@} ///@}
bool NamelinkOnly = false;
}; };

View File

@@ -17,3 +17,4 @@ run_cmake(DependOnNotExport)
run_cmake(DependOnDoubleExport) run_cmake(DependOnDoubleExport)
run_cmake(UnknownExport) run_cmake(UnknownExport)
run_cmake(NamelinkOnlyExport) run_cmake(NamelinkOnlyExport)
run_cmake(SeparateNamelinkExport)

View File

@@ -0,0 +1,16 @@
enable_language(CXX)
add_library(foo SHARED empty.cpp)
install(TARGETS foo EXPORT fooExport
RUNTIME DESTINATION bin
LIBRARY
DESTINATION lib
COMPONENT runtime
NAMELINK_SKIP
)
install(TARGETS foo EXPORT fooExport
LIBRARY
DESTINATION lib
COMPONENT development
NAMELINK_ONLY
)
export(EXPORT fooExport FILE "${CMAKE_CURRENT_BINARY_DIR}/foo.cmake")

View File

@@ -0,0 +1,19 @@
enable_language(C)
add_library(foo SHARED empty.c)
install(TARGETS foo EXPORT fooExport
RUNTIME DESTINATION bin
LIBRARY
DESTINATION lib
COMPONENT runtime
NAMELINK_SKIP
)
install(TARGETS foo EXPORT fooExport
LIBRARY
DESTINATION lib
COMPONENT development
NAMELINK_ONLY
)
install(EXPORT fooExport
DESTINATION "lib/cmake/"
FILE "foo.cmake"
)

View File

@@ -78,6 +78,7 @@ run_cmake(TARGETS-DESTINATION-bad)
run_cmake(EXPORT-OldIFace) run_cmake(EXPORT-OldIFace)
run_cmake(EXPORT-UnknownExport) run_cmake(EXPORT-UnknownExport)
run_cmake(EXPORT-NamelinkOnly) run_cmake(EXPORT-NamelinkOnly)
run_cmake(EXPORT-SeparateNamelink)
run_cmake(CMP0062-OLD) run_cmake(CMP0062-OLD)
run_cmake(CMP0062-NEW) run_cmake(CMP0062-NEW)
run_cmake(CMP0062-WARN) run_cmake(CMP0062-WARN)