diff options
author | Brad King <brad.king@kitware.com> | 2015-05-18 17:31:11 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2015-05-18 19:01:06 (GMT) |
commit | a390de65e09e3ebc496fc14d40848ea4940cc9b0 (patch) | |
tree | f8d2c58ba7b46117e408af8378cfd79a3e370f5f /Source/cmGlobalNinjaGenerator.cxx | |
parent | 00ccfff2bc06e640a185fb3d628ac36ea0b0fe9a (diff) | |
download | CMake-a390de65e09e3ebc496fc14d40848ea4940cc9b0.zip CMake-a390de65e09e3ebc496fc14d40848ea4940cc9b0.tar.gz CMake-a390de65e09e3ebc496fc14d40848ea4940cc9b0.tar.bz2 |
Ninja: Generate separate compile and link rules for each target
Our <LANG>_COMPILER and <LANG>_<TARGET_TYPE>_LINKER rule generation has
access to a specific cmTarget so the results may depend on it. Instead
generate separate rules for each target using an encoded target name.
In particular, this makes CTEST_USE_LAUNCHERS report proper target
information.
Diffstat (limited to 'Source/cmGlobalNinjaGenerator.cxx')
-rw-r--r-- | Source/cmGlobalNinjaGenerator.cxx | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 9a952a3..e064b84 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -21,6 +21,7 @@ #include <algorithm> #include <assert.h> +#include <ctype.h> const char* cmGlobalNinjaGenerator::NINJA_BUILD_FILE = "build.ninja"; const char* cmGlobalNinjaGenerator::NINJA_RULES_FILE = "rules.ninja"; @@ -57,6 +58,28 @@ void cmGlobalNinjaGenerator::WriteComment(std::ostream& os, os << "# " << replace.substr(lpos) << "\n\n"; } +std::string cmGlobalNinjaGenerator::EncodeRuleName(std::string const& name) +{ + // Ninja rule names must match "[a-zA-Z0-9_.-]+". Use ".xx" to encode + // "." and all invalid characters as hexadecimal. + std::string encoded; + for (std::string::const_iterator i = name.begin(); + i != name.end(); ++i) + { + if (isalnum(*i) || *i == '_' || *i == '-') + { + encoded += *i; + } + else + { + char buf[16]; + sprintf(buf, ".%02x", static_cast<unsigned int>(*i)); + encoded += buf; + } + } + return encoded; +} + static bool IsIdentChar(char c) { return @@ -120,7 +143,8 @@ void cmGlobalNinjaGenerator::WriteBuild(std::ostream& os, const cmNinjaDeps& orderOnlyDeps, const cmNinjaVars& variables, const std::string& rspfile, - int cmdLineLimit) + int cmdLineLimit, + bool* usedResponseFile) { // Make sure there is a rule. if(rule.empty()) @@ -205,6 +229,7 @@ void cmGlobalNinjaGenerator::WriteBuild(std::ostream& os, std::string buildstr = build; std::string assignments = variable_assignments.str(); const std::string& args = arguments; + bool useResponseFile = false; if (cmdLineLimit > 0 && args.size() + buildstr.size() + assignments.size() > (size_t) cmdLineLimit) { @@ -213,7 +238,12 @@ void cmGlobalNinjaGenerator::WriteBuild(std::ostream& os, cmGlobalNinjaGenerator::WriteVariable(variable_assignments, "RSP_FILE", rspfile, "", 1); assignments += variable_assignments.str(); + useResponseFile = true; } + if (usedResponseFile) + { + *usedResponseFile = useResponseFile; + } os << buildstr << args << assignments; } |