diff --git a/Help/generator/Ninja Multi-Config.rst b/Help/generator/Ninja Multi-Config.rst index 248eb0534d..41cd5c26c4 100644 --- a/Help/generator/Ninja Multi-Config.rst +++ b/Help/generator/Ninja Multi-Config.rst @@ -78,4 +78,13 @@ targets built with the generated code. As a convenience, ``Ninja Multi-Config`` offers a :variable:`CMAKE_NINJA_MULTI_DEFAULT_BUILD_TYPE` setting. If this variable is specified, a ``build.ninja`` file will be generated which points to the -specified ``build-.ninja`` file. +specified ``build-.ninja`` file. In addition, if +:variable:`CMAKE_NINJA_MULTI_DEFAULT_BUILD_TYPE` is used in conjunction with +:variable:`CMAKE_NINJA_MULTI_CROSS_CONFIG_ENABLE`, you can also specify +:variable:`CMAKE_NINJA_MULTI_DEFAULT_BUILD_ALIAS`, which changes the config +of the ```` targets in ``build.ninja``. For example, if you set +:variable:`CMAKE_NINJA_MULTI_DEFAULT_BUILD_TYPE` to ``Release``, but set +:variable:`CMAKE_NINJA_MULTI_DEFAULT_BUILD_ALIAS` to ``Debug`` or ``all``, +all ```` aliases in ``build.ninja`` will resolve to ``:Debug`` +or ``:all``, but custom commands will still use the ``Release`` +configuration. diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst index a8fbc0927b..da2b06e4da 100644 --- a/Help/manual/cmake-variables.7.rst +++ b/Help/manual/cmake-variables.7.rst @@ -425,6 +425,7 @@ Variables that Control the Build /variable/CMAKE_MSVCIDE_RUN_PATH /variable/CMAKE_MSVC_RUNTIME_LIBRARY /variable/CMAKE_NINJA_MULTI_CROSS_CONFIG_ENABLE + /variable/CMAKE_NINJA_MULTI_DEFAULT_BUILD_ALIAS /variable/CMAKE_NINJA_MULTI_DEFAULT_BUILD_TYPE /variable/CMAKE_NINJA_OUTPUT_PATH_PREFIX /variable/CMAKE_NO_BUILTIN_CHRPATH diff --git a/Help/variable/CMAKE_NINJA_MULTI_DEFAULT_BUILD_ALIAS.rst b/Help/variable/CMAKE_NINJA_MULTI_DEFAULT_BUILD_ALIAS.rst new file mode 100644 index 0000000000..a997e9b794 --- /dev/null +++ b/Help/variable/CMAKE_NINJA_MULTI_DEFAULT_BUILD_ALIAS.rst @@ -0,0 +1,6 @@ +CMAKE_NINJA_MULTI_DEFAULT_BUILD_ALIAS +------------------------------------- + +Controls the config of ```` aliases in ``build.ninja`` for the +:generator:`Ninja Multi-Config` generator. See the generator's documentation +for more details. diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 1f83ec5de1..0911cd02f4 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -293,7 +293,7 @@ void cmGlobalNinjaGenerator::WriteCustomCommandBuild( if (config.empty()) { this->WriteBuild(*this->GetCommonFileStream(), build); } else { - this->WriteBuild(*this->GetConfigFileStream(config), build); + this->WriteBuild(*this->GetImplFileStream(config), build); } } @@ -324,7 +324,7 @@ void cmGlobalNinjaGenerator::WriteMacOSXContentBuild(std::string input, cmNinjaBuild build("COPY_OSX_CONTENT"); build.Outputs.push_back(std::move(output)); build.ExplicitDeps.push_back(std::move(input)); - this->WriteBuild(*this->GetConfigFileStream(config), build); + this->WriteBuild(*this->GetImplFileStream(config), build); } } @@ -518,6 +518,7 @@ void cmGlobalNinjaGenerator::Generate() if (cmSystemTools::GetErrorOccuredFlag()) { this->RulesFileStream->setstate(std::ios::failbit); for (auto const& config : this->Makefiles[0]->GetGeneratorConfigs()) { + this->GetImplFileStream(config)->setstate(std::ios::failbit); this->GetConfigFileStream(config)->setstate(std::ios::failbit); } this->GetCommonFileStream()->setstate(std::ios::failbit); @@ -527,10 +528,6 @@ void cmGlobalNinjaGenerator::Generate() this->CloseRulesFileStream(); this->CloseBuildFileStreams(); - if (!this->WriteDefaultBuildFile()) { - return; - } - auto run_ninja_tool = [this](std::vector const& args) { std::vector command; command.push_back(this->NinjaCommand); @@ -1164,14 +1161,11 @@ void cmGlobalNinjaGenerator::AddTargetAlias(const std::string& alias, newAliasGlobal.first->second.GeneratorTarget != target) { newAliasGlobal.first->second.GeneratorTarget = nullptr; } - if (config != "all") { - std::pair newAliasConfig = - this->Configs[config].TargetAliases.insert( - std::make_pair(outputPath, ta)); - if (newAliasConfig.second && - newAliasConfig.first->second.GeneratorTarget != target) { - newAliasConfig.first->second.GeneratorTarget = nullptr; - } + std::pair newAliasConfig = + this->Configs[config].TargetAliases.insert(std::make_pair(outputPath, ta)); + if (newAliasConfig.second && + newAliasConfig.first->second.GeneratorTarget != target) { + newAliasConfig.first->second.GeneratorTarget = nullptr; } } @@ -1208,7 +1202,7 @@ void cmGlobalNinjaGenerator::WriteTargetAliases(std::ostream& os) } this->WriteBuild(this->EnableCrossConfigBuild() ? os - : *this->GetConfigFileStream(ta.second.Config), + : *this->GetImplFileStream(ta.second.Config), build); } @@ -1233,6 +1227,37 @@ void cmGlobalNinjaGenerator::WriteTargetAliases(std::ostream& os) this->WriteBuild(*this->GetConfigFileStream(config), build); } } + + auto const* defaultConfig = this->GetDefaultBuildAlias(); + if (defaultConfig) { + std::string config = defaultConfig; + for (auto const& ta : this->Configs[config].TargetAliases) { + // Don't write ambiguous aliases. + if (!ta.second.GeneratorTarget) { + continue; + } + + // Don't write alias if there is a already a custom command with + // matching output + if (this->HasCustomCommandOutput(ta.first)) { + continue; + } + + build.Outputs.front() = ta.first; + build.ExplicitDeps.clear(); + if (config == "all") { + for (auto const& config2 : + this->Makefiles.front()->GetGeneratorConfigs()) { + this->AppendTargetOutputs(ta.second.GeneratorTarget, + build.ExplicitDeps, config2); + } + } else { + this->AppendTargetOutputs(ta.second.GeneratorTarget, + build.ExplicitDeps, config); + } + this->WriteBuild(*this->GetDefaultFileStream(), build); + } + } } } @@ -1276,10 +1301,9 @@ void cmGlobalNinjaGenerator::WriteFolderTargets(std::ostream& os) } } // Write target - this->WriteBuild(this->EnableCrossConfigBuild() - ? os - : *this->GetConfigFileStream(config), - build); + this->WriteBuild( + this->EnableCrossConfigBuild() ? os : *this->GetImplFileStream(config), + build); } // Add shortcut target @@ -1291,6 +1315,16 @@ void cmGlobalNinjaGenerator::WriteFolderTargets(std::ostream& os) this->ConvertToNinjaPath(currentBinaryDir + "/all"); this->WriteBuild(*this->GetConfigFileStream(config), build); } + + auto const* defaultConfig = this->GetDefaultBuildAlias(); + if (defaultConfig) { + std::string config = defaultConfig; + build.ExplicitDeps = { this->BuildAlias( + this->ConvertToNinjaPath(currentBinaryDir + "/all"), config) }; + build.Outputs.front() = + this->ConvertToNinjaPath(currentBinaryDir + "/all"); + this->WriteBuild(*this->GetDefaultFileStream(), build); + } } // Add target for all configs @@ -1442,6 +1476,10 @@ void cmGlobalNinjaGenerator::WriteBuiltinTargets(std::ostream& os) for (auto const& config : this->Makefiles[0]->GetGeneratorConfigs()) { this->WriteTargetDefault(*this->GetConfigFileStream(config)); } + + if (this->GetDefaultBuildType()) { + this->WriteTargetDefault(*this->GetDefaultFileStream()); + } } void cmGlobalNinjaGenerator::WriteTargetDefault(std::ostream& os) @@ -1734,9 +1772,10 @@ void cmGlobalNinjaGenerator::WriteTargetClean(std::ostream& os) } if (this->IsMultiConfig()) { build.Variables["FILE_ARG"] = cmStrCat( - "-f ", cmGlobalNinjaMultiGenerator::GetNinjaFilename(fileConfig)); + "-f ", + cmGlobalNinjaMultiGenerator::GetNinjaImplFilename(fileConfig)); } - this->WriteBuild(*this->GetConfigFileStream(fileConfig), build); + this->WriteBuild(*this->GetImplFileStream(fileConfig), build); } } @@ -1754,8 +1793,9 @@ void cmGlobalNinjaGenerator::WriteTargetClean(std::ostream& os) for (auto const& fileConfig : configs) { build.Variables["FILE_ARG"] = cmStrCat( - "-f ", cmGlobalNinjaMultiGenerator::GetNinjaFilename(fileConfig)); - this->WriteBuild(*this->GetConfigFileStream(fileConfig), build); + "-f ", + cmGlobalNinjaMultiGenerator::GetNinjaImplFilename(fileConfig)); + this->WriteBuild(*this->GetImplFileStream(fileConfig), build); } } } @@ -1771,6 +1811,14 @@ void cmGlobalNinjaGenerator::WriteTargetClean(std::ostream& os) this->NinjaOutputPath(this->GetCleanTargetName()), config); this->WriteBuild(*this->GetConfigFileStream(config), build); } + + auto const* defaultConfig = this->GetDefaultBuildAlias(); + if (defaultConfig) { + std::string config = defaultConfig; + build.ExplicitDeps.front() = this->BuildAlias( + this->NinjaOutputPath(this->GetCleanTargetName()), config); + this->WriteBuild(*this->GetDefaultFileStream(), build); + } } // Write byproducts @@ -2311,7 +2359,8 @@ void cmGlobalNinjaGenerator::AppendDirectoryForConfig( } } -const char* cmGlobalNinjaMultiGenerator::NINJA_COMMON_FILE = "common.ninja"; +const char* cmGlobalNinjaMultiGenerator::NINJA_COMMON_FILE = + "CMakeFiles/common.ninja"; const char* cmGlobalNinjaMultiGenerator::NINJA_FILE_EXTENSION = ".ninja"; cmGlobalNinjaMultiGenerator::cmGlobalNinjaMultiGenerator(cmake* cm) @@ -2342,21 +2391,45 @@ bool cmGlobalNinjaMultiGenerator::OpenBuildFileStreams() return false; } + auto const* defaultConfig = this->GetDefaultBuildType(); + if (defaultConfig) { + if (!this->OpenFileStream(this->DefaultFileStream, NINJA_BUILD_FILE)) { + return false; + } + *this->DefaultFileStream + << "# This file is a convenience file generated by\n" + << "# CMAKE_NINJA_MULTI_DEFAULT_BUILD_TYPE.\n\n" + << "include " << GetNinjaImplFilename(defaultConfig) << "\n\n"; + } + // Write a comment about this file. *this->CommonFileStream << "# This file contains build statements common to all " "configurations.\n\n"; for (auto const& config : this->Makefiles[0]->GetGeneratorConfigs()) { + // Open impl file. + if (!this->OpenFileStream(this->ImplFileStreams[config], + GetNinjaImplFilename(config))) { + return false; + } + + // Write a comment about this file. + *this->ImplFileStreams[config] + << "# This file contains build statements specific to the \"" << config + << "\"\n# configuration.\n\n"; + + // Open config file. if (!this->OpenFileStream(this->ConfigFileStreams[config], - GetNinjaFilename(config))) { + GetNinjaConfigFilename(config))) { return false; } // Write a comment about this file. *this->ConfigFileStreams[config] - << "# This file contains build statements specific to the \"" << config - << "\"\n# configuration.\n\n"; + << "# This file contains aliases specific to the \"" << config + << "\"\n# configuration.\n\n" + << "include " << GetNinjaImplFilename(config) << "\n\n"; } return true; @@ -2370,7 +2443,17 @@ void cmGlobalNinjaMultiGenerator::CloseBuildFileStreams() cmSystemTools::Error("Common file stream was not open."); } + if (this->DefaultFileStream) { + this->DefaultFileStream.reset(); + } // No error if it wasn't open + for (auto const& config : this->Makefiles[0]->GetGeneratorConfigs()) { + if (this->ImplFileStreams[config]) { + this->ImplFileStreams[config].reset(); + } else { + cmSystemTools::Error( + cmStrCat("Impl file stream for \"", config, "\" was not open.")); + } if (this->ConfigFileStreams[config]) { this->ConfigFileStreams[config].reset(); } else { @@ -2384,10 +2467,17 @@ void cmGlobalNinjaMultiGenerator::AppendNinjaFileArgument( GeneratedMakeCommand& command, const std::string& config) const { command.Add("-f"); - command.Add(GetNinjaFilename(config)); + command.Add(GetNinjaConfigFilename(config)); } -std::string cmGlobalNinjaMultiGenerator::GetNinjaFilename( +std::string cmGlobalNinjaMultiGenerator::GetNinjaImplFilename( + const std::string& config) +{ + return cmStrCat("CMakeFiles/impl-", config, + cmGlobalNinjaMultiGenerator::NINJA_FILE_EXTENSION); +} + +std::string cmGlobalNinjaMultiGenerator::GetNinjaConfigFilename( const std::string& config) { return cmStrCat("build-", config, @@ -2398,7 +2488,8 @@ void cmGlobalNinjaMultiGenerator::AddRebuildManifestOutputs( cmNinjaDeps& outputs) const { for (auto const& config : this->Makefiles.front()->GetGeneratorConfigs()) { - outputs.push_back(this->NinjaOutputPath(GetNinjaFilename(config))); + outputs.push_back(this->NinjaOutputPath(GetNinjaImplFilename(config))); + outputs.push_back(this->NinjaOutputPath(GetNinjaConfigFilename(config))); } if (this->Makefiles.front()->GetDefinition( "CMAKE_NINJA_MULTI_DEFAULT_BUILD_TYPE")) { @@ -2416,20 +2507,21 @@ void cmGlobalNinjaMultiGenerator::GetQtAutoGenConfigs( } } -bool cmGlobalNinjaMultiGenerator::WriteDefaultBuildFile() +const char* cmGlobalNinjaMultiGenerator::GetDefaultBuildType() const { - auto const* defaultConfig = this->Makefiles.front()->GetDefinition( + return this->Makefiles.front()->GetDefinition( "CMAKE_NINJA_MULTI_DEFAULT_BUILD_TYPE"); - if (defaultConfig) { - std::unique_ptr defaultStream; - if (!this->OpenFileStream(defaultStream, NINJA_BUILD_FILE)) { - return false; +} + +const char* cmGlobalNinjaMultiGenerator::GetDefaultBuildAlias() const +{ + if (this->EnableCrossConfigBuild()) { + auto const* alias = this->Makefiles.front()->GetDefinition( + "CMAKE_NINJA_MULTI_DEFAULT_BUILD_ALIAS"); + if (alias) { + return alias; } - *defaultStream << "# This file is a convenience file generated by\n" - << "# CMAKE_NINJA_MULTI_DEFAULT_BUILD_TYPE.\n\n" - << "include " << this->GetNinjaFilename(defaultConfig) - << "\n"; } - return true; + return this->GetDefaultBuildType(); } diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h index 3545f1e869..b61999f66e 100644 --- a/Source/cmGlobalNinjaGenerator.h +++ b/Source/cmGlobalNinjaGenerator.h @@ -208,12 +208,23 @@ public: } const char* GetCleanTargetName() const override { return "clean"; } + virtual cmGeneratedFileStream* GetImplFileStream( + const std::string& /*config*/) const + { + return this->BuildFileStream.get(); + } + virtual cmGeneratedFileStream* GetConfigFileStream( const std::string& /*config*/) const { return this->BuildFileStream.get(); } + virtual cmGeneratedFileStream* GetDefaultFileStream() const + { + return this->BuildFileStream.get(); + } + virtual cmGeneratedFileStream* GetCommonFileStream() const { return this->BuildFileStream.get(); @@ -397,6 +408,10 @@ public: bool EnableCrossConfigBuild() const; + virtual const char* GetDefaultBuildType() const { return nullptr; } + + virtual const char* GetDefaultBuildAlias() const { return nullptr; } + protected: void Generate() override; @@ -404,7 +419,6 @@ protected: virtual bool OpenBuildFileStreams(); virtual void CloseBuildFileStreams(); - virtual bool WriteDefaultBuildFile() { return true; } bool OpenFileStream(std::unique_ptr& stream, const std::string& name); @@ -573,12 +587,23 @@ public: std::string ExpandCFGIntDir(const std::string& str, const std::string& config) const override; + cmGeneratedFileStream* GetImplFileStream( + const std::string& config) const override + { + return this->ImplFileStreams.at(config).get(); + } + cmGeneratedFileStream* GetConfigFileStream( const std::string& config) const override { return this->ConfigFileStreams.at(config).get(); } + cmGeneratedFileStream* GetDefaultFileStream() const override + { + return this->DefaultFileStream.get(); + } + cmGeneratedFileStream* GetCommonFileStream() const override { return this->CommonFileStream.get(); @@ -587,22 +612,28 @@ public: void AppendNinjaFileArgument(GeneratedMakeCommand& command, const std::string& config) const override; - static std::string GetNinjaFilename(const std::string& config); + static std::string GetNinjaImplFilename(const std::string& config); + static std::string GetNinjaConfigFilename(const std::string& config); void AddRebuildManifestOutputs(cmNinjaDeps& outputs) const override; void GetQtAutoGenConfigs(std::vector& configs) const override; - bool WriteDefaultBuildFile() override; + const char* GetDefaultBuildType() const override; + + const char* GetDefaultBuildAlias() const override; protected: bool OpenBuildFileStreams() override; void CloseBuildFileStreams() override; private: + std::map> + ImplFileStreams; std::map> ConfigFileStreams; std::unique_ptr CommonFileStream; + std::unique_ptr DefaultFileStream; }; #endif // ! cmGlobalNinjaGenerator_h diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx index 69670975b9..be1dd0df53 100644 --- a/Source/cmLocalNinjaGenerator.cxx +++ b/Source/cmLocalNinjaGenerator.cxx @@ -64,7 +64,7 @@ void cmLocalNinjaGenerator::Generate() if (this->GetGlobalGenerator()->IsMultiConfig()) { for (auto const& config : this->GetConfigNames()) { - this->WriteProcessedMakefile(this->GetConfigFileStream(config)); + this->WriteProcessedMakefile(this->GetImplFileStream(config)); } } this->WriteProcessedMakefile(this->GetCommonFileStream()); @@ -154,10 +154,10 @@ std::string cmLocalNinjaGenerator::ConvertToIncludeReference( // Private methods. -cmGeneratedFileStream& cmLocalNinjaGenerator::GetConfigFileStream( +cmGeneratedFileStream& cmLocalNinjaGenerator::GetImplFileStream( const std::string& config) const { - return *this->GetGlobalNinjaGenerator()->GetConfigFileStream(config); + return *this->GetGlobalNinjaGenerator()->GetImplFileStream(config); } cmGeneratedFileStream& cmLocalNinjaGenerator::GetCommonFileStream() const @@ -186,7 +186,7 @@ void cmLocalNinjaGenerator::WriteBuildFileTop() if (this->GetGlobalGenerator()->IsMultiConfig()) { for (auto const& config : this->GetConfigNames()) { - auto& stream = this->GetConfigFileStream(config); + auto& stream = this->GetImplFileStream(config); this->WriteProjectHeader(stream); this->WriteNinjaRequiredVersion(stream); this->WriteNinjaConfigurationVariable(stream, config); @@ -560,7 +560,7 @@ void cmLocalNinjaGenerator::WriteCustomCommandBuildStatement( build.Outputs = std::move(ninjaOutputs); build.ExplicitDeps = std::move(ninjaDeps); build.OrderOnlyDeps = orderOnlyDeps; - gg->WriteBuild(this->GetConfigFileStream(config), build); + gg->WriteBuild(this->GetImplFileStream(config), build); } else { std::string customStep = cmSystemTools::GetFilenameName(ninjaOutputs[0]); // Hash full path to make unique. diff --git a/Source/cmLocalNinjaGenerator.h b/Source/cmLocalNinjaGenerator.h index 0445879c7f..ef160e70f8 100644 --- a/Source/cmLocalNinjaGenerator.h +++ b/Source/cmLocalNinjaGenerator.h @@ -86,7 +86,7 @@ protected: bool forceFullPaths = false) override; private: - cmGeneratedFileStream& GetConfigFileStream(const std::string& config) const; + cmGeneratedFileStream& GetImplFileStream(const std::string& config) const; cmGeneratedFileStream& GetCommonFileStream() const; cmGeneratedFileStream& GetRulesFileStream() const; diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index f853ac510c..a871a9203e 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -811,9 +811,9 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement( } // Write comments. - cmGlobalNinjaGenerator::WriteDivider(this->GetConfigFileStream(fileConfig)); + cmGlobalNinjaGenerator::WriteDivider(this->GetImplFileStream(fileConfig)); const cmStateEnums::TargetType targetType = gt->GetType(); - this->GetConfigFileStream(fileConfig) + this->GetImplFileStream(fileConfig) << "# Link build statements for " << cmState::GetTargetTypeName(targetType) << " target " << this->GetTargetName() << "\n\n"; @@ -1183,7 +1183,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement( // Write the build statement for this target. bool usedResponseFile = false; - globalGen->WriteBuild(this->GetConfigFileStream(fileConfig), linkBuild, + globalGen->WriteBuild(this->GetImplFileStream(fileConfig), linkBuild, commandLineLengthLimit, &usedResponseFile); this->WriteLinkRule(usedResponseFile, config); @@ -1197,7 +1197,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement( } build.ExplicitDeps.push_back(targetOutputReal); build.Variables = std::move(symlinkVars); - globalGen->WriteBuild(this->GetConfigFileStream(fileConfig), build); + globalGen->WriteBuild(this->GetImplFileStream(fileConfig), build); } else { cmNinjaBuild build("CMAKE_SYMLINK_LIBRARY"); build.Comment = "Create library symlink " + targetOutput; @@ -1223,7 +1223,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement( build.ExplicitDeps.push_back(targetOutputReal); build.Variables = std::move(symlinkVars); - globalGen->WriteBuild(this->GetConfigFileStream(fileConfig), build); + globalGen->WriteBuild(this->GetImplFileStream(fileConfig), build); } } diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 5a8c144328..455d8097cd 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -68,10 +68,10 @@ cmNinjaTargetGenerator::cmNinjaTargetGenerator(cmGeneratorTarget* target) cmNinjaTargetGenerator::~cmNinjaTargetGenerator() = default; -cmGeneratedFileStream& cmNinjaTargetGenerator::GetConfigFileStream( +cmGeneratedFileStream& cmNinjaTargetGenerator::GetImplFileStream( const std::string& config) const { - return *this->GetGlobalGenerator()->GetConfigFileStream(config); + return *this->GetGlobalGenerator()->GetImplFileStream(config); } cmGeneratedFileStream& cmNinjaTargetGenerator::GetCommonFileStream() const @@ -815,8 +815,8 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements( bool firstForConfig) { // Write comments. - cmGlobalNinjaGenerator::WriteDivider(this->GetConfigFileStream(fileConfig)); - this->GetConfigFileStream(fileConfig) + cmGlobalNinjaGenerator::WriteDivider(this->GetImplFileStream(fileConfig)); + this->GetImplFileStream(fileConfig) << "# Object build statements for " << cmState::GetTargetTypeName(this->GetGeneratorTarget()->GetType()) << " target " << this->GetTargetName() << "\n\n"; @@ -901,8 +901,8 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements( orderOnlyDeps.push_back(this->ConvertToNinjaPath(tgtDir)); } - this->GetGlobalGenerator()->WriteBuild( - this->GetConfigFileStream(fileConfig), build); + this->GetGlobalGenerator()->WriteBuild(this->GetImplFileStream(fileConfig), + build); } { @@ -935,11 +935,11 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements( this->GeneratorTarget, build.OrderOnlyDeps, config, fileConfig, DependOnTargetArtifact); - this->GetGlobalGenerator()->WriteBuild( - this->GetConfigFileStream(fileConfig), build); + this->GetGlobalGenerator()->WriteBuild(this->GetImplFileStream(fileConfig), + build); } - this->GetConfigFileStream(fileConfig) << "\n"; + this->GetImplFileStream(fileConfig) << "\n"; if (!this->Configs[config].SwiftOutputMap.empty()) { std::string const mapFilePath = @@ -1177,8 +1177,8 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( this->addPoolNinjaVariable("JOB_POOL_COMPILE", this->GetGeneratorTarget(), ppBuild.Variables); - this->GetGlobalGenerator()->WriteBuild( - this->GetConfigFileStream(fileConfig), ppBuild, commandLineLengthLimit); + this->GetGlobalGenerator()->WriteBuild(this->GetImplFileStream(fileConfig), + ppBuild, commandLineLengthLimit); } if (needDyndep) { std::string const dyndep = this->GetDyndepFilePath(language, config); @@ -1210,8 +1210,8 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( if (language == "Swift") { this->EmitSwiftDependencyInfo(source, config); } else { - this->GetGlobalGenerator()->WriteBuild( - this->GetConfigFileStream(fileConfig), objBuild, commandLineLengthLimit); + this->GetGlobalGenerator()->WriteBuild(this->GetImplFileStream(fileConfig), + objBuild, commandLineLengthLimit); } if (const char* objectOutputs = source->GetProperty("OBJECT_OUTPUTS")) { @@ -1221,8 +1221,8 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( std::transform(build.Outputs.begin(), build.Outputs.end(), build.Outputs.begin(), MapToNinjaPath()); build.ExplicitDeps = objBuild.Outputs; - this->GetGlobalGenerator()->WriteBuild( - this->GetConfigFileStream(fileConfig), build); + this->GetGlobalGenerator()->WriteBuild(this->GetImplFileStream(fileConfig), + build); } } diff --git a/Source/cmNinjaTargetGenerator.h b/Source/cmNinjaTargetGenerator.h index 22dd7b8cb5..bca12b1680 100644 --- a/Source/cmNinjaTargetGenerator.h +++ b/Source/cmNinjaTargetGenerator.h @@ -47,7 +47,7 @@ public: protected: bool SetMsvcTargetPdbVariable(cmNinjaVars&, const std::string& config) const; - cmGeneratedFileStream& GetConfigFileStream(const std::string& config) const; + cmGeneratedFileStream& GetImplFileStream(const std::string& config) const; cmGeneratedFileStream& GetCommonFileStream() const; cmGeneratedFileStream& GetRulesFileStream() const; diff --git a/Source/cmNinjaUtilityTargetGenerator.cxx b/Source/cmNinjaUtilityTargetGenerator.cxx index 0cddb127cf..a42d65d3de 100644 --- a/Source/cmNinjaUtilityTargetGenerator.cxx +++ b/Source/cmNinjaUtilityTargetGenerator.cxx @@ -164,6 +164,6 @@ void cmNinjaUtilityTargetGenerator::Generate(const std::string& config) cmNinjaBuild phonyAlias("phony"); gg->AppendTargetOutputs(genTarget, phonyAlias.Outputs, ""); phonyAlias.ExplicitDeps = phonyBuild.Outputs; - gg->WriteBuild(this->GetConfigFileStream(config), phonyAlias); + gg->WriteBuild(this->GetImplFileStream(config), phonyAlias); } } diff --git a/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake b/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake index f3208edf3e..7d32b2767f 100644 --- a/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake +++ b/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake @@ -103,6 +103,18 @@ run_ninja(Simple reconfigure-config build-Release.ninja simpleexe) execute_process(COMMAND ${CMAKE_COMMAND} -E sleep 1) file(TOUCH "${RunCMake_TEST_BINARY_DIR}/empty.cmake") run_ninja(Simple reconfigure-noconfig build.ninja simpleexe) +run_ninja(Simple default-build-file-clean build.ninja clean) +run_ninja(Simple default-build-file-clean-minsizerel build.ninja clean:MinSizeRel) +run_ninja(Simple default-build-file-all build.ninja all) + +set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/SimpleDefaultBuildAlias-build) +set(RunCMake_TEST_OPTIONS "-DCMAKE_NINJA_MULTI_DEFAULT_BUILD_TYPE=Release;-DCMAKE_NINJA_MULTI_DEFAULT_BUILD_ALIAS=all;-DCMAKE_NINJA_MULTI_CROSS_CONFIG_ENABLE=ON") +run_cmake_configure(SimpleDefaultBuildAlias) +unset(RunCMake_TEST_OPTIONS) +include(${RunCMake_TEST_BINARY_DIR}/target_files.cmake) +run_ninja(SimpleDefaultBuildAlias target build.ninja simpleexe) +run_ninja(SimpleDefaultBuildAlias all build.ninja all) +run_ninja(SimpleDefaultBuildAlias clean build.ninja clean) set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/SimpleNoCross-build) run_cmake_configure(SimpleNoCross) diff --git a/Tests/RunCMake/NinjaMultiConfig/Simple-default-build-file-all-ninja-check.cmake b/Tests/RunCMake/NinjaMultiConfig/Simple-default-build-file-all-ninja-check.cmake new file mode 100644 index 0000000000..4e6e654417 --- /dev/null +++ b/Tests/RunCMake/NinjaMultiConfig/Simple-default-build-file-all-ninja-check.cmake @@ -0,0 +1,49 @@ +check_files("${RunCMake_TEST_BINARY_DIR}" + INCLUDE + ${GENERATED_FILES} + + ${TARGET_FILE_simpleexe_Debug} + ${TARGET_OBJECT_FILES_simpleexe_Debug} + + ${TARGET_FILE_simpleshared_Debug} + ${TARGET_LINKER_FILE_simpleshared_Debug} + ${TARGET_OBJECT_FILES_simpleshared_Debug} + + ${TARGET_FILE_simplestatic_Debug} + ${TARGET_LINKER_FILE_simplestatic_Debug} + ${TARGET_OBJECT_FILES_simplestatic_Debug} + + ${TARGET_OBJECT_FILES_simpleobj_Debug} + + ${TARGET_FILE_simpleexe_Release} + ${TARGET_OBJECT_FILES_simpleexe_Release} + + ${TARGET_FILE_simpleshared_Release} + ${TARGET_LINKER_FILE_simpleshared_Release} + ${TARGET_OBJECT_FILES_simpleshared_Release} + + ${TARGET_FILE_simplestatic_Release} + ${TARGET_LINKER_FILE_simplestatic_Release} + ${TARGET_OBJECT_FILES_simplestatic_Release} + + ${TARGET_OBJECT_FILES_simpleobj_Release} + + ${TARGET_FILE_simpleexe_RelWithDebInfo} + ${TARGET_OBJECT_FILES_simpleexe_RelWithDebInfo} + + ${TARGET_FILE_simpleshared_RelWithDebInfo} + ${TARGET_LINKER_FILE_simpleshared_RelWithDebInfo} + ${TARGET_OBJECT_FILES_simpleshared_RelWithDebInfo} + + ${TARGET_FILE_simplestatic_RelWithDebInfo} + ${TARGET_LINKER_FILE_simplestatic_RelWithDebInfo} + ${TARGET_OBJECT_FILES_simplestatic_RelWithDebInfo} + + ${TARGET_OBJECT_FILES_simpleobj_RelWithDebInfo} + + EXCLUDE + ${TARGET_OBJECT_FILES_simpleexe_MinSizeRel} + ${TARGET_OBJECT_FILES_simpleshared_MinSizeRel} + ${TARGET_OBJECT_FILES_simplestatic_MinSizeRel} + ${TARGET_OBJECT_FILES_simpleobj_MinSizeRel} + ) diff --git a/Tests/RunCMake/NinjaMultiConfig/Simple-default-build-file-clean-minsizerel-ninja-check.cmake b/Tests/RunCMake/NinjaMultiConfig/Simple-default-build-file-clean-minsizerel-ninja-check.cmake new file mode 100644 index 0000000000..c09ae65b95 --- /dev/null +++ b/Tests/RunCMake/NinjaMultiConfig/Simple-default-build-file-clean-minsizerel-ninja-check.cmake @@ -0,0 +1,41 @@ +check_files("${RunCMake_TEST_BINARY_DIR}" + INCLUDE + ${GENERATED_FILES} + + ${TARGET_FILE_simpleexe_Debug} + ${TARGET_OBJECT_FILES_simpleexe_Debug} + + ${TARGET_FILE_simpleshared_Debug} + ${TARGET_LINKER_FILE_simpleshared_Debug} + ${TARGET_OBJECT_FILES_simpleshared_Debug} + + ${TARGET_FILE_simplestatic_Debug} + ${TARGET_LINKER_FILE_simplestatic_Debug} + ${TARGET_OBJECT_FILES_simplestatic_Debug} + + ${TARGET_OBJECT_FILES_simpleobj_Debug} + + ${TARGET_FILE_simpleexe_Release} + ${TARGET_OBJECT_FILES_simpleexe_Release} + + ${TARGET_FILE_simpleshared_Release} + ${TARGET_LINKER_FILE_simpleshared_Release} + ${TARGET_OBJECT_FILES_simpleshared_Release} + + ${TARGET_FILE_simplestatic_Release} + ${TARGET_LINKER_FILE_simplestatic_Release} + ${TARGET_OBJECT_FILES_simplestatic_Release} + + ${TARGET_OBJECT_FILES_simpleobj_Release} + + EXCLUDE + ${TARGET_OBJECT_FILES_simpleexe_MinSizeRel} + ${TARGET_OBJECT_FILES_simpleshared_MinSizeRel} + ${TARGET_OBJECT_FILES_simplestatic_MinSizeRel} + ${TARGET_OBJECT_FILES_simpleobj_MinSizeRel} + + ${TARGET_OBJECT_FILES_simpleexe_RelWithDebInfo} + ${TARGET_OBJECT_FILES_simpleshared_RelWithDebInfo} + ${TARGET_OBJECT_FILES_simplestatic_RelWithDebInfo} + ${TARGET_OBJECT_FILES_simpleobj_RelWithDebInfo} + ) diff --git a/Tests/RunCMake/NinjaMultiConfig/Simple-default-build-file-clean-ninja-check.cmake b/Tests/RunCMake/NinjaMultiConfig/Simple-default-build-file-clean-ninja-check.cmake new file mode 100644 index 0000000000..43213dd013 --- /dev/null +++ b/Tests/RunCMake/NinjaMultiConfig/Simple-default-build-file-clean-ninja-check.cmake @@ -0,0 +1,49 @@ +check_files("${RunCMake_TEST_BINARY_DIR}" + INCLUDE + ${GENERATED_FILES} + + ${TARGET_FILE_simpleexe_Debug} + ${TARGET_OBJECT_FILES_simpleexe_Debug} + + ${TARGET_FILE_simpleshared_Debug} + ${TARGET_LINKER_FILE_simpleshared_Debug} + ${TARGET_OBJECT_FILES_simpleshared_Debug} + + ${TARGET_FILE_simplestatic_Debug} + ${TARGET_LINKER_FILE_simplestatic_Debug} + ${TARGET_OBJECT_FILES_simplestatic_Debug} + + ${TARGET_OBJECT_FILES_simpleobj_Debug} + + ${TARGET_FILE_simpleexe_Release} + ${TARGET_OBJECT_FILES_simpleexe_Release} + + ${TARGET_FILE_simpleshared_Release} + ${TARGET_LINKER_FILE_simpleshared_Release} + ${TARGET_OBJECT_FILES_simpleshared_Release} + + ${TARGET_FILE_simplestatic_Release} + ${TARGET_LINKER_FILE_simplestatic_Release} + ${TARGET_OBJECT_FILES_simplestatic_Release} + + ${TARGET_OBJECT_FILES_simpleobj_Release} + + ${TARGET_FILE_simpleexe_MinSizeRel} + ${TARGET_OBJECT_FILES_simpleexe_MinSizeRel} + + ${TARGET_FILE_simpleshared_MinSizeRel} + ${TARGET_LINKER_FILE_simpleshared_MinSizeRel} + ${TARGET_OBJECT_FILES_simpleshared_MinSizeRel} + + ${TARGET_FILE_simplestatic_MinSizeRel} + ${TARGET_LINKER_FILE_simplestatic_MinSizeRel} + ${TARGET_OBJECT_FILES_simplestatic_MinSizeRel} + + ${TARGET_OBJECT_FILES_simpleobj_MinSizeRel} + + EXCLUDE + ${TARGET_OBJECT_FILES_simpleexe_RelWithDebInfo} + ${TARGET_OBJECT_FILES_simpleshared_RelWithDebInfo} + ${TARGET_OBJECT_FILES_simplestatic_RelWithDebInfo} + ${TARGET_OBJECT_FILES_simpleobj_RelWithDebInfo} + ) diff --git a/Tests/RunCMake/NinjaMultiConfig/SimpleDefaultBuildAlias-all-ninja-check.cmake b/Tests/RunCMake/NinjaMultiConfig/SimpleDefaultBuildAlias-all-ninja-check.cmake new file mode 100644 index 0000000000..c171e3d057 --- /dev/null +++ b/Tests/RunCMake/NinjaMultiConfig/SimpleDefaultBuildAlias-all-ninja-check.cmake @@ -0,0 +1,56 @@ +check_files("${RunCMake_TEST_BINARY_DIR}" + INCLUDE + ${GENERATED_FILES} + + ${TARGET_FILE_simpleexe_Debug} + ${TARGET_OBJECT_FILES_simpleexe_Debug} + + ${TARGET_FILE_simpleshared_Debug} + ${TARGET_LINKER_FILE_simpleshared_Debug} + ${TARGET_OBJECT_FILES_simpleshared_Debug} + + ${TARGET_FILE_simplestatic_Debug} + ${TARGET_LINKER_FILE_simplestatic_Debug} + ${TARGET_OBJECT_FILES_simplestatic_Debug} + + ${TARGET_OBJECT_FILES_simpleobj_Debug} + + ${TARGET_FILE_simpleexe_Release} + ${TARGET_OBJECT_FILES_simpleexe_Release} + + ${TARGET_FILE_simpleshared_Release} + ${TARGET_LINKER_FILE_simpleshared_Release} + ${TARGET_OBJECT_FILES_simpleshared_Release} + + ${TARGET_FILE_simplestatic_Release} + ${TARGET_LINKER_FILE_simplestatic_Release} + ${TARGET_OBJECT_FILES_simplestatic_Release} + + ${TARGET_OBJECT_FILES_simpleobj_Release} + + ${TARGET_FILE_simpleexe_MinSizeRel} + ${TARGET_OBJECT_FILES_simpleexe_MinSizeRel} + + ${TARGET_FILE_simpleshared_MinSizeRel} + ${TARGET_LINKER_FILE_simpleshared_MinSizeRel} + ${TARGET_OBJECT_FILES_simpleshared_MinSizeRel} + + ${TARGET_FILE_simplestatic_MinSizeRel} + ${TARGET_LINKER_FILE_simplestatic_MinSizeRel} + ${TARGET_OBJECT_FILES_simplestatic_MinSizeRel} + + ${TARGET_OBJECT_FILES_simpleobj_MinSizeRel} + + ${TARGET_FILE_simpleexe_RelWithDebInfo} + ${TARGET_OBJECT_FILES_simpleexe_RelWithDebInfo} + + ${TARGET_FILE_simpleshared_RelWithDebInfo} + ${TARGET_LINKER_FILE_simpleshared_RelWithDebInfo} + ${TARGET_OBJECT_FILES_simpleshared_RelWithDebInfo} + + ${TARGET_FILE_simplestatic_RelWithDebInfo} + ${TARGET_LINKER_FILE_simplestatic_RelWithDebInfo} + ${TARGET_OBJECT_FILES_simplestatic_RelWithDebInfo} + + ${TARGET_OBJECT_FILES_simpleobj_RelWithDebInfo} + ) diff --git a/Tests/RunCMake/NinjaMultiConfig/SimpleDefaultBuildAlias-clean-ninja-check.cmake b/Tests/RunCMake/NinjaMultiConfig/SimpleDefaultBuildAlias-clean-ninja-check.cmake new file mode 100644 index 0000000000..0f919dfe01 --- /dev/null +++ b/Tests/RunCMake/NinjaMultiConfig/SimpleDefaultBuildAlias-clean-ninja-check.cmake @@ -0,0 +1,25 @@ +check_files("${RunCMake_TEST_BINARY_DIR}" + INCLUDE + ${GENERATED_FILES} + + EXCLUDE + ${TARGET_OBJECT_FILES_simpleexe_Debug} + ${TARGET_OBJECT_FILES_simpleshared_Debug} + ${TARGET_OBJECT_FILES_simplestatic_Debug} + ${TARGET_OBJECT_FILES_simpleobj_Debug} + + ${TARGET_OBJECT_FILES_simpleexe_Release} + ${TARGET_OBJECT_FILES_simpleshared_Release} + ${TARGET_OBJECT_FILES_simplestatic_Release} + ${TARGET_OBJECT_FILES_simpleobj_Release} + + ${TARGET_OBJECT_FILES_simpleexe_MinSizeRel} + ${TARGET_OBJECT_FILES_simpleshared_MinSizeRel} + ${TARGET_OBJECT_FILES_simplestatic_MinSizeRel} + ${TARGET_OBJECT_FILES_simpleobj_MinSizeRel} + + ${TARGET_OBJECT_FILES_simpleexe_RelWithDebInfo} + ${TARGET_OBJECT_FILES_simpleshared_RelWithDebInfo} + ${TARGET_OBJECT_FILES_simplestatic_RelWithDebInfo} + ${TARGET_OBJECT_FILES_simpleobj_RelWithDebInfo} + ) diff --git a/Tests/RunCMake/NinjaMultiConfig/SimpleDefaultBuildAlias-target-ninja-check.cmake b/Tests/RunCMake/NinjaMultiConfig/SimpleDefaultBuildAlias-target-ninja-check.cmake new file mode 100644 index 0000000000..de4505ccc0 --- /dev/null +++ b/Tests/RunCMake/NinjaMultiConfig/SimpleDefaultBuildAlias-target-ninja-check.cmake @@ -0,0 +1,49 @@ +check_files("${RunCMake_TEST_BINARY_DIR}" + INCLUDE + ${GENERATED_FILES} + + ${TARGET_FILE_simpleexe_Debug} + ${TARGET_OBJECT_FILES_simpleexe_Debug} + + ${TARGET_FILE_simpleshared_Debug} + ${TARGET_LINKER_FILE_simpleshared_Debug} + ${TARGET_OBJECT_FILES_simpleshared_Debug} + + ${TARGET_OBJECT_FILES_simpleobj_Debug} + + ${TARGET_FILE_simpleexe_Release} + ${TARGET_OBJECT_FILES_simpleexe_Release} + + ${TARGET_FILE_simpleshared_Release} + ${TARGET_LINKER_FILE_simpleshared_Release} + ${TARGET_OBJECT_FILES_simpleshared_Release} + + ${TARGET_OBJECT_FILES_simpleobj_Release} + + ${TARGET_FILE_simpleexe_MinSizeRel} + ${TARGET_OBJECT_FILES_simpleexe_MinSizeRel} + + ${TARGET_FILE_simpleshared_MinSizeRel} + ${TARGET_LINKER_FILE_simpleshared_MinSizeRel} + ${TARGET_OBJECT_FILES_simpleshared_MinSizeRel} + + ${TARGET_OBJECT_FILES_simpleobj_MinSizeRel} + + ${TARGET_FILE_simpleexe_RelWithDebInfo} + ${TARGET_OBJECT_FILES_simpleexe_RelWithDebInfo} + + ${TARGET_FILE_simpleshared_RelWithDebInfo} + ${TARGET_LINKER_FILE_simpleshared_RelWithDebInfo} + ${TARGET_OBJECT_FILES_simpleshared_RelWithDebInfo} + + ${TARGET_OBJECT_FILES_simpleobj_RelWithDebInfo} + + EXCLUDE + ${TARGET_OBJECT_FILES_simplestatic_Debug} + + ${TARGET_OBJECT_FILES_simplestatic_Release} + + ${TARGET_OBJECT_FILES_simplestatic_MinSizeRel} + + ${TARGET_OBJECT_FILES_simplestatic_RelWithDebInfo} + ) diff --git a/Tests/RunCMake/NinjaMultiConfig/SimpleDefaultBuildAlias.cmake b/Tests/RunCMake/NinjaMultiConfig/SimpleDefaultBuildAlias.cmake new file mode 100644 index 0000000000..2a5b708621 --- /dev/null +++ b/Tests/RunCMake/NinjaMultiConfig/SimpleDefaultBuildAlias.cmake @@ -0,0 +1 @@ +include("${CMAKE_CURRENT_SOURCE_DIR}/Simple.cmake")