From c794b70f194bcff6f06971767f18473da13950e3 Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Wed, 26 Feb 2020 17:19:47 -0500 Subject: Ninja Multi-Config: Always generate build.ninja If CMAKE_DEFAULT_BUILD_TYPE is not specified, use the first item from CMAKE_CONFIGURATION_TYPES instead. --- Help/generator/Ninja Multi-Config.rst | 15 ++++++++------- Source/cmGlobalNinjaGenerator.cxx | 12 +++++------- .../InvalidDefaultConfigsNoDefaultFile-result.txt | 1 - .../InvalidDefaultConfigsNoDefaultFile-stderr.txt | 6 ------ .../InvalidDefaultConfigsNoDefaultFile.cmake | 0 Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake | 8 +++----- 6 files changed, 16 insertions(+), 26 deletions(-) delete mode 100644 Tests/RunCMake/NinjaMultiConfig/InvalidDefaultConfigsNoDefaultFile-result.txt delete mode 100644 Tests/RunCMake/NinjaMultiConfig/InvalidDefaultConfigsNoDefaultFile-stderr.txt delete mode 100644 Tests/RunCMake/NinjaMultiConfig/InvalidDefaultConfigsNoDefaultFile.cmake 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-.ninja`` file will be generated for each of these configurations (with ```` being the configuration name.) These files -are intended to be run with ``ninja -f build-.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-.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 `` will always use ``build-.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-.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-.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 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) -- cgit v0.12