diff options
Diffstat (limited to 'Source/cmComputeLinkInformation.cxx')
-rw-r--r-- | Source/cmComputeLinkInformation.cxx | 91 |
1 files changed, 44 insertions, 47 deletions
diff --git a/Source/cmComputeLinkInformation.cxx b/Source/cmComputeLinkInformation.cxx index 44d8615..4273383 100644 --- a/Source/cmComputeLinkInformation.cxx +++ b/Source/cmComputeLinkInformation.cxx @@ -2,7 +2,6 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmComputeLinkInformation.h" -#include "cmAlgorithms.h" #include "cmComputeLinkDepends.h" #include "cmGeneratorTarget.h" #include "cmGlobalGenerator.h" @@ -14,6 +13,7 @@ #include "cmPolicies.h" #include "cmState.h" #include "cmStateTypes.h" +#include "cmStringAlgorithms.h" #include "cmSystemTools.h" #include "cmTarget.h" #include "cmake.h" @@ -268,10 +268,6 @@ cmComputeLinkInformation::cmComputeLinkInformation( return; } - // Check whether we should use an import library for linking a target. - this->UseImportLibrary = - this->Makefile->IsDefinitionSet("CMAKE_IMPORT_LIBRARY_SUFFIX"); - // Check whether we should skip dependencies on shared library files. this->LinkDependsNoShared = this->Target->GetPropertyAsBool("LINK_DEPENDS_NO_SHARED"); @@ -280,7 +276,7 @@ cmComputeLinkInformation::cmComputeLinkInformation( // to use when creating a plugin (module) that obtains symbols from // the program that will load it. this->LoaderFlag = nullptr; - if (!this->UseImportLibrary && + if (!this->Target->IsDLLPlatform() && this->Target->GetType() == cmStateEnums::MODULE_LIBRARY) { std::string loader_flag_var = "CMAKE_SHARED_MODULE_LOADER_"; loader_flag_var += this->LinkLanguage; @@ -289,8 +285,13 @@ cmComputeLinkInformation::cmComputeLinkInformation( } // Get options needed to link libraries. - this->LibLinkFlag = - this->Makefile->GetSafeDefinition("CMAKE_LINK_LIBRARY_FLAG"); + if (const char* flag = this->Makefile->GetDefinition( + "CMAKE_" + this->LinkLanguage + "_LINK_LIBRARY_FLAG")) { + this->LibLinkFlag = flag; + } else { + this->LibLinkFlag = + this->Makefile->GetSafeDefinition("CMAKE_LINK_LIBRARY_FLAG"); + } this->LibLinkFileFlag = this->Makefile->GetSafeDefinition("CMAKE_LINK_LIBRARY_FILE_FLAG"); this->LibLinkSuffix = @@ -479,7 +480,7 @@ bool cmComputeLinkInformation::Compute() // Restore the target link type so the correct system runtime // libraries are found. const char* lss = this->Target->GetProperty("LINK_SEARCH_END_STATIC"); - if (cmSystemTools::IsOn(lss)) { + if (cmIsOn(lss)) { this->SetCurrentLinkType(LinkStatic); } else { this->SetCurrentLinkType(this->StartLinkType); @@ -493,9 +494,7 @@ bool cmComputeLinkInformation::Compute() std::set<cmGeneratorTarget const*> const& wrongItems = cld.GetOldWrongConfigItems(); for (cmGeneratorTarget const* tgt : wrongItems) { - bool implib = (this->UseImportLibrary && - (tgt->GetType() == cmStateEnums::SHARED_LIBRARY)); - cmStateEnums::ArtifactType artifact = implib + cmStateEnums::ArtifactType artifact = tgt->HasImportLibrary(this->Config) ? cmStateEnums::ImportLibraryArtifact : cmStateEnums::RuntimeBinaryArtifact; this->OldLinkDirItems.push_back( @@ -552,7 +551,7 @@ void cmComputeLinkInformation::AddImplicitLinkInfo(std::string const& lang) libVar += "_IMPLICIT_LINK_LIBRARIES"; if (const char* libs = this->Makefile->GetDefinition(libVar)) { std::vector<std::string> libsVec; - cmSystemTools::ExpandListArgument(libs, libsVec); + cmExpandList(libs, libsVec); for (std::string const& i : libsVec) { if (this->ImplicitLinkLibs.find(i) == this->ImplicitLinkLibs.end()) { this->AddItem(i, nullptr); @@ -567,7 +566,7 @@ void cmComputeLinkInformation::AddImplicitLinkInfo(std::string const& lang) dirVar += "_IMPLICIT_LINK_DIRECTORIES"; if (const char* dirs = this->Makefile->GetDefinition(dirVar)) { std::vector<std::string> dirsVec; - cmSystemTools::ExpandListArgument(dirs, dirsVec); + cmExpandList(dirs, dirsVec); this->OrderLinkerSearchPath->AddLanguageDirectories(dirsVec); } } @@ -578,7 +577,7 @@ void cmComputeLinkInformation::AddItem(std::string const& item, // Compute the proper name to use to link this library. const std::string& config = this->Config; bool impexe = (tgt && tgt->IsExecutableWithExports()); - if (impexe && !this->UseImportLibrary && !this->LoaderFlag) { + if (impexe && !tgt->HasImportLibrary(config) && !this->LoaderFlag) { // Skip linking to executables on platforms with no import // libraries or loader flags. return; @@ -592,7 +591,7 @@ void cmComputeLinkInformation::AddItem(std::string const& item, // platform. Add it now. std::string linkItem; linkItem = this->LoaderFlag; - cmStateEnums::ArtifactType artifact = this->UseImportLibrary + cmStateEnums::ArtifactType artifact = tgt->HasImportLibrary(config) ? cmStateEnums::ImportLibraryArtifact : cmStateEnums::RuntimeBinaryArtifact; @@ -616,15 +615,21 @@ void cmComputeLinkInformation::AddItem(std::string const& item, // Its object-files should already have been extracted for linking. } else { // Decide whether to use an import library. - bool implib = - (this->UseImportLibrary && - (impexe || tgt->GetType() == cmStateEnums::SHARED_LIBRARY)); - cmStateEnums::ArtifactType artifact = implib + cmStateEnums::ArtifactType artifact = tgt->HasImportLibrary(config) ? cmStateEnums::ImportLibraryArtifact : cmStateEnums::RuntimeBinaryArtifact; // Pass the full path to the target file. std::string lib = tgt->GetFullPath(config, artifact, true); + if (tgt->Target->IsAIX() && cmHasLiteralSuffix(lib, "-NOTFOUND") && + artifact == cmStateEnums::ImportLibraryArtifact) { + // This is an imported executable on AIX that has ENABLE_EXPORTS + // but not IMPORTED_IMPLIB. CMake used to produce and accept such + // imported executables on AIX before we taught it to use linker + // import files. For compatibility, simply skip linking to this + // executable as we did before. It works with runtime linking. + return; + } if (!this->LinkDependsNoShared || tgt->GetType() != cmStateEnums::SHARED_LIBRARY) { this->Depends.push_back(lib); @@ -694,7 +699,7 @@ void cmComputeLinkInformation::AddSharedDepItem(std::string const& item, // linked will be able to find it. std::string lib; if (tgt) { - cmStateEnums::ArtifactType artifact = this->UseImportLibrary + cmStateEnums::ArtifactType artifact = tgt->HasImportLibrary(this->Config) ? cmStateEnums::ImportLibraryArtifact : cmStateEnums::RuntimeBinaryArtifact; lib = tgt->GetFullPath(this->Config, artifact); @@ -782,7 +787,7 @@ void cmComputeLinkInformation::ComputeLinkTypeInfo() // Lookup the starting link type from the target (linked statically?). const char* lss = this->Target->GetProperty("LINK_SEARCH_START_STATIC"); - this->StartLinkType = cmSystemTools::IsOn(lss) ? LinkStatic : LinkShared; + this->StartLinkType = cmIsOn(lss) ? LinkStatic : LinkShared; this->CurrentLinkType = this->StartLinkType; } @@ -806,7 +811,7 @@ void cmComputeLinkInformation::ComputeItemParserInfo() if (const char* linkSuffixes = mf->GetDefinition("CMAKE_EXTRA_LINK_EXTENSIONS")) { std::vector<std::string> linkSuffixVec; - cmSystemTools::ExpandListArgument(linkSuffixes, linkSuffixVec); + cmExpandList(linkSuffixes, linkSuffixVec); for (std::string const& i : linkSuffixVec) { this->AddLinkExtension(i.c_str(), LinkUnknown); } @@ -814,7 +819,7 @@ void cmComputeLinkInformation::ComputeItemParserInfo() if (const char* sharedSuffixes = mf->GetDefinition("CMAKE_EXTRA_SHARED_LIBRARY_SUFFIXES")) { std::vector<std::string> sharedSuffixVec; - cmSystemTools::ExpandListArgument(sharedSuffixes, sharedSuffixVec); + cmExpandList(sharedSuffixes, sharedSuffixVec); for (std::string const& i : sharedSuffixVec) { this->AddLinkExtension(i.c_str(), LinkShared); } @@ -990,11 +995,6 @@ void cmComputeLinkInformation::AddTargetItem(std::string const& item, return; } - // If this platform wants a flag before the full path, add it. - if (!this->LibLinkFileFlag.empty()) { - this->Items.emplace_back(this->LibLinkFileFlag, false); - } - // For compatibility with CMake 2.4 include the item's directory in // the linker search path. if (this->OldLinkDirMode && !target->IsFrameworkOnApple() && @@ -1057,11 +1057,6 @@ void cmComputeLinkInformation::AddFullItem(std::string const& item) this->OldLinkDirItems.push_back(item); } - // If this platform wants a flag before the full path, add it. - if (!this->LibLinkFileFlag.empty()) { - this->Items.emplace_back(this->LibLinkFileFlag, false); - } - // Now add the full path to the library. this->Items.emplace_back(item, true); } @@ -1293,7 +1288,7 @@ void cmComputeLinkInformation::ComputeFrameworkInfo() // Get platform-wide implicit directories. if (const char* implicitLinks = this->Makefile->GetDefinition( "CMAKE_PLATFORM_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES")) { - cmSystemTools::ExpandListArgument(implicitLinks, implicitDirVec); + cmExpandList(implicitLinks, implicitDirVec); } // Get language-specific implicit directories. @@ -1302,7 +1297,7 @@ void cmComputeLinkInformation::ComputeFrameworkInfo() implicitDirVar += "_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES"; if (const char* implicitDirs = this->Makefile->GetDefinition(implicitDirVar)) { - cmSystemTools::ExpandListArgument(implicitDirs, implicitDirVec); + cmExpandList(implicitDirs, implicitDirVec); } this->FrameworkPathsEmmitted.insert(implicitDirVec.begin(), @@ -1521,7 +1516,7 @@ void cmComputeLinkInformation::LoadImplicitLinkInfo() // Get platform-wide implicit directories. if (const char* implicitLinks = (this->Makefile->GetDefinition( "CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES"))) { - cmSystemTools::ExpandListArgument(implicitLinks, implicitDirVec); + cmExpandList(implicitLinks, implicitDirVec); } // Append library architecture to all implicit platform directories @@ -1539,7 +1534,7 @@ void cmComputeLinkInformation::LoadImplicitLinkInfo() implicitDirVar += "_IMPLICIT_LINK_DIRECTORIES"; if (const char* implicitDirs = this->Makefile->GetDefinition(implicitDirVar)) { - cmSystemTools::ExpandListArgument(implicitDirs, implicitDirVec); + cmExpandList(implicitDirs, implicitDirVec); } // Store implicit link directories. @@ -1552,7 +1547,7 @@ void cmComputeLinkInformation::LoadImplicitLinkInfo() implicitLibVar += "_IMPLICIT_LINK_LIBRARIES"; if (const char* implicitLibs = this->Makefile->GetDefinition(implicitLibVar)) { - cmSystemTools::ExpandListArgument(implicitLibs, implicitLibVec); + cmExpandList(implicitLibs, implicitLibVec); } // Store implicit link libraries. @@ -1567,7 +1562,7 @@ void cmComputeLinkInformation::LoadImplicitLinkInfo() // Get platform specific rpath link directories if (const char* rpathDirs = (this->Makefile->GetDefinition("CMAKE_PLATFORM_RUNTIME_PATH"))) { - cmSystemTools::ExpandListArgument(rpathDirs, this->RuntimeLinkDirs); + cmExpandList(rpathDirs, this->RuntimeLinkDirs); } } @@ -1674,7 +1669,7 @@ static void cmCLI_ExpandListUnique(const char* str, std::set<std::string>& emitted) { std::vector<std::string> tmp; - cmSystemTools::ExpandListArgument(str, tmp); + cmExpandList(str, tmp); for (std::string const& i : tmp) { if (emitted.insert(i).second) { out.push_back(i); @@ -1695,7 +1690,7 @@ void cmComputeLinkInformation::GetRPath(std::vector<std::string>& runtimeDirs, (for_install || this->Target->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH")); bool use_install_rpath = - (outputRuntime && this->Target->HaveInstallTreeRPATH() && + (outputRuntime && this->Target->HaveInstallTreeRPATH(this->Config) && linking_for_install); bool use_build_rpath = (outputRuntime && this->Target->HaveBuildTreeRPATH(this->Config) && @@ -1715,15 +1710,17 @@ void cmComputeLinkInformation::GetRPath(std::vector<std::string>& runtimeDirs, // Construct the RPATH. std::set<std::string> emitted; if (use_install_rpath) { - const char* install_rpath = this->Target->GetProperty("INSTALL_RPATH"); - cmCLI_ExpandListUnique(install_rpath, runtimeDirs, emitted); + std::string install_rpath; + this->Target->GetInstallRPATH(this->Config, install_rpath); + cmCLI_ExpandListUnique(install_rpath.c_str(), runtimeDirs, emitted); } if (use_build_rpath) { // Add directories explicitly specified by user - if (const char* build_rpath = this->Target->GetProperty("BUILD_RPATH")) { + std::string build_rpath; + if (this->Target->GetBuildRPATH(this->Config, build_rpath)) { // This will not resolve entries to use $ORIGIN, the user is expected to // do that if necessary. - cmCLI_ExpandListUnique(build_rpath, runtimeDirs, emitted); + cmCLI_ExpandListUnique(build_rpath.c_str(), runtimeDirs, emitted); } } if (use_build_rpath || use_link_rpath) { @@ -1762,7 +1759,7 @@ void cmComputeLinkInformation::GetRPath(std::vector<std::string>& runtimeDirs, cmSystemTools::IsSubDirectory(d, topBinaryDir)) { d = cmSystemTools::RelativePath(targetOutputDir, d); if (!d.empty()) { - d = originToken + "/" + d; + d = cmStrCat(originToken, "/", d); } else { d = originToken; } |