diff options
author | Brad King <brad.king@kitware.com> | 2016-05-19 14:41:27 (GMT) |
---|---|---|
committer | CMake Topic Stage <kwrobot@kitware.com> | 2016-05-19 14:41:27 (GMT) |
commit | e0da6c3b562f7fd25b83b00c432f016439c24c22 (patch) | |
tree | 43e44454dbdf69f2caffe587a270e1446a2c7d2b /Source | |
parent | 43a456e1351fc6c2aca088a55855b7f7c501c100 (diff) | |
parent | eb076692459a8d4cc214156af3553c36309bdce3 (diff) | |
download | CMake-e0da6c3b562f7fd25b83b00c432f016439c24c22.zip CMake-e0da6c3b562f7fd25b83b00c432f016439c24c22.tar.gz CMake-e0da6c3b562f7fd25b83b00c432f016439c24c22.tar.bz2 |
Merge topic 'ninja-output-path-prefix'
eb076692 Tests: Select RunCMake.Ninja test cases based on ninja version
8a862a4d Ninja: Support embedding of CMake as subninja project
038e7716 Ninja: Pass all build paths through a central method
7c26a6a2 Ninja: Fix path to soname-d target file
ac3cdd9a Ninja: Convert object file names to ninja paths earlier
d4381cb1 Ninja: Convert link library file names like all other output paths
0397c92a Ninja: Pre-compute "CMakeCache.txt" build target name
3b3ecdfa Ninja: Pre-compute "all" build target name
5ca72750 Ninja: Simplify generation of custom target logical path
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmAlgorithms.h | 15 | ||||
-rw-r--r-- | Source/cmGlobalNinjaGenerator.cxx | 88 | ||||
-rw-r--r-- | Source/cmGlobalNinjaGenerator.h | 11 | ||||
-rw-r--r-- | Source/cmLocalNinjaGenerator.cxx | 12 | ||||
-rw-r--r-- | Source/cmNinjaNormalTargetGenerator.cxx | 3 | ||||
-rw-r--r-- | Source/cmNinjaTargetGenerator.cxx | 20 | ||||
-rw-r--r-- | Source/cmNinjaUtilityTargetGenerator.cxx | 2 |
7 files changed, 119 insertions, 32 deletions
diff --git a/Source/cmAlgorithms.h b/Source/cmAlgorithms.h index 76acaca..ee803c8 100644 --- a/Source/cmAlgorithms.h +++ b/Source/cmAlgorithms.h @@ -379,4 +379,19 @@ std::reverse_iterator<Iter> cmMakeReverseIterator(Iter it) return std::reverse_iterator<Iter>(it); } +inline bool cmHasSuffix(const std::string& str, const std::string& suffix) +{ + if (str.size() < suffix.size()) { + return false; + } + return str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0; +} + +inline void cmStripSuffixIfExists(std::string& str, const std::string& suffix) +{ + if (cmHasSuffix(str, suffix)) { + str.resize(str.size() - suffix.size()); + } +} + #endif diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 012ef90..d65b463 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -488,6 +488,10 @@ void cmGlobalNinjaGenerator::Generate() this->OpenBuildFileStream(); this->OpenRulesFileStream(); + this->InitOutputPathPrefix(); + this->TargetAll = this->NinjaOutputPath("all"); + this->CMakeCacheFile = this->NinjaOutputPath("CMakeCache.txt"); + this->PolicyCMP0058 = this->LocalGenerators[0]->GetMakefile()->GetPolicyStatus( cmPolicies::CMP0058); @@ -714,11 +718,29 @@ void cmGlobalNinjaGenerator::CloseRulesFileStream() } } +static void EnsureTrailingSlash(std::string& path) +{ + if (path.empty()) { + return; + } + std::string::value_type last = path[path.size() - 1]; +#ifdef _WIN32 + if (last != '\\') { + path += '\\'; + } +#else + if (last != '/') { + path += '/'; + } +#endif +} + std::string cmGlobalNinjaGenerator::ConvertToNinjaPath(const std::string& path) { cmLocalNinjaGenerator* ng = static_cast<cmLocalNinjaGenerator*>(this->LocalGenerators[0]); std::string convPath = ng->Convert(path, cmOutputConverter::HOME_OUTPUT); + convPath = this->NinjaOutputPath(convPath); #ifdef _WIN32 cmSystemTools::ReplaceString(convPath, "/", "\\"); #endif @@ -731,6 +753,7 @@ std::string cmGlobalNinjaGenerator::ConvertToNinjaFolderRule( cmLocalNinjaGenerator* ng = static_cast<cmLocalNinjaGenerator*>(this->LocalGenerators[0]); std::string convPath = ng->Convert(path + "/all", cmOutputConverter::HOME); + convPath = this->NinjaOutputPath(convPath); #ifdef _WIN32 cmSystemTools::ReplaceString(convPath, "/", "\\"); #endif @@ -836,22 +859,17 @@ void cmGlobalNinjaGenerator::AppendTargetOutputs( } case cmState::OBJECT_LIBRARY: case cmState::UTILITY: { - std::string path = this->ConvertToNinjaPath( - target->GetLocalGenerator()->GetCurrentBinaryDirectory()); - if (path.empty() || path == ".") - outputs.push_back(target->GetName()); - else { - path += "/"; - path += target->GetName(); - outputs.push_back(path); - } + std::string path = + target->GetLocalGenerator()->GetCurrentBinaryDirectory() + + std::string("/") + target->GetName(); + outputs.push_back(this->ConvertToNinjaPath(path)); break; } case cmState::GLOBAL_TARGET: // Always use the target in HOME instead of an unused duplicate in a // subdirectory. - outputs.push_back(target->GetName()); + outputs.push_back(this->NinjaOutputPath(target->GetName())); break; default: @@ -885,6 +903,7 @@ void cmGlobalNinjaGenerator::AppendTargetDepends( void cmGlobalNinjaGenerator::AddTargetAlias(const std::string& alias, cmGeneratorTarget* target) { + std::string buildAlias = this->NinjaOutputPath(alias); cmNinjaDeps outputs; this->AppendTargetOutputs(target, outputs); // Mark the target's outputs as ambiguous to ensure that no other target uses @@ -895,7 +914,7 @@ void cmGlobalNinjaGenerator::AddTargetAlias(const std::string& alias, // Insert the alias into the map. If the alias was already present in the // map and referred to another target, mark it as ambiguous. std::pair<TargetAliasMap::iterator, bool> newAlias = - TargetAliases.insert(std::make_pair(alias, target)); + TargetAliases.insert(std::make_pair(buildAlias, target)); if (newAlias.second && newAlias.first->second != target) newAlias.first->second = 0; } @@ -1043,7 +1062,7 @@ void cmGlobalNinjaGenerator::WriteUnknownExplicitDependencies(std::ostream& os) } } } - knownDependencies.insert("CMakeCache.txt"); + knownDependencies.insert(this->CMakeCacheFile); for (TargetAliasMap::const_iterator i = this->TargetAliases.begin(); i != this->TargetAliases.end(); ++i) { @@ -1064,7 +1083,7 @@ void cmGlobalNinjaGenerator::WriteUnknownExplicitDependencies(std::ostream& os) // should all match now. std::vector<std::string> unknownExplicitDepends; - this->CombinedCustomCommandExplicitDependencies.erase("all"); + this->CombinedCustomCommandExplicitDependencies.erase(this->TargetAll); std::set_difference(this->CombinedCustomCommandExplicitDependencies.begin(), this->CombinedCustomCommandExplicitDependencies.end(), @@ -1130,13 +1149,15 @@ void cmGlobalNinjaGenerator::WriteBuiltinTargets(std::ostream& os) void cmGlobalNinjaGenerator::WriteTargetAll(std::ostream& os) { cmNinjaDeps outputs; - outputs.push_back("all"); + outputs.push_back(this->TargetAll); this->WritePhonyBuild(os, "The main all target.", outputs, this->AllDependencies); - cmGlobalNinjaGenerator::WriteDefault(os, outputs, - "Make the all target the default."); + if (!this->HasOutputPathPrefix()) { + cmGlobalNinjaGenerator::WriteDefault(os, outputs, + "Make the all target the default."); + } } void cmGlobalNinjaGenerator::WriteTargetRebuildManifest(std::ostream& os) @@ -1171,7 +1192,7 @@ void cmGlobalNinjaGenerator::WriteTargetRebuildManifest(std::ostream& os) implicitDeps.push_back(this->ConvertToNinjaPath(*fi)); } } - implicitDeps.push_back("CMakeCache.txt"); + implicitDeps.push_back(this->CMakeCacheFile); std::sort(implicitDeps.begin(), implicitDeps.end()); implicitDeps.erase(std::unique(implicitDeps.begin(), implicitDeps.end()), @@ -1184,9 +1205,10 @@ void cmGlobalNinjaGenerator::WriteTargetRebuildManifest(std::ostream& os) variables["pool"] = "console"; } + std::string const ninjaBuildFile = this->NinjaOutputPath(NINJA_BUILD_FILE); this->WriteBuild(os, "Re-run CMake if any of its inputs changed.", "RERUN_CMAKE", - /*outputs=*/cmNinjaDeps(1, NINJA_BUILD_FILE), + /*outputs=*/cmNinjaDeps(1, ninjaBuildFile), /*explicitDeps=*/cmNinjaDeps(), implicitDeps, /*orderOnlyDeps=*/cmNinjaDeps(), variables); @@ -1223,7 +1245,7 @@ void cmGlobalNinjaGenerator::WriteTargetClean(std::ostream& os) /*restat=*/"", /*generator=*/false); WriteBuild(os, "Clean all the built files.", "CLEAN", - /*outputs=*/cmNinjaDeps(1, "clean"), + /*outputs=*/cmNinjaDeps(1, this->NinjaOutputPath("clean")), /*explicitDeps=*/cmNinjaDeps(), /*implicitDeps=*/cmNinjaDeps(), /*orderOnlyDeps=*/cmNinjaDeps(), @@ -1242,9 +1264,35 @@ void cmGlobalNinjaGenerator::WriteTargetHelp(std::ostream& os) /*restat=*/"", /*generator=*/false); WriteBuild(os, "Print all primary targets available.", "HELP", - /*outputs=*/cmNinjaDeps(1, "help"), + /*outputs=*/cmNinjaDeps(1, this->NinjaOutputPath("help")), /*explicitDeps=*/cmNinjaDeps(), /*implicitDeps=*/cmNinjaDeps(), /*orderOnlyDeps=*/cmNinjaDeps(), /*variables=*/cmNinjaVars()); } + +void cmGlobalNinjaGenerator::InitOutputPathPrefix() +{ + this->OutputPathPrefix = + this->LocalGenerators[0]->GetMakefile()->GetSafeDefinition( + "CMAKE_NINJA_OUTPUT_PATH_PREFIX"); + EnsureTrailingSlash(this->OutputPathPrefix); +} + +std::string cmGlobalNinjaGenerator::NinjaOutputPath(std::string const& path) +{ + if (!this->HasOutputPathPrefix() || cmSystemTools::FileIsFullPath(path)) { + return path; + } + return this->OutputPathPrefix + path; +} + +void cmGlobalNinjaGenerator::StripNinjaOutputPathPrefixAsSuffix( + std::string& path) +{ + if (path.empty()) { + return; + } + EnsureTrailingSlash(path); + cmStripSuffixIfExists(path, this->OutputPathPrefix); +} diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h index 881104f..6d9bfe8 100644 --- a/Source/cmGlobalNinjaGenerator.h +++ b/Source/cmGlobalNinjaGenerator.h @@ -314,6 +314,10 @@ public: static std::string RequiredNinjaVersionForConsolePool() { return "1.5"; } bool SupportsConsolePool() const; + std::string NinjaOutputPath(std::string const& path); + bool HasOutputPathPrefix() const { return !this->OutputPathPrefix.empty(); } + void StripNinjaOutputPathPrefixAsSuffix(std::string& path); + protected: virtual void Generate(); @@ -397,6 +401,13 @@ private: std::string NinjaCommand; std::string NinjaVersion; + +private: + void InitOutputPathPrefix(); + + std::string OutputPathPrefix; + std::string TargetAll; + std::string CMakeCacheFile; }; #endif // ! cmGlobalNinjaGenerator_h diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx index 671d8a0..c7e1a90f8 100644 --- a/Source/cmLocalNinjaGenerator.cxx +++ b/Source/cmLocalNinjaGenerator.cxx @@ -123,7 +123,8 @@ cmGlobalNinjaGenerator* cmLocalNinjaGenerator::GetGlobalNinjaGenerator() std::string cmLocalNinjaGenerator::ConvertToLinkReference( std::string const& lib, OutputFormat format) { - return this->Convert(lib, HOME_OUTPUT, format); + std::string path = this->GetGlobalNinjaGenerator()->ConvertToNinjaPath(lib); + return this->ConvertToOutputFormat(path, format); } std::string cmLocalNinjaGenerator::ConvertToIncludeReference( @@ -224,8 +225,13 @@ void cmLocalNinjaGenerator::WriteNinjaFilesInclusion(std::ostream& os) cmGlobalNinjaGenerator::WriteDivider(os); os << "# Include auxiliary files.\n" << "\n"; - cmGlobalNinjaGenerator::WriteInclude( - os, cmGlobalNinjaGenerator::NINJA_RULES_FILE, "Include rules file."); + cmGlobalNinjaGenerator* ng = this->GetGlobalNinjaGenerator(); + std::string const ninjaRulesFile = + ng->NinjaOutputPath(cmGlobalNinjaGenerator::NINJA_RULES_FILE); + std::string const rulesFilePath = + ng->EncodeIdent(ng->EncodePath(ninjaRulesFile), os); + cmGlobalNinjaGenerator::WriteInclude(os, rulesFilePath, + "Include rules file."); os << "\n"; } diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index 831d44b..8d7a892 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -652,7 +652,8 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() cmNinjaDeps(1, targetOutputReal), emptyDeps, emptyDeps, symlinkVars); } else { cmNinjaDeps symlinks; - const std::string soName = this->GetTargetFilePath(this->TargetNameSO); + std::string const soName = + this->ConvertToNinjaPath(this->GetTargetFilePath(this->TargetNameSO)); // If one link has to be created. if (targetOutputReal == soName || targetOutput == soName) { symlinkVars["SONAME"] = soName; diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index c214c8a..4d58242 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -521,8 +521,10 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( std::string const language = source->GetLanguage(); std::string const sourceFileName = language == "RC" ? source->GetFullPath() : this->GetSourceFilePath(source); - std::string const objectDir = this->GeneratorTarget->GetSupportDirectory(); - std::string const objectFileName = this->GetObjectFilePath(source); + std::string const objectDir = + this->ConvertToNinjaPath(this->GeneratorTarget->GetSupportDirectory()); + std::string const objectFileName = + this->ConvertToNinjaPath(this->GetObjectFilePath(source)); std::string const objectFileDir = cmSystemTools::GetFilenamePath(objectFileName); @@ -582,9 +584,9 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( EnsureParentDirectoryExists(objectFileName); vars["OBJECT_DIR"] = this->GetLocalGenerator()->ConvertToOutputFormat( - ConvertToNinjaPath(objectDir), cmLocalGenerator::SHELL); + objectDir, cmLocalGenerator::SHELL); vars["OBJECT_FILE_DIR"] = this->GetLocalGenerator()->ConvertToOutputFormat( - ConvertToNinjaPath(objectFileDir), cmLocalGenerator::SHELL); + objectFileDir, cmLocalGenerator::SHELL); this->addPoolNinjaVariable("JOB_POOL_COMPILE", this->GetGeneratorTarget(), vars); @@ -667,10 +669,12 @@ void cmNinjaTargetGenerator::EnsureDirectoryExists( if (cmSystemTools::FileIsFullPath(path.c_str())) { cmSystemTools::MakeDirectory(path.c_str()); } else { - const std::string fullPath = std::string(this->GetGlobalGenerator() - ->GetCMakeInstance() - ->GetHomeOutputDirectory()) + - "/" + path; + cmGlobalNinjaGenerator* gg = this->GetGlobalGenerator(); + std::string fullPath = + std::string(gg->GetCMakeInstance()->GetHomeOutputDirectory()); + // Also ensures their is a trailing slash. + gg->StripNinjaOutputPathPrefixAsSuffix(fullPath); + fullPath += path; cmSystemTools::MakeDirectory(fullPath.c_str()); } } diff --git a/Source/cmNinjaUtilityTargetGenerator.cxx b/Source/cmNinjaUtilityTargetGenerator.cxx index b0b1147..d07341c 100644 --- a/Source/cmNinjaUtilityTargetGenerator.cxx +++ b/Source/cmNinjaUtilityTargetGenerator.cxx @@ -33,6 +33,8 @@ void cmNinjaUtilityTargetGenerator::Generate() { std::string utilCommandName = cmake::GetCMakeFilesDirectoryPostSlash(); utilCommandName += this->GetTargetName() + ".util"; + utilCommandName = + this->GetGlobalGenerator()->NinjaOutputPath(utilCommandName); std::vector<std::string> commands; cmNinjaDeps deps, outputs, util_outputs(1, utilCommandName); |