mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-07 22:30:13 -06:00
Ninja Multi-Config: Add variable to control aliases in build.ninja
This commit is contained in:
@@ -78,4 +78,13 @@ targets built with the generated code.
|
|||||||
As a convenience, ``Ninja Multi-Config`` offers a
|
As a convenience, ``Ninja Multi-Config`` offers a
|
||||||
:variable:`CMAKE_NINJA_MULTI_DEFAULT_BUILD_TYPE` setting. If this variable is
|
: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, a ``build.ninja`` file will be generated which points to the
|
||||||
specified ``build-<Config>.ninja`` file.
|
specified ``build-<Config>.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 ``<target>`` 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 ``<target>`` aliases in ``build.ninja`` will resolve to ``<target>:Debug``
|
||||||
|
or ``<target>:all``, but custom commands will still use the ``Release``
|
||||||
|
configuration.
|
||||||
|
|||||||
@@ -425,6 +425,7 @@ Variables that Control the Build
|
|||||||
/variable/CMAKE_MSVCIDE_RUN_PATH
|
/variable/CMAKE_MSVCIDE_RUN_PATH
|
||||||
/variable/CMAKE_MSVC_RUNTIME_LIBRARY
|
/variable/CMAKE_MSVC_RUNTIME_LIBRARY
|
||||||
/variable/CMAKE_NINJA_MULTI_CROSS_CONFIG_ENABLE
|
/variable/CMAKE_NINJA_MULTI_CROSS_CONFIG_ENABLE
|
||||||
|
/variable/CMAKE_NINJA_MULTI_DEFAULT_BUILD_ALIAS
|
||||||
/variable/CMAKE_NINJA_MULTI_DEFAULT_BUILD_TYPE
|
/variable/CMAKE_NINJA_MULTI_DEFAULT_BUILD_TYPE
|
||||||
/variable/CMAKE_NINJA_OUTPUT_PATH_PREFIX
|
/variable/CMAKE_NINJA_OUTPUT_PATH_PREFIX
|
||||||
/variable/CMAKE_NO_BUILTIN_CHRPATH
|
/variable/CMAKE_NO_BUILTIN_CHRPATH
|
||||||
|
|||||||
6
Help/variable/CMAKE_NINJA_MULTI_DEFAULT_BUILD_ALIAS.rst
Normal file
6
Help/variable/CMAKE_NINJA_MULTI_DEFAULT_BUILD_ALIAS.rst
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
CMAKE_NINJA_MULTI_DEFAULT_BUILD_ALIAS
|
||||||
|
-------------------------------------
|
||||||
|
|
||||||
|
Controls the config of ``<target>`` aliases in ``build.ninja`` for the
|
||||||
|
:generator:`Ninja Multi-Config` generator. See the generator's documentation
|
||||||
|
for more details.
|
||||||
@@ -1161,14 +1161,11 @@ void cmGlobalNinjaGenerator::AddTargetAlias(const std::string& alias,
|
|||||||
newAliasGlobal.first->second.GeneratorTarget != target) {
|
newAliasGlobal.first->second.GeneratorTarget != target) {
|
||||||
newAliasGlobal.first->second.GeneratorTarget = nullptr;
|
newAliasGlobal.first->second.GeneratorTarget = nullptr;
|
||||||
}
|
}
|
||||||
if (config != "all") {
|
std::pair<TargetAliasMap::iterator, bool> newAliasConfig =
|
||||||
std::pair<TargetAliasMap::iterator, bool> newAliasConfig =
|
this->Configs[config].TargetAliases.insert(std::make_pair(outputPath, ta));
|
||||||
this->Configs[config].TargetAliases.insert(
|
if (newAliasConfig.second &&
|
||||||
std::make_pair(outputPath, ta));
|
newAliasConfig.first->second.GeneratorTarget != target) {
|
||||||
if (newAliasConfig.second &&
|
newAliasConfig.first->second.GeneratorTarget = nullptr;
|
||||||
newAliasConfig.first->second.GeneratorTarget != target) {
|
|
||||||
newAliasConfig.first->second.GeneratorTarget = nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1231,7 +1228,7 @@ void cmGlobalNinjaGenerator::WriteTargetAliases(std::ostream& os)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto const* defaultConfig = this->GetDefaultBuildType();
|
auto const* defaultConfig = this->GetDefaultBuildAlias();
|
||||||
if (defaultConfig) {
|
if (defaultConfig) {
|
||||||
std::string config = defaultConfig;
|
std::string config = defaultConfig;
|
||||||
for (auto const& ta : this->Configs[config].TargetAliases) {
|
for (auto const& ta : this->Configs[config].TargetAliases) {
|
||||||
@@ -1248,8 +1245,16 @@ void cmGlobalNinjaGenerator::WriteTargetAliases(std::ostream& os)
|
|||||||
|
|
||||||
build.Outputs.front() = ta.first;
|
build.Outputs.front() = ta.first;
|
||||||
build.ExplicitDeps.clear();
|
build.ExplicitDeps.clear();
|
||||||
this->AppendTargetOutputs(ta.second.GeneratorTarget,
|
if (config == "all") {
|
||||||
build.ExplicitDeps, config);
|
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);
|
this->WriteBuild(*this->GetDefaultFileStream(), build);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1311,7 +1316,7 @@ void cmGlobalNinjaGenerator::WriteFolderTargets(std::ostream& os)
|
|||||||
this->WriteBuild(*this->GetConfigFileStream(config), build);
|
this->WriteBuild(*this->GetConfigFileStream(config), build);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto const* defaultConfig = this->GetDefaultBuildType();
|
auto const* defaultConfig = this->GetDefaultBuildAlias();
|
||||||
if (defaultConfig) {
|
if (defaultConfig) {
|
||||||
std::string config = defaultConfig;
|
std::string config = defaultConfig;
|
||||||
build.ExplicitDeps = { this->BuildAlias(
|
build.ExplicitDeps = { this->BuildAlias(
|
||||||
@@ -1807,7 +1812,7 @@ void cmGlobalNinjaGenerator::WriteTargetClean(std::ostream& os)
|
|||||||
this->WriteBuild(*this->GetConfigFileStream(config), build);
|
this->WriteBuild(*this->GetConfigFileStream(config), build);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto const* defaultConfig = this->GetDefaultBuildType();
|
auto const* defaultConfig = this->GetDefaultBuildAlias();
|
||||||
if (defaultConfig) {
|
if (defaultConfig) {
|
||||||
std::string config = defaultConfig;
|
std::string config = defaultConfig;
|
||||||
build.ExplicitDeps.front() = this->BuildAlias(
|
build.ExplicitDeps.front() = this->BuildAlias(
|
||||||
@@ -2507,3 +2512,16 @@ const char* cmGlobalNinjaMultiGenerator::GetDefaultBuildType() const
|
|||||||
return this->Makefiles.front()->GetDefinition(
|
return this->Makefiles.front()->GetDefinition(
|
||||||
"CMAKE_NINJA_MULTI_DEFAULT_BUILD_TYPE");
|
"CMAKE_NINJA_MULTI_DEFAULT_BUILD_TYPE");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return this->GetDefaultBuildType();
|
||||||
|
}
|
||||||
|
|||||||
@@ -410,6 +410,8 @@ public:
|
|||||||
|
|
||||||
virtual const char* GetDefaultBuildType() const { return nullptr; }
|
virtual const char* GetDefaultBuildType() const { return nullptr; }
|
||||||
|
|
||||||
|
virtual const char* GetDefaultBuildAlias() const { return nullptr; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void Generate() override;
|
void Generate() override;
|
||||||
|
|
||||||
@@ -619,6 +621,8 @@ public:
|
|||||||
|
|
||||||
const char* GetDefaultBuildType() const override;
|
const char* GetDefaultBuildType() const override;
|
||||||
|
|
||||||
|
const char* GetDefaultBuildAlias() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool OpenBuildFileStreams() override;
|
bool OpenBuildFileStreams() override;
|
||||||
void CloseBuildFileStreams() override;
|
void CloseBuildFileStreams() override;
|
||||||
|
|||||||
@@ -107,6 +107,15 @@ 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-clean-minsizerel build.ninja clean:MinSizeRel)
|
||||||
run_ninja(Simple default-build-file-all build.ninja all)
|
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)
|
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/SimpleNoCross-build)
|
||||||
run_cmake_configure(SimpleNoCross)
|
run_cmake_configure(SimpleNoCross)
|
||||||
include(${RunCMake_TEST_BINARY_DIR}/target_files.cmake)
|
include(${RunCMake_TEST_BINARY_DIR}/target_files.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}
|
||||||
|
)
|
||||||
@@ -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}
|
||||||
|
)
|
||||||
@@ -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}
|
||||||
|
)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
include("${CMAKE_CURRENT_SOURCE_DIR}/Simple.cmake")
|
||||||
Reference in New Issue
Block a user