From 058b8a0bfb722b3a75ca051c0e1f7b1261643815 Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Thu, 17 Feb 2022 14:43:06 -0500 Subject: install(): Properly ignore FILE_SETs that don't exist Fixes: #22960 --- Source/cmInstallCommand.cxx | 43 +++++++++++----------- .../target_sources/FileSetNoExistInstall.cmake | 4 ++ Tests/RunCMake/target_sources/RunCMakeTest.cmake | 1 + 3 files changed, 27 insertions(+), 21 deletions(-) create mode 100644 Tests/RunCMake/target_sources/FileSetNoExistInstall.cmake diff --git a/Source/cmInstallCommand.cxx b/Source/cmInstallCommand.cxx index a77b26b..8ce7ed1 100644 --- a/Source/cmInstallCommand.cxx +++ b/Source/cmInstallCommand.cxx @@ -1077,29 +1077,30 @@ bool HandleTargetsMode(std::vector const& args, if (!namelinkOnly) { for (std::size_t i = 0; i < fileSetArgs.size(); i++) { - auto* fileSet = target.GetFileSet(fileSetArgs[i].GetFileSet()); - auto interfaceFileSetEntries = cmExpandedList(target.GetSafeProperty( - cmTarget::GetInterfaceFileSetsPropertyName(fileSet->GetType()))); - if (fileSet && - std::find( - interfaceFileSetEntries.begin(), interfaceFileSetEntries.end(), - fileSetArgs[i].GetFileSet()) != interfaceFileSetEntries.end()) { - std::string destination; - if (fileSet->GetType() == "HEADERS"_s) { - destination = helper.GetIncludeDestination(&fileSetArgs[i]); - } else { - destination = fileSetArgs[i].GetDestination(); - if (destination.empty()) { - status.SetError( - cmStrCat("TARGETS given no FILE_SET DESTINATION for target \"", - target.GetName(), "\" file set \"", - fileSet->GetName(), "\".")); - return false; + if (auto* fileSet = target.GetFileSet(fileSetArgs[i].GetFileSet())) { + auto interfaceFileSetEntries = cmExpandedList(target.GetSafeProperty( + cmTarget::GetInterfaceFileSetsPropertyName(fileSet->GetType()))); + if (std::find(interfaceFileSetEntries.begin(), + interfaceFileSetEntries.end(), + fileSetArgs[i].GetFileSet()) != + interfaceFileSetEntries.end()) { + std::string destination; + if (fileSet->GetType() == "HEADERS"_s) { + destination = helper.GetIncludeDestination(&fileSetArgs[i]); + } else { + destination = fileSetArgs[i].GetDestination(); + if (destination.empty()) { + status.SetError(cmStrCat( + "TARGETS given no FILE_SET DESTINATION for target \"", + target.GetName(), "\" file set \"", fileSet->GetName(), + "\".")); + return false; + } } + fileSetGenerators.push_back(CreateInstallFileSetGenerator( + helper, target, fileSet, destination, fileSetArgs[i])); + installsFileSet[i] = true; } - fileSetGenerators.push_back(CreateInstallFileSetGenerator( - helper, target, fileSet, destination, fileSetArgs[i])); - installsFileSet[i] = true; } } } diff --git a/Tests/RunCMake/target_sources/FileSetNoExistInstall.cmake b/Tests/RunCMake/target_sources/FileSetNoExistInstall.cmake new file mode 100644 index 0000000..a8b4b94 --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetNoExistInstall.cmake @@ -0,0 +1,4 @@ +enable_language(C) + +add_library(lib1 STATIC empty.c) +install(TARGETS lib1 FILE_SET a) diff --git a/Tests/RunCMake/target_sources/RunCMakeTest.cmake b/Tests/RunCMake/target_sources/RunCMakeTest.cmake index 9828fa2..171de60 100644 --- a/Tests/RunCMake/target_sources/RunCMakeTest.cmake +++ b/Tests/RunCMake/target_sources/RunCMakeTest.cmake @@ -36,6 +36,7 @@ run_cmake(FileSetInstallMissingSetsInterface) run_cmake(FileSetNoScope) run_cmake(FileSetNoExistPrivate) run_cmake(FileSetNoExistInterface) +run_cmake(FileSetNoExistInstall) run_cmake(FileSetDirectories) set(RunCMake_TEST_OPTIONS -DCMAKE_POLICY_DEFAULT_CMP0115=NEW) -- cgit v0.12