Skip to content

Commit 9b236b5

Browse files
author
Vitaly Stakhovsky
committed
cmComputeLinkInformation: members use std:string arguments
1 parent 95db8c5 commit 9b236b5

File tree

2 files changed

+33
-34
lines changed

2 files changed

+33
-34
lines changed

Source/cmComputeLinkInformation.cxx

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -849,31 +849,31 @@ void cmComputeLinkInformation::ComputeItemParserInfo()
849849
{
850850
// Get possible library name prefixes.
851851
cmMakefile* mf = this->Makefile;
852-
this->AddLinkPrefix(mf->GetDefinition("CMAKE_STATIC_LIBRARY_PREFIX"));
853-
this->AddLinkPrefix(mf->GetDefinition("CMAKE_SHARED_LIBRARY_PREFIX"));
852+
this->AddLinkPrefix(mf->GetSafeDefinition("CMAKE_STATIC_LIBRARY_PREFIX"));
853+
this->AddLinkPrefix(mf->GetSafeDefinition("CMAKE_SHARED_LIBRARY_PREFIX"));
854854

855855
// Import library names should be matched and treated as shared
856856
// libraries for the purposes of linking.
857-
this->AddLinkExtension(mf->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"),
857+
this->AddLinkExtension(mf->GetSafeDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"),
858858
LinkShared);
859-
this->AddLinkExtension(mf->GetDefinition("CMAKE_STATIC_LIBRARY_SUFFIX"),
859+
this->AddLinkExtension(mf->GetSafeDefinition("CMAKE_STATIC_LIBRARY_SUFFIX"),
860860
LinkStatic);
861-
this->AddLinkExtension(mf->GetDefinition("CMAKE_SHARED_LIBRARY_SUFFIX"),
861+
this->AddLinkExtension(mf->GetSafeDefinition("CMAKE_SHARED_LIBRARY_SUFFIX"),
862862
LinkShared);
863-
this->AddLinkExtension(mf->GetDefinition("CMAKE_LINK_LIBRARY_SUFFIX"),
863+
this->AddLinkExtension(mf->GetSafeDefinition("CMAKE_LINK_LIBRARY_SUFFIX"),
864864
LinkUnknown);
865865
if (const char* linkSuffixes =
866866
mf->GetDefinition("CMAKE_EXTRA_LINK_EXTENSIONS")) {
867867
std::vector<std::string> linkSuffixVec = cmExpandedList(linkSuffixes);
868868
for (std::string const& i : linkSuffixVec) {
869-
this->AddLinkExtension(i.c_str(), LinkUnknown);
869+
this->AddLinkExtension(i, LinkUnknown);
870870
}
871871
}
872872
if (const char* sharedSuffixes =
873873
mf->GetDefinition("CMAKE_EXTRA_SHARED_LIBRARY_SUFFIXES")) {
874874
std::vector<std::string> sharedSuffixVec = cmExpandedList(sharedSuffixes);
875875
for (std::string const& i : sharedSuffixVec) {
876-
this->AddLinkExtension(i.c_str(), LinkShared);
876+
this->AddLinkExtension(i, LinkShared);
877877
}
878878
}
879879

@@ -903,7 +903,7 @@ void cmComputeLinkInformation::ComputeItemParserInfo()
903903
#ifdef CM_COMPUTE_LINK_INFO_DEBUG
904904
fprintf(stderr, "any regex [%s]\n", reg_any.c_str());
905905
#endif
906-
this->ExtractAnyLibraryName.compile(reg_any.c_str());
906+
this->ExtractAnyLibraryName.compile(reg_any);
907907

908908
// Create a regex to match static library names.
909909
if (!this->StaticLinkExtensions.empty()) {
@@ -912,7 +912,7 @@ void cmComputeLinkInformation::ComputeItemParserInfo()
912912
#ifdef CM_COMPUTE_LINK_INFO_DEBUG
913913
fprintf(stderr, "static regex [%s]\n", reg_static.c_str());
914914
#endif
915-
this->ExtractStaticLibraryName.compile(reg_static.c_str());
915+
this->ExtractStaticLibraryName.compile(reg_static);
916916
}
917917

918918
// Create a regex to match shared library names.
@@ -924,20 +924,21 @@ void cmComputeLinkInformation::ComputeItemParserInfo()
924924
#ifdef CM_COMPUTE_LINK_INFO_DEBUG
925925
fprintf(stderr, "shared regex [%s]\n", reg_shared.c_str());
926926
#endif
927-
this->ExtractSharedLibraryName.compile(reg_shared.c_str());
927+
this->ExtractSharedLibraryName.compile(reg_shared);
928928
}
929929
}
930930

931-
void cmComputeLinkInformation::AddLinkPrefix(const char* p)
931+
void cmComputeLinkInformation::AddLinkPrefix(std::string const& p)
932932
{
933-
if (p && *p) {
933+
if (!p.empty()) {
934934
this->LinkPrefixes.insert(p);
935935
}
936936
}
937937

938-
void cmComputeLinkInformation::AddLinkExtension(const char* e, LinkType type)
938+
void cmComputeLinkInformation::AddLinkExtension(std::string const& e,
939+
LinkType type)
939940
{
940-
if (e && *e) {
941+
if (!e.empty()) {
941942
if (type == LinkStatic) {
942943
this->StaticLinkExtensions.emplace_back(e);
943944
}
@@ -962,7 +963,7 @@ std::string cmComputeLinkInformation::CreateExtensionRegex(
962963
// Store this extension choice with the "." escaped.
963964
libext += "\\";
964965
#if defined(_WIN32) && !defined(__CYGWIN__)
965-
libext += this->NoCaseExpression(i.c_str());
966+
libext += this->NoCaseExpression(i);
966967
#else
967968
libext += i;
968969
#endif
@@ -980,21 +981,19 @@ std::string cmComputeLinkInformation::CreateExtensionRegex(
980981
return libext;
981982
}
982983

983-
std::string cmComputeLinkInformation::NoCaseExpression(const char* str)
984+
std::string cmComputeLinkInformation::NoCaseExpression(std::string const& str)
984985
{
985986
std::string ret;
986-
ret.reserve(strlen(str) * 4);
987-
const char* s = str;
988-
while (*s) {
989-
if (*s == '.') {
990-
ret += *s;
987+
ret.reserve(str.size() * 4);
988+
for (char c : str) {
989+
if (c == '.') {
990+
ret += c;
991991
} else {
992992
ret += '[';
993-
ret += static_cast<char>(tolower(*s));
994-
ret += static_cast<char>(toupper(*s));
993+
ret += static_cast<char>(tolower(c));
994+
ret += static_cast<char>(toupper(c));
995995
ret += ']';
996996
}
997-
s++;
998997
}
999998
return ret;
1000999
}
@@ -1688,7 +1687,7 @@ void cmComputeLinkInformation::AddLibraryRuntimeInfo(
16881687
}
16891688
}
16901689

1691-
static void cmCLI_ExpandListUnique(const char* str,
1690+
static void cmCLI_ExpandListUnique(std::string const& str,
16921691
std::vector<std::string>& out,
16931692
std::set<std::string>& emitted)
16941693
{
@@ -1735,15 +1734,15 @@ void cmComputeLinkInformation::GetRPath(std::vector<std::string>& runtimeDirs,
17351734
if (use_install_rpath) {
17361735
std::string install_rpath;
17371736
this->Target->GetInstallRPATH(this->Config, install_rpath);
1738-
cmCLI_ExpandListUnique(install_rpath.c_str(), runtimeDirs, emitted);
1737+
cmCLI_ExpandListUnique(install_rpath, runtimeDirs, emitted);
17391738
}
17401739
if (use_build_rpath) {
17411740
// Add directories explicitly specified by user
17421741
std::string build_rpath;
17431742
if (this->Target->GetBuildRPATH(this->Config, build_rpath)) {
17441743
// This will not resolve entries to use $ORIGIN, the user is expected to
17451744
// do that if necessary.
1746-
cmCLI_ExpandListUnique(build_rpath.c_str(), runtimeDirs, emitted);
1745+
cmCLI_ExpandListUnique(build_rpath, runtimeDirs, emitted);
17471746
}
17481747
}
17491748
if (use_build_rpath || use_link_rpath) {
@@ -1823,16 +1822,16 @@ void cmComputeLinkInformation::GetRPath(std::vector<std::string>& runtimeDirs,
18231822
"CMAKE_" + li + "_USE_IMPLICIT_LINK_DIRECTORIES_IN_RUNTIME_PATH";
18241823
if (this->Makefile->IsOn(useVar)) {
18251824
std::string dirVar = "CMAKE_" + li + "_IMPLICIT_LINK_DIRECTORIES";
1826-
if (const char* dirs = this->Makefile->GetDefinition(dirVar)) {
1827-
cmCLI_ExpandListUnique(dirs, runtimeDirs, emitted);
1825+
if (cmProp dirs = this->Makefile->GetDef(dirVar)) {
1826+
cmCLI_ExpandListUnique(*dirs, runtimeDirs, emitted);
18281827
}
18291828
}
18301829
}
18311830
}
18321831

18331832
// Add runtime paths required by the platform to always be
18341833
// present. This is done even when skipping rpath support.
1835-
cmCLI_ExpandListUnique(this->RuntimeAlways.c_str(), runtimeDirs, emitted);
1834+
cmCLI_ExpandListUnique(this->RuntimeAlways, runtimeDirs, emitted);
18361835
}
18371836

18381837
std::string cmComputeLinkInformation::GetRPathString(bool for_install) const

Source/cmComputeLinkInformation.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,11 @@ class cmComputeLinkInformation
144144
cmsys::RegularExpression ExtractSharedLibraryName;
145145
cmsys::RegularExpression ExtractAnyLibraryName;
146146
std::string SharedRegexString;
147-
void AddLinkPrefix(const char* p);
148-
void AddLinkExtension(const char* e, LinkType type);
147+
void AddLinkPrefix(std::string const& p);
148+
void AddLinkExtension(std::string const& e, LinkType type);
149149
std::string CreateExtensionRegex(std::vector<std::string> const& exts,
150150
LinkType type);
151-
std::string NoCaseExpression(const char* str);
151+
std::string NoCaseExpression(std::string const& str);
152152

153153
// Handling of link items.
154154
void AddTargetItem(BT<std::string> const& item,

0 commit comments

Comments
 (0)