diff options
author | Ben Boeckel <ben.boeckel@kitware.com> | 2024-04-29 21:23:08 (GMT) |
---|---|---|
committer | Ben Boeckel <ben.boeckel@kitware.com> | 2024-04-29 21:23:08 (GMT) |
commit | 4452d41488d8ebd660f129aebb57a87c5dbb4caa (patch) | |
tree | 738ba46ecdc86e7be7c9c304d6836e86f2feabb1 | |
parent | b5602e7254c8ce4a6f732c017d784cd80559e5aa (diff) | |
download | CMake-4452d41488d8ebd660f129aebb57a87c5dbb4caa.zip CMake-4452d41488d8ebd660f129aebb57a87c5dbb4caa.tar.gz CMake-4452d41488d8ebd660f129aebb57a87c5dbb4caa.tar.bz2 |
cmGeneratorTarget: add method to get a filesystem-safe export name
C++ module support puts the export name in a filename. Export names with
`:` in them are not valid filenames on Windows. Add a method to escape
names as necessary.
See: #25828
-rw-r--r-- | Source/cmGeneratorTarget.cxx | 10 | ||||
-rw-r--r-- | Source/cmGeneratorTarget.h | 1 |
2 files changed, 11 insertions, 0 deletions
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 94bb8e1..5196e4e 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -367,6 +367,16 @@ std::string cmGeneratorTarget::GetExportName() const return this->GetName(); } +std::string cmGeneratorTarget::GetFilesystemExportName() const +{ + auto fs_safe = this->GetExportName(); + // First escape any `_` characters to avoid collisions. + cmSystemTools::ReplaceString(fs_safe, "_", "__"); + // Escape other characters that are not generally filesystem-safe. + cmSystemTools::ReplaceString(fs_safe, ":", "_c"); + return fs_safe; +} + cmValue cmGeneratorTarget::GetProperty(const std::string& prop) const { if (cmValue result = diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 736aab0..7cd7f43 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -99,6 +99,7 @@ public: cmStateEnums::TargetType GetType() const; const std::string& GetName() const; std::string GetExportName() const; + std::string GetFilesystemExportName() const; std::vector<std::string> GetPropertyKeys() const; //! Might return a nullptr if the property is not set or invalid |