diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 8e6b9a1dd5..abf72de166 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -4056,6 +4056,27 @@ bool cmLocalGeneratorCheckObjectName(std::string& objName, } } +std::string cmLocalGenerator::CreateSafeObjectFileName( + std::string const& sin) const +{ + // Start with the original name. + std::string ssin = sin; + + // Avoid full paths by removing leading slashes. + ssin.erase(0, ssin.find_first_not_of('/')); + + // Avoid full paths by removing colons. + std::replace(ssin.begin(), ssin.end(), ':', '_'); + + // Avoid relative paths that go up the tree. + cmSystemTools::ReplaceString(ssin, "../", "__/"); + + // Avoid spaces. + std::replace(ssin.begin(), ssin.end(), ' ', '_'); + + return ssin; +} + std::string& cmLocalGenerator::CreateSafeUniqueObjectFileName( std::string const& sin, std::string const& dir_max) { @@ -4064,20 +4085,7 @@ std::string& cmLocalGenerator::CreateSafeUniqueObjectFileName( // If no entry exists create one. if (it == this->UniqueObjectNamesMap.end()) { - // Start with the original name. - std::string ssin = sin; - - // Avoid full paths by removing leading slashes. - ssin.erase(0, ssin.find_first_not_of('/')); - - // Avoid full paths by removing colons. - std::replace(ssin.begin(), ssin.end(), ':', '_'); - - // Avoid relative paths that go up the tree. - cmSystemTools::ReplaceString(ssin, "../", "__/"); - - // Avoid spaces. - std::replace(ssin.begin(), ssin.end(), ' ', '_'); + auto ssin = this->CreateSafeObjectFileName(sin); // Mangle the name if necessary. if (this->Makefile->IsOn("CMAKE_MANGLE_OBJECT_FILE_NAMES")) { diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index 87247d1df3..ee41498bea 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -536,6 +536,8 @@ public: // (If CMP0157 is NEW, we can do a split build) bool IsSplitSwiftBuild() const; + std::string CreateSafeObjectFileName(std::string const& sin) const; + protected: // The default implementation converts to a Windows shortpath to // help older toolchains handle spaces and such. A generator may