summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKyle Edwards <kyle.edwards@kitware.com>2020-02-26 22:19:47 (GMT)
committerKyle Edwards <kyle.edwards@kitware.com>2020-02-27 15:39:35 (GMT)
commitc794b70f194bcff6f06971767f18473da13950e3 (patch)
tree10882364d6d53229428bf2448ef25daf1325c75d
parent9590c3a400cc16882fee860818cfdcca82e17a37 (diff)
downloadCMake-c794b70f194bcff6f06971767f18473da13950e3.zip
CMake-c794b70f194bcff6f06971767f18473da13950e3.tar.gz
CMake-c794b70f194bcff6f06971767f18473da13950e3.tar.bz2
Ninja Multi-Config: Always generate build.ninja
If CMAKE_DEFAULT_BUILD_TYPE is not specified, use the first item from CMAKE_CONFIGURATION_TYPES instead.
-rw-r--r--Help/generator/Ninja Multi-Config.rst15
-rw-r--r--Source/cmGlobalNinjaGenerator.cxx12
-rw-r--r--Tests/RunCMake/NinjaMultiConfig/InvalidDefaultConfigsNoDefaultFile-result.txt1
-rw-r--r--Tests/RunCMake/NinjaMultiConfig/InvalidDefaultConfigsNoDefaultFile-stderr.txt6
-rw-r--r--Tests/RunCMake/NinjaMultiConfig/InvalidDefaultConfigsNoDefaultFile.cmake0
-rw-r--r--Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake8
6 files changed, 16 insertions, 26 deletions
diff --git a/Help/generator/Ninja Multi-Config.rst b/Help/generator/Ninja Multi-Config.rst
index c2331f0..1f68535 100644
--- a/Help/generator/Ninja Multi-Config.rst
+++ b/Help/generator/Ninja Multi-Config.rst
@@ -12,9 +12,10 @@ multiple configurations at once with :variable:`CMAKE_CONFIGURATION_TYPES`
instead of only one configuration with :variable:`CMAKE_BUILD_TYPE`. One
``build-<Config>.ninja`` file will be generated for each of these
configurations (with ``<Config>`` being the configuration name.) These files
-are intended to be run with ``ninja -f build-<Config>.ninja``. No
-``build.ninja`` file is generated by default (see below for how to generate
-it.)
+are intended to be run with ``ninja -f build-<Config>.ninja``. A
+``build.ninja`` file is also generated, using the configuration from either
+:variable:`CMAKE_DEFAULT_BUILD_TYPE` or the first item from
+:variable:`CMAKE_CONFIGURATION_TYPES`.
``cmake --build . --config <Config>`` will always use ``build-<Config>.ninja``
to build. If no ``--config`` argument is specified, ``cmake --build .`` will
@@ -51,10 +52,10 @@ The ``Ninja Multi-Config`` generator recognizes the following variables:
:variable:`CMAKE_DEFAULT_BUILD_TYPE`
Specifies the configuration to use by default in a ``build.ninja`` file. If
- this variable is specified, a ``build.ninja`` file is generated which uses
- build rules from ``build-<Config>.ninja`` by default. All custom commands are
- executed with this configuration. If the variable is not specified, no
- ``build.ninja`` file is generated.
+ this variable is specified, ``build.ninja`` uses build rules from
+ ``build-<Config>.ninja`` by default. All custom commands are executed with
+ this configuration. If the variable is not specified, the first item from
+ :variable:`CMAKE_CONFIGURATION_TYPES` is used instead.
The value of this variable must be one of the items from
:variable:`CMAKE_CONFIGURATION_TYPES`.
diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx
index 27c28fe..5243c36 100644
--- a/Source/cmGlobalNinjaGenerator.cxx
+++ b/Source/cmGlobalNinjaGenerator.cxx
@@ -2488,8 +2488,7 @@ bool cmGlobalNinjaMultiGenerator::OpenBuildFileStreams()
return false;
}
*this->DefaultFileStream
- << "# This file is a convenience file generated by\n"
- << "# CMAKE_DEFAULT_BUILD_TYPE.\n\n"
+ << "# Build using rules for '" << this->DefaultFileConfig << "'.\n\n"
<< "include " << GetNinjaImplFilename(this->DefaultFileConfig) << "\n\n";
}
@@ -2606,9 +2605,6 @@ bool cmGlobalNinjaMultiGenerator::InspectConfigTypeVariables()
std::string cmGlobalNinjaMultiGenerator::GetDefaultBuildConfig() const
{
- if (this->DefaultFileConfig.empty()) {
- return "Debug";
- }
return "";
}
@@ -2625,8 +2621,10 @@ bool cmGlobalNinjaMultiGenerator::ReadCacheEntriesForBuild(
this->DefaultFileConfig =
state.GetSafeCacheEntryValue("CMAKE_DEFAULT_BUILD_TYPE");
- if (!this->DefaultFileConfig.empty() &&
- !configs.count(this->DefaultFileConfig)) {
+ if (this->DefaultFileConfig.empty()) {
+ this->DefaultFileConfig = configsVec.front();
+ }
+ if (!configs.count(this->DefaultFileConfig)) {
std::ostringstream msg;
msg << "The configuration specified by "
<< "CMAKE_DEFAULT_BUILD_TYPE (" << this->DefaultFileConfig
diff --git a/Tests/RunCMake/NinjaMultiConfig/InvalidDefaultConfigsNoDefaultFile-result.txt b/Tests/RunCMake/NinjaMultiConfig/InvalidDefaultConfigsNoDefaultFile-result.txt
deleted file mode 100644
index d00491f..0000000
--- a/Tests/RunCMake/NinjaMultiConfig/InvalidDefaultConfigsNoDefaultFile-result.txt
+++ /dev/null
@@ -1 +0,0 @@
-1
diff --git a/Tests/RunCMake/NinjaMultiConfig/InvalidDefaultConfigsNoDefaultFile-stderr.txt b/Tests/RunCMake/NinjaMultiConfig/InvalidDefaultConfigsNoDefaultFile-stderr.txt
deleted file mode 100644
index 5d090a0..0000000
--- a/Tests/RunCMake/NinjaMultiConfig/InvalidDefaultConfigsNoDefaultFile-stderr.txt
+++ /dev/null
@@ -1,6 +0,0 @@
-^CMake Error:
- CMAKE_DEFAULT_CONFIGS cannot be used without CMAKE_DEFAULT_BUILD_TYPE or
- CMAKE_CROSS_CONFIGS
-
-
-CMake Generate step failed\. Build files cannot be regenerated correctly\.$
diff --git a/Tests/RunCMake/NinjaMultiConfig/InvalidDefaultConfigsNoDefaultFile.cmake b/Tests/RunCMake/NinjaMultiConfig/InvalidDefaultConfigsNoDefaultFile.cmake
deleted file mode 100644
index e69de29..0000000
--- a/Tests/RunCMake/NinjaMultiConfig/InvalidDefaultConfigsNoDefaultFile.cmake
+++ /dev/null
diff --git a/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake b/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake
index bed7531..b07b4f7 100644
--- a/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake
+++ b/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake
@@ -81,7 +81,9 @@ endfunction()
set(RunCMake_TEST_NO_CLEAN 1)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/Simple-build)
-set(RunCMake_TEST_OPTIONS "-DCMAKE_CONFIGURATION_TYPES=Debug\\;Release\\;MinSizeRel\\;RelWithDebInfo;-DCMAKE_DEFAULT_BUILD_TYPE=RelWithDebInfo;-DCMAKE_CROSS_CONFIGS=all")
+# IMPORTANT: Setting RelWithDebInfo as the first item in CMAKE_CONFIGURATION_TYPES
+# generates a build.ninja file with that configuration
+set(RunCMake_TEST_OPTIONS "-DCMAKE_CONFIGURATION_TYPES=RelWithDebInfo\\;Debug\\;Release\\;MinSizeRel;-DCMAKE_CROSS_CONFIGS=all")
run_cmake_configure(Simple)
unset(RunCMake_TEST_OPTIONS)
include(${RunCMake_TEST_BINARY_DIR}/target_files.cmake)
@@ -153,10 +155,6 @@ set(RunCMake_TEST_OPTIONS "-DCMAKE_CROSS_CONFIGS=Debug\\;Release;-DCMAKE_DEFAULT
run_cmake(InvalidDefaultConfigsCross)
unset(RunCMake_TEST_OPTIONS)
-set(RunCMake_TEST_OPTIONS "-DCMAKE_CROSS_CONFIGS=Debug\\;Release;-DCMAKE_DEFAULT_CONFIGS=all")
-run_cmake(InvalidDefaultConfigsNoDefaultFile)
-unset(RunCMake_TEST_OPTIONS)
-
set(RunCMake_TEST_OPTIONS "-DCMAKE_DEFAULT_BUILD_TYPE=Release;-DCMAKE_DEFAULT_CONFIGS=all")
run_cmake(InvalidDefaultConfigsNoCross)
unset(RunCMake_TEST_OPTIONS)