diff options
Diffstat (limited to 'Source/cmTargetLinkLibrariesCommand.cxx')
-rw-r--r-- | Source/cmTargetLinkLibrariesCommand.cxx | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/Source/cmTargetLinkLibrariesCommand.cxx b/Source/cmTargetLinkLibrariesCommand.cxx index 0d2383a..1d9ecc2 100644 --- a/Source/cmTargetLinkLibrariesCommand.cxx +++ b/Source/cmTargetLinkLibrariesCommand.cxx @@ -3,6 +3,7 @@ #include "cmTargetLinkLibrariesCommand.h" #include <cstring> +#include <memory> #include <sstream> #include "cmExecutionStatus.h" @@ -64,11 +65,9 @@ bool cmTargetLinkLibrariesCommand(std::vector<std::string> const& args, cmTarget* target = mf.GetCMakeInstance()->GetGlobalGenerator()->FindTarget(args[0]); if (!target) { - const std::vector<cmTarget*>& importedTargets = - mf.GetOwnedImportedTargets(); - for (cmTarget* importedTarget : importedTargets) { + for (const auto& importedTarget : mf.GetOwnedImportedTargets()) { if (importedTarget->GetName() == args[0]) { - target = importedTarget; + target = importedTarget.get(); break; } } @@ -406,6 +405,10 @@ static bool HandleLibrary(cmMakefile& mf, cmTarget* target, // the name to tell ResolveLinkItem to look up the name in the // caller's directory. cmDirectoryId const dirId = mf.GetDirectoryId(); + // FIXME: The "lib" may be a genex with a list inside it. + // After expansion this id will only attach to the last entry, + // or may attach to an empty string! We will need another way + // to encode this that can apply to a whole list. See issue #20204. libRef = lib + CMAKE_DIRECTORY_ID_SEP + dirId.String; } else { // This is an absolute path or a library name added by a caller @@ -480,7 +483,7 @@ static bool HandleLibrary(cmMakefile& mf, cmTarget* target, cmGeneratorExpression::Find(lib) != std::string::npos) { configLib = "$<LINK_ONLY:" + configLib + ">"; } - target->AppendProperty("INTERFACE_LINK_LIBRARIES", configLib.c_str()); + target->AppendProperty("INTERFACE_LINK_LIBRARIES", configLib); } return true; } @@ -488,9 +491,8 @@ static bool HandleLibrary(cmMakefile& mf, cmTarget* target, // Handle general case where the command was called with another keyword than // PRIVATE / LINK_PRIVATE or none at all. (The "INTERFACE_LINK_LIBRARIES" // property of the target on the LHS shall be populated.) - target->AppendProperty( - "INTERFACE_LINK_LIBRARIES", - target->GetDebugGeneratorExpressions(libRef, llt).c_str()); + target->AppendProperty("INTERFACE_LINK_LIBRARIES", + target->GetDebugGeneratorExpressions(libRef, llt)); // Stop processing if called without any keyword. if (currentProcessingState == ProcessingLinkLibraries) { @@ -522,12 +524,12 @@ static bool HandleLibrary(cmMakefile& mf, cmTarget* target, // Put in the DEBUG configuration interfaces. for (std::string const& dc : debugConfigs) { prop = cmStrCat("LINK_INTERFACE_LIBRARIES_", dc); - target->AppendProperty(prop, libRef.c_str()); + target->AppendProperty(prop, libRef); } } if (llt == OPTIMIZED_LibraryType || llt == GENERAL_LibraryType) { // Put in the non-DEBUG configuration interfaces. - target->AppendProperty("LINK_INTERFACE_LIBRARIES", libRef.c_str()); + target->AppendProperty("LINK_INTERFACE_LIBRARIES", libRef); // Make sure the DEBUG configuration interfaces exist so that the // general one will not be used as a fall-back. |