From 9590c3a400cc16882fee860818cfdcca82e17a37 Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Wed, 26 Feb 2020 16:37:30 -0500 Subject: Generator: Don't allow Ninja Multi-Config variables on other generators We may want to enable these variables later on with specific semantics. To avoid breaking backwards compatibility, make it an error to use them for now. --- Source/cmGlobalGenerator.cxx | 35 ++++++++++++++++++++++ Source/cmGlobalGenerator.h | 7 +++++ Source/cmGlobalNinjaGenerator.h | 4 +++ .../Configure/NoCMAKE_CROSS_CONFIGS-result.txt | 1 + .../Configure/NoCMAKE_CROSS_CONFIGS-stderr.txt | 11 +++++++ .../RunCMake/Configure/NoCMAKE_CROSS_CONFIGS.cmake | 1 + .../NoCMAKE_DEFAULT_BUILD_TYPE-result.txt | 1 + .../NoCMAKE_DEFAULT_BUILD_TYPE-stderr.txt | 11 +++++++ .../Configure/NoCMAKE_DEFAULT_BUILD_TYPE.cmake | 1 + .../Configure/NoCMAKE_DEFAULT_CONFIGS-result.txt | 1 + .../Configure/NoCMAKE_DEFAULT_CONFIGS-stderr.txt | 11 +++++++ .../Configure/NoCMAKE_DEFAULT_CONFIGS.cmake | 1 + Tests/RunCMake/Configure/RunCMakeTest.cmake | 6 ++++ 13 files changed, 91 insertions(+) create mode 100644 Tests/RunCMake/Configure/NoCMAKE_CROSS_CONFIGS-result.txt create mode 100644 Tests/RunCMake/Configure/NoCMAKE_CROSS_CONFIGS-stderr.txt create mode 100644 Tests/RunCMake/Configure/NoCMAKE_CROSS_CONFIGS.cmake create mode 100644 Tests/RunCMake/Configure/NoCMAKE_DEFAULT_BUILD_TYPE-result.txt create mode 100644 Tests/RunCMake/Configure/NoCMAKE_DEFAULT_BUILD_TYPE-stderr.txt create mode 100644 Tests/RunCMake/Configure/NoCMAKE_DEFAULT_BUILD_TYPE.cmake create mode 100644 Tests/RunCMake/Configure/NoCMAKE_DEFAULT_CONFIGS-result.txt create mode 100644 Tests/RunCMake/Configure/NoCMAKE_DEFAULT_CONFIGS-stderr.txt create mode 100644 Tests/RunCMake/Configure/NoCMAKE_DEFAULT_CONFIGS.cmake diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index ff6ad9d..0404715 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -1361,8 +1361,43 @@ void cmGlobalGenerator::ComputeBuildFileGenerators() } } +bool cmGlobalGenerator::UnsupportedVariableIsDefined(const std::string& name, + bool supported) const +{ + if (!supported && this->Makefiles.front()->GetDefinition(name)) { + std::ostringstream e; + /* clang-format off */ + e << + "Generator\n" + " " << this->GetName() << "\n" + "does not support variable\n" + " " << name << "\n" + "but it has been specified." + ; + /* clang-format on */ + this->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR, e.str()); + return true; + } + + return false; +} + bool cmGlobalGenerator::Compute() { + // Make sure unsupported variables are not used. + if (this->UnsupportedVariableIsDefined("CMAKE_DEFAULT_BUILD_TYPE", + this->SupportsDefaultBuildType())) { + return false; + } + if (this->UnsupportedVariableIsDefined("CMAKE_CROSS_CONFIGS", + this->SupportsCrossConfigs())) { + return false; + } + if (this->UnsupportedVariableIsDefined("CMAKE_DEFAULT_CONFIGS", + this->SupportsDefaultConfigs())) { + return false; + } + // Some generators track files replaced during the Generate. // Start with an empty vector: this->FilesReplacedDuringGenerate.clear(); diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index 0e7e03d..ba997b2 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -455,6 +455,10 @@ public: /** Generate an .rule file path for a given command output. */ virtual std::string GenerateRuleFile(std::string const& output) const; + virtual bool SupportsDefaultBuildType() const { return false; } + virtual bool SupportsCrossConfigs() const { return false; } + virtual bool SupportsDefaultConfigs() const { return false; } + static std::string EscapeJSON(const std::string& s); void ProcessEvaluationFiles(); @@ -674,6 +678,9 @@ private: virtual const char* GetBuildIgnoreErrorsFlag() const { return nullptr; } + bool UnsupportedVariableIsDefined(const std::string& name, + bool supported) const; + // Cache directory content and target files to be built. struct DirectoryContent { diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h index 3db8356..5668dd1 100644 --- a/Source/cmGlobalNinjaGenerator.h +++ b/Source/cmGlobalNinjaGenerator.h @@ -640,6 +640,10 @@ public: bool ReadCacheEntriesForBuild(const cmState& state) override; + bool SupportsDefaultBuildType() const override { return true; } + bool SupportsCrossConfigs() const override { return true; } + bool SupportsDefaultConfigs() const override { return true; } + protected: bool OpenBuildFileStreams() override; void CloseBuildFileStreams() override; diff --git a/Tests/RunCMake/Configure/NoCMAKE_CROSS_CONFIGS-result.txt b/Tests/RunCMake/Configure/NoCMAKE_CROSS_CONFIGS-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/Configure/NoCMAKE_CROSS_CONFIGS-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/Configure/NoCMAKE_CROSS_CONFIGS-stderr.txt b/Tests/RunCMake/Configure/NoCMAKE_CROSS_CONFIGS-stderr.txt new file mode 100644 index 0000000..a5d149d --- /dev/null +++ b/Tests/RunCMake/Configure/NoCMAKE_CROSS_CONFIGS-stderr.txt @@ -0,0 +1,11 @@ +^CMake Error: + Generator + + [^ +]* + + does not support variable + + CMAKE_CROSS_CONFIGS + + but it has been specified. diff --git a/Tests/RunCMake/Configure/NoCMAKE_CROSS_CONFIGS.cmake b/Tests/RunCMake/Configure/NoCMAKE_CROSS_CONFIGS.cmake new file mode 100644 index 0000000..75d0c47 --- /dev/null +++ b/Tests/RunCMake/Configure/NoCMAKE_CROSS_CONFIGS.cmake @@ -0,0 +1 @@ +set(CMAKE_CROSS_CONFIGS "") diff --git a/Tests/RunCMake/Configure/NoCMAKE_DEFAULT_BUILD_TYPE-result.txt b/Tests/RunCMake/Configure/NoCMAKE_DEFAULT_BUILD_TYPE-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/Configure/NoCMAKE_DEFAULT_BUILD_TYPE-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/Configure/NoCMAKE_DEFAULT_BUILD_TYPE-stderr.txt b/Tests/RunCMake/Configure/NoCMAKE_DEFAULT_BUILD_TYPE-stderr.txt new file mode 100644 index 0000000..8aa3ed3 --- /dev/null +++ b/Tests/RunCMake/Configure/NoCMAKE_DEFAULT_BUILD_TYPE-stderr.txt @@ -0,0 +1,11 @@ +^CMake Error: + Generator + + [^ +]* + + does not support variable + + CMAKE_DEFAULT_BUILD_TYPE + + but it has been specified. diff --git a/Tests/RunCMake/Configure/NoCMAKE_DEFAULT_BUILD_TYPE.cmake b/Tests/RunCMake/Configure/NoCMAKE_DEFAULT_BUILD_TYPE.cmake new file mode 100644 index 0000000..64c7feb --- /dev/null +++ b/Tests/RunCMake/Configure/NoCMAKE_DEFAULT_BUILD_TYPE.cmake @@ -0,0 +1 @@ +set(CMAKE_DEFAULT_BUILD_TYPE "") diff --git a/Tests/RunCMake/Configure/NoCMAKE_DEFAULT_CONFIGS-result.txt b/Tests/RunCMake/Configure/NoCMAKE_DEFAULT_CONFIGS-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/Configure/NoCMAKE_DEFAULT_CONFIGS-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/Configure/NoCMAKE_DEFAULT_CONFIGS-stderr.txt b/Tests/RunCMake/Configure/NoCMAKE_DEFAULT_CONFIGS-stderr.txt new file mode 100644 index 0000000..040bf4d --- /dev/null +++ b/Tests/RunCMake/Configure/NoCMAKE_DEFAULT_CONFIGS-stderr.txt @@ -0,0 +1,11 @@ +^CMake Error: + Generator + + [^ +]* + + does not support variable + + CMAKE_DEFAULT_CONFIGS + + but it has been specified. diff --git a/Tests/RunCMake/Configure/NoCMAKE_DEFAULT_CONFIGS.cmake b/Tests/RunCMake/Configure/NoCMAKE_DEFAULT_CONFIGS.cmake new file mode 100644 index 0000000..5b65172 --- /dev/null +++ b/Tests/RunCMake/Configure/NoCMAKE_DEFAULT_CONFIGS.cmake @@ -0,0 +1 @@ +set(CMAKE_DEFAULT_CONFIGS "") diff --git a/Tests/RunCMake/Configure/RunCMakeTest.cmake b/Tests/RunCMake/Configure/RunCMakeTest.cmake index 76d843c..9fd4499 100644 --- a/Tests/RunCMake/Configure/RunCMakeTest.cmake +++ b/Tests/RunCMake/Configure/RunCMakeTest.cmake @@ -50,3 +50,9 @@ file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") run_cmake(RemoveCache) file(REMOVE "${RunCMake_TEST_BINARY_DIR}/CMakeCache.txt") run_cmake(RemoveCache) + +if(NOT RunCMake_GENERATOR MATCHES "^Ninja Multi-Config$") + run_cmake(NoCMAKE_CROSS_CONFIGS) + run_cmake(NoCMAKE_DEFAULT_BUILD_TYPE) + run_cmake(NoCMAKE_DEFAULT_CONFIGS) +endif() -- cgit v0.12