diff --git a/Help/policy/DISALLOWED_COMMAND.txt b/Help/policy/DISALLOWED_COMMAND.txt new file mode 100644 index 000000000..36280d2b6 --- /dev/null +++ b/Help/policy/DISALLOWED_COMMAND.txt @@ -0,0 +1,9 @@ +CMake >= |disallowed_version| prefer that this command never be called. +The OLD behavior for this policy is to allow the command to be called. +The NEW behavior for this policy is to issue a FATAL_ERROR when the +command is called. + +This policy was introduced in CMake version |disallowed_version|. +CMake version |release| warns when the policy is not set and uses +OLD behavior. Use the cmake_policy command to set it to OLD or +NEW explicitly. diff --git a/Source/cmCommand.h b/Source/cmCommand.h index 83184a0e4..e1488571f 100644 --- a/Source/cmCommand.h +++ b/Source/cmCommand.h @@ -173,6 +173,25 @@ public: this->Error += e; } + /** Check if the command is disallowed by a policy. */ + bool Disallowed(cmPolicies::PolicyID pol, const char* e) + { + switch(this->Makefile->GetPolicyStatus(pol)) + { + case cmPolicies::WARN: + this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, + this->Makefile->GetPolicies()->GetPolicyWarning(pol)); + case cmPolicies::OLD: + return false; + case cmPolicies::REQUIRED_IF_USED: + case cmPolicies::REQUIRED_ALWAYS: + case cmPolicies::NEW: + this->Makefile->IssueMessage(cmake::FATAL_ERROR, e); + break; + } + return true; + } + protected: cmMakefile* Makefile; cmCommandArgumentsHelper Helper; diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 3a0ea9186..8148cb693 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -61,6 +61,7 @@ if(UNIX AND "${CMAKE_TEST_GENERATOR}" MATCHES "Unix Makefiles") add_RunCMake_test(CompilerChange) endif() add_RunCMake_test(Configure) +add_RunCMake_test(DisallowedCommands) add_RunCMake_test(ExternalData) add_RunCMake_test(FPHSA) add_RunCMake_test(GeneratorExpression) diff --git a/Tests/RunCMake/DisallowedCommands/CMakeLists.txt b/Tests/RunCMake/DisallowedCommands/CMakeLists.txt new file mode 100644 index 000000000..e8db6b05b --- /dev/null +++ b/Tests/RunCMake/DisallowedCommands/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8) +project(${RunCMake_TEST} NONE) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/DisallowedCommands/RunCMakeTest.cmake b/Tests/RunCMake/DisallowedCommands/RunCMakeTest.cmake new file mode 100644 index 000000000..5f26857c5 --- /dev/null +++ b/Tests/RunCMake/DisallowedCommands/RunCMakeTest.cmake @@ -0,0 +1,8 @@ +include(RunCMake) + +foreach(p + ) + run_cmake(${p}-WARN) + run_cmake(${p}-OLD) + run_cmake(${p}-NEW) +endforeach()