diff options
Diffstat (limited to 'Source/cmComputeLinkInformation.cxx')
-rw-r--r-- | Source/cmComputeLinkInformation.cxx | 148 |
1 files changed, 75 insertions, 73 deletions
diff --git a/Source/cmComputeLinkInformation.cxx b/Source/cmComputeLinkInformation.cxx index 4c5f57d..201a9d9 100644 --- a/Source/cmComputeLinkInformation.cxx +++ b/Source/cmComputeLinkInformation.cxx @@ -4,7 +4,6 @@ #include <algorithm> #include <cctype> -#include <cstring> #include <sstream> #include <utility> @@ -284,27 +283,28 @@ cmComputeLinkInformation::cmComputeLinkInformation( this->Target->GetType() == cmStateEnums::MODULE_LIBRARY) { std::string loader_flag_var = cmStrCat("CMAKE_SHARED_MODULE_LOADER_", this->LinkLanguage, "_FLAG"); - this->LoaderFlag = this->Makefile->GetDefinition(loader_flag_var); + this->LoaderFlag = + cmToCStr(this->Makefile->GetDefinition(loader_flag_var)); } // Get options needed to link libraries. - if (const char* flag = this->Makefile->GetDefinition( + if (cmProp flag = this->Makefile->GetDefinition( "CMAKE_" + this->LinkLanguage + "_LINK_LIBRARY_FLAG")) { - this->LibLinkFlag = flag; + this->LibLinkFlag = *flag; } else { this->LibLinkFlag = this->Makefile->GetSafeDefinition("CMAKE_LINK_LIBRARY_FLAG"); } - if (const char* flag = this->Makefile->GetDefinition( + if (cmProp flag = this->Makefile->GetDefinition( "CMAKE_" + this->LinkLanguage + "_LINK_LIBRARY_FILE_FLAG")) { - this->LibLinkFileFlag = flag; + this->LibLinkFileFlag = *flag; } else { this->LibLinkFileFlag = this->Makefile->GetSafeDefinition("CMAKE_LINK_LIBRARY_FILE_FLAG"); } - if (const char* suffix = this->Makefile->GetDefinition( + if (cmProp suffix = this->Makefile->GetDefinition( "CMAKE_" + this->LinkLanguage + "_LINK_LIBRARY_SUFFIX")) { - this->LibLinkSuffix = suffix; + this->LibLinkSuffix = *suffix; } else { this->LibLinkSuffix = this->Makefile->GetSafeDefinition("CMAKE_LINK_LIBRARY_SUFFIX"); @@ -515,7 +515,7 @@ bool cmComputeLinkInformation::Compute() // Restore the target link type so the correct system runtime // libraries are found. cmProp lss = this->Target->GetProperty("LINK_SEARCH_END_STATIC"); - if (lss && cmIsOn(*lss)) { + if (cmIsOn(lss)) { this->SetCurrentLinkType(LinkStatic); } else { this->SetCurrentLinkType(this->StartLinkType); @@ -593,9 +593,9 @@ void cmComputeLinkInformation::AddRuntimeLinkLibrary(std::string const& lang) if (runtimeLibrary.empty()) { return; } - if (const char* runtimeLinkOptions = this->Makefile->GetDefinition( + if (cmProp runtimeLinkOptions = this->Makefile->GetDefinition( "CMAKE_" + lang + "_RUNTIME_LIBRARY_LINK_OPTIONS_" + runtimeLibrary)) { - std::vector<std::string> libsVec = cmExpandedList(runtimeLinkOptions); + std::vector<std::string> libsVec = cmExpandedList(*runtimeLinkOptions); for (std::string const& i : libsVec) { if (!cm::contains(this->ImplicitLinkLibs, i)) { this->AddItem(i, nullptr); @@ -609,8 +609,8 @@ void cmComputeLinkInformation::AddImplicitLinkInfo(std::string const& lang) // Add libraries for this language that are not implied by the // linker language. std::string libVar = cmStrCat("CMAKE_", lang, "_IMPLICIT_LINK_LIBRARIES"); - if (const char* libs = this->Makefile->GetDefinition(libVar)) { - std::vector<std::string> libsVec = cmExpandedList(libs); + if (cmProp libs = this->Makefile->GetDefinition(libVar)) { + std::vector<std::string> libsVec = cmExpandedList(*libs); for (std::string const& i : libsVec) { if (!cm::contains(this->ImplicitLinkLibs, i)) { this->AddItem(i, nullptr); @@ -621,8 +621,8 @@ void cmComputeLinkInformation::AddImplicitLinkInfo(std::string const& lang) // Add linker search paths for this language that are not // implied by the linker language. std::string dirVar = cmStrCat("CMAKE_", lang, "_IMPLICIT_LINK_DIRECTORIES"); - if (const char* dirs = this->Makefile->GetDefinition(dirVar)) { - std::vector<std::string> dirsVec = cmExpandedList(dirs); + if (cmProp dirs = this->Makefile->GetDefinition(dirVar)) { + std::vector<std::string> dirsVec = cmExpandedList(*dirs); this->OrderLinkerSearchPath->AddLanguageDirectories(dirsVec); } } @@ -800,8 +800,8 @@ void cmComputeLinkInformation::ComputeLinkTypeInfo() this->LinkTypeEnabled = false; // Lookup link type selection flags. - const char* static_link_type_flag = nullptr; - const char* shared_link_type_flag = nullptr; + cmProp static_link_type_flag = nullptr; + cmProp shared_link_type_flag = nullptr; const char* target_type_str = nullptr; switch (this->Target->GetType()) { case cmStateEnums::EXECUTABLE: @@ -832,16 +832,15 @@ void cmComputeLinkInformation::ComputeLinkTypeInfo() // We can support link type switching only if all needed flags are // known. - if (static_link_type_flag && *static_link_type_flag && - shared_link_type_flag && *shared_link_type_flag) { + if (cmNonempty(static_link_type_flag) && cmNonempty(shared_link_type_flag)) { this->LinkTypeEnabled = true; - this->StaticLinkTypeFlag = static_link_type_flag; - this->SharedLinkTypeFlag = shared_link_type_flag; + this->StaticLinkTypeFlag = *static_link_type_flag; + this->SharedLinkTypeFlag = *shared_link_type_flag; } // Lookup the starting link type from the target (linked statically?). cmProp lss = this->Target->GetProperty("LINK_SEARCH_START_STATIC"); - this->StartLinkType = (lss && cmIsOn(*lss)) ? LinkStatic : LinkShared; + this->StartLinkType = cmIsOn(lss) ? LinkStatic : LinkShared; this->CurrentLinkType = this->StartLinkType; } @@ -849,31 +848,30 @@ void cmComputeLinkInformation::ComputeItemParserInfo() { // Get possible library name prefixes. cmMakefile* mf = this->Makefile; - this->AddLinkPrefix(mf->GetDefinition("CMAKE_STATIC_LIBRARY_PREFIX")); - this->AddLinkPrefix(mf->GetDefinition("CMAKE_SHARED_LIBRARY_PREFIX")); + this->AddLinkPrefix(mf->GetSafeDefinition("CMAKE_STATIC_LIBRARY_PREFIX")); + this->AddLinkPrefix(mf->GetSafeDefinition("CMAKE_SHARED_LIBRARY_PREFIX")); // Import library names should be matched and treated as shared // libraries for the purposes of linking. - this->AddLinkExtension(mf->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"), + this->AddLinkExtension(mf->GetSafeDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"), LinkShared); - this->AddLinkExtension(mf->GetDefinition("CMAKE_STATIC_LIBRARY_SUFFIX"), + this->AddLinkExtension(mf->GetSafeDefinition("CMAKE_STATIC_LIBRARY_SUFFIX"), LinkStatic); - this->AddLinkExtension(mf->GetDefinition("CMAKE_SHARED_LIBRARY_SUFFIX"), + this->AddLinkExtension(mf->GetSafeDefinition("CMAKE_SHARED_LIBRARY_SUFFIX"), LinkShared); - this->AddLinkExtension(mf->GetDefinition("CMAKE_LINK_LIBRARY_SUFFIX"), + this->AddLinkExtension(mf->GetSafeDefinition("CMAKE_LINK_LIBRARY_SUFFIX"), LinkUnknown); - if (const char* linkSuffixes = - mf->GetDefinition("CMAKE_EXTRA_LINK_EXTENSIONS")) { - std::vector<std::string> linkSuffixVec = cmExpandedList(linkSuffixes); + if (cmProp linkSuffixes = mf->GetDefinition("CMAKE_EXTRA_LINK_EXTENSIONS")) { + std::vector<std::string> linkSuffixVec = cmExpandedList(*linkSuffixes); for (std::string const& i : linkSuffixVec) { - this->AddLinkExtension(i.c_str(), LinkUnknown); + this->AddLinkExtension(i, LinkUnknown); } } - if (const char* sharedSuffixes = + if (cmProp sharedSuffixes = mf->GetDefinition("CMAKE_EXTRA_SHARED_LIBRARY_SUFFIXES")) { - std::vector<std::string> sharedSuffixVec = cmExpandedList(sharedSuffixes); + std::vector<std::string> sharedSuffixVec = cmExpandedList(*sharedSuffixes); for (std::string const& i : sharedSuffixVec) { - this->AddLinkExtension(i.c_str(), LinkShared); + this->AddLinkExtension(i, LinkShared); } } @@ -903,7 +901,7 @@ void cmComputeLinkInformation::ComputeItemParserInfo() #ifdef CM_COMPUTE_LINK_INFO_DEBUG fprintf(stderr, "any regex [%s]\n", reg_any.c_str()); #endif - this->ExtractAnyLibraryName.compile(reg_any.c_str()); + this->ExtractAnyLibraryName.compile(reg_any); // Create a regex to match static library names. if (!this->StaticLinkExtensions.empty()) { @@ -912,7 +910,7 @@ void cmComputeLinkInformation::ComputeItemParserInfo() #ifdef CM_COMPUTE_LINK_INFO_DEBUG fprintf(stderr, "static regex [%s]\n", reg_static.c_str()); #endif - this->ExtractStaticLibraryName.compile(reg_static.c_str()); + this->ExtractStaticLibraryName.compile(reg_static); } // Create a regex to match shared library names. @@ -924,20 +922,21 @@ void cmComputeLinkInformation::ComputeItemParserInfo() #ifdef CM_COMPUTE_LINK_INFO_DEBUG fprintf(stderr, "shared regex [%s]\n", reg_shared.c_str()); #endif - this->ExtractSharedLibraryName.compile(reg_shared.c_str()); + this->ExtractSharedLibraryName.compile(reg_shared); } } -void cmComputeLinkInformation::AddLinkPrefix(const char* p) +void cmComputeLinkInformation::AddLinkPrefix(std::string const& p) { - if (p && *p) { + if (!p.empty()) { this->LinkPrefixes.insert(p); } } -void cmComputeLinkInformation::AddLinkExtension(const char* e, LinkType type) +void cmComputeLinkInformation::AddLinkExtension(std::string const& e, + LinkType type) { - if (e && *e) { + if (!e.empty()) { if (type == LinkStatic) { this->StaticLinkExtensions.emplace_back(e); } @@ -962,7 +961,7 @@ std::string cmComputeLinkInformation::CreateExtensionRegex( // Store this extension choice with the "." escaped. libext += "\\"; #if defined(_WIN32) && !defined(__CYGWIN__) - libext += this->NoCaseExpression(i.c_str()); + libext += this->NoCaseExpression(i); #else libext += i; #endif @@ -980,21 +979,19 @@ std::string cmComputeLinkInformation::CreateExtensionRegex( return libext; } -std::string cmComputeLinkInformation::NoCaseExpression(const char* str) +std::string cmComputeLinkInformation::NoCaseExpression(std::string const& str) { std::string ret; - ret.reserve(strlen(str) * 4); - const char* s = str; - while (*s) { - if (*s == '.') { - ret += *s; + ret.reserve(str.size() * 4); + for (char c : str) { + if (c == '.') { + ret += c; } else { ret += '['; - ret += static_cast<char>(tolower(*s)); - ret += static_cast<char>(toupper(*s)); + ret += static_cast<char>(tolower(c)); + ret += static_cast<char>(toupper(c)); ret += ']'; } - s++; } return ret; } @@ -1296,11 +1293,17 @@ void cmComputeLinkInformation::AddFrameworkItem(std::string const& item) // add runtime information this->AddLibraryRuntimeInfo(full_fw); - // Add the item using the -framework option. - this->Items.emplace_back(std::string("-framework"), false); - cmOutputConverter converter(this->Makefile->GetStateSnapshot()); - fw = converter.EscapeForShell(fw); - this->Items.emplace_back(fw, false); + if (this->GlobalGenerator->IsXcode()) { + // Add framework path - it will be handled by Xcode after it's added to + // "Link Binary With Libraries" build phase + this->Items.emplace_back(item, true); + } else { + // Add the item using the -framework option. + this->Items.emplace_back(std::string("-framework"), false); + cmOutputConverter converter(this->Makefile->GetStateSnapshot()); + fw = converter.EscapeForShell(fw); + this->Items.emplace_back(fw, false); + } } void cmComputeLinkInformation::AddDirectoryItem(std::string const& item) @@ -1555,10 +1558,10 @@ void cmComputeLinkInformation::LoadImplicitLinkInfo() // Append library architecture to all implicit platform directories // and add them to the set - if (const char* libraryArch = + if (cmProp libraryArch = this->Makefile->GetDefinition("CMAKE_LIBRARY_ARCHITECTURE")) { for (std::string const& i : implicitDirVec) { - this->ImplicitLinkDirs.insert(i + "/" + libraryArch); + this->ImplicitLinkDirs.insert(i + "/" + *libraryArch); } } @@ -1688,7 +1691,7 @@ void cmComputeLinkInformation::AddLibraryRuntimeInfo( } } -static void cmCLI_ExpandListUnique(const char* str, +static void cmCLI_ExpandListUnique(std::string const& str, std::vector<std::string>& out, std::set<std::string>& emitted) { @@ -1735,7 +1738,7 @@ void cmComputeLinkInformation::GetRPath(std::vector<std::string>& runtimeDirs, if (use_install_rpath) { std::string install_rpath; this->Target->GetInstallRPATH(this->Config, install_rpath); - cmCLI_ExpandListUnique(install_rpath.c_str(), runtimeDirs, emitted); + cmCLI_ExpandListUnique(install_rpath, runtimeDirs, emitted); } if (use_build_rpath) { // Add directories explicitly specified by user @@ -1743,19 +1746,18 @@ void cmComputeLinkInformation::GetRPath(std::vector<std::string>& runtimeDirs, 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.c_str(), runtimeDirs, emitted); + cmCLI_ExpandListUnique(build_rpath, runtimeDirs, emitted); } } if (use_build_rpath || use_link_rpath) { std::string rootPath; - if (const char* sysrootLink = + if (cmProp sysrootLink = this->Makefile->GetDefinition("CMAKE_SYSROOT_LINK")) { - rootPath = sysrootLink; + rootPath = *sysrootLink; } else { rootPath = this->Makefile->GetSafeDefinition("CMAKE_SYSROOT"); } - const char* stagePath = - this->Makefile->GetDefinition("CMAKE_STAGING_PREFIX"); + cmProp stagePath = this->Makefile->GetDefinition("CMAKE_STAGING_PREFIX"); std::string const& installPrefix = this->Makefile->GetSafeDefinition("CMAKE_INSTALL_PREFIX"); cmSystemTools::ConvertToUnixSlashes(rootPath); @@ -1769,8 +1771,8 @@ void cmComputeLinkInformation::GetRPath(std::vector<std::string>& runtimeDirs, std::string d = ri; if (!rootPath.empty() && cmHasPrefix(d, rootPath)) { d.erase(0, rootPath.size()); - } else if (stagePath && *stagePath && cmHasPrefix(d, stagePath)) { - d.erase(0, strlen(stagePath)); + } else if (cmNonempty(stagePath) && cmHasPrefix(d, *stagePath)) { + d.erase(0, (*stagePath).size()); d = cmStrCat(installPrefix, '/', d); cmSystemTools::ConvertToUnixSlashes(d); } else if (use_relative_build_rpath) { @@ -1800,8 +1802,8 @@ void cmComputeLinkInformation::GetRPath(std::vector<std::string>& runtimeDirs, std::string d = ri; if (!rootPath.empty() && cmHasPrefix(d, rootPath)) { d.erase(0, rootPath.size()); - } else if (stagePath && *stagePath && cmHasPrefix(d, stagePath)) { - d.erase(0, strlen(stagePath)); + } else if (cmNonempty(stagePath) && cmHasPrefix(d, *stagePath)) { + d.erase(0, (*stagePath).size()); d = cmStrCat(installPrefix, '/', d); cmSystemTools::ConvertToUnixSlashes(d); } @@ -1823,8 +1825,8 @@ void cmComputeLinkInformation::GetRPath(std::vector<std::string>& runtimeDirs, "CMAKE_" + li + "_USE_IMPLICIT_LINK_DIRECTORIES_IN_RUNTIME_PATH"; if (this->Makefile->IsOn(useVar)) { std::string dirVar = "CMAKE_" + li + "_IMPLICIT_LINK_DIRECTORIES"; - if (const char* dirs = this->Makefile->GetDefinition(dirVar)) { - cmCLI_ExpandListUnique(dirs, runtimeDirs, emitted); + if (cmProp dirs = this->Makefile->GetDefinition(dirVar)) { + cmCLI_ExpandListUnique(*dirs, runtimeDirs, emitted); } } } @@ -1832,7 +1834,7 @@ void cmComputeLinkInformation::GetRPath(std::vector<std::string>& runtimeDirs, // Add runtime paths required by the platform to always be // present. This is done even when skipping rpath support. - cmCLI_ExpandListUnique(this->RuntimeAlways.c_str(), runtimeDirs, emitted); + cmCLI_ExpandListUnique(this->RuntimeAlways, runtimeDirs, emitted); } std::string cmComputeLinkInformation::GetRPathString(bool for_install) const |