diff --git a/Help/policy/CMP0040.rst b/Help/policy/CMP0040.rst index b6777efaea..7d7bec0a90 100644 --- a/Help/policy/CMP0040.rst +++ b/Help/policy/CMP0040.rst @@ -1,6 +1,9 @@ CMP0040 ------- +.. |REMOVED_IN_CMAKE_VERSION| replace:: 4.0 +.. include:: REMOVED_PROLOGUE.txt + The target in the ``TARGET`` signature of :command:`add_custom_command` must exist and must be defined in the current directory. @@ -14,7 +17,5 @@ an error if the target referenced in :command:`add_custom_command` is unknown or was defined outside the current directory. .. |INTRODUCED_IN_CMAKE_VERSION| replace:: 3.0 -.. |WARNS_OR_DOES_NOT_WARN| replace:: warns -.. include:: STANDARD_ADVICE.txt - -.. include:: DEPRECATED.txt +.. |WARNED_OR_DID_NOT_WARN| replace:: warned +.. include:: REMOVED_EPILOGUE.txt diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 94184a6897..0c33902248 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1066,38 +1066,20 @@ cmTarget* cmMakefile::GetCustomCommandTarget( // Find the target to which to add the custom command. auto ti = this->Targets.find(realTarget); if (ti == this->Targets.end()) { - MessageType messageType = MessageType::AUTHOR_WARNING; - bool issueMessage = false; std::string e; - switch (this->GetPolicyStatus(cmPolicies::CMP0040)) { - case cmPolicies::WARN: - e = cmStrCat(cmPolicies::GetPolicyWarning(cmPolicies::CMP0040), '\n'); - issueMessage = true; - CM_FALLTHROUGH; - case cmPolicies::OLD: - break; - case cmPolicies::NEW: - issueMessage = true; - messageType = MessageType::FATAL_ERROR; - break; - } - - if (issueMessage) { - if (cmTarget const* t = this->FindTargetToUse(target)) { - if (t->IsImported()) { - e += cmStrCat("TARGET '", target, - "' is IMPORTED and does not build here."); - } else { - e += cmStrCat("TARGET '", target, - "' was not created in this directory."); - } + if (cmTarget const* t = this->FindTargetToUse(target)) { + if (t->IsImported()) { + e += cmStrCat("TARGET '", target, + "' is IMPORTED and does not build here."); } else { - e += cmStrCat("No TARGET '", target, - "' has been created in this directory."); + e += + cmStrCat("TARGET '", target, "' was not created in this directory."); } - this->GetCMakeInstance()->IssueMessage(messageType, e, lfbt); + } else { + e += cmStrCat("No TARGET '", target, + "' has been created in this directory."); } - + this->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR, e, lfbt); return nullptr; } diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h index 9db0cc3642..8094552504 100644 --- a/Source/cmPolicies.h +++ b/Source/cmPolicies.h @@ -125,7 +125,7 @@ class cmMakefile; SELECT(POLICY, CMP0040, \ "The target in the TARGET signature of add_custom_command() must " \ "exist and must be defined in the current directory.", \ - 3, 0, 0, WARN) \ + 3, 0, 0, NEW) \ SELECT(POLICY, CMP0041, \ "Error on relative include with generator expression.", 3, 0, 0, \ WARN) \ diff --git a/Tests/RunCMake/CMP0040/CMP0040-NEW-existing-target-result.txt b/Tests/RunCMake/CMP0040/CMP0040-NEW-existing-target-result.txt deleted file mode 100644 index 573541ac97..0000000000 --- a/Tests/RunCMake/CMP0040/CMP0040-NEW-existing-target-result.txt +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/Tests/RunCMake/CMP0040/CMP0040-NEW-existing-target.cmake b/Tests/RunCMake/CMP0040/CMP0040-NEW-existing-target.cmake index 880b1782dd..f0af0239d3 100644 --- a/Tests/RunCMake/CMP0040/CMP0040-NEW-existing-target.cmake +++ b/Tests/RunCMake/CMP0040/CMP0040-NEW-existing-target.cmake @@ -1,5 +1,3 @@ -cmake_policy(SET CMP0040 NEW) - add_library(foobar empty.cpp) add_custom_command(TARGET foobar PRE_BUILD diff --git a/Tests/RunCMake/CMP0040/CMP0040-NEW-missing-target-stderr.txt b/Tests/RunCMake/CMP0040/CMP0040-NEW-missing-target-stderr.txt index 4a1077c7db..d577dc1c1b 100644 --- a/Tests/RunCMake/CMP0040/CMP0040-NEW-missing-target-stderr.txt +++ b/Tests/RunCMake/CMP0040/CMP0040-NEW-missing-target-stderr.txt @@ -1,4 +1,4 @@ -CMake Error at CMP0040-NEW-missing-target.cmake:3 \(add_custom_command\): - No TARGET 'foobar' has been created in this directory. +^CMake Error at CMP0040-NEW-missing-target.cmake:[0-9]+ \(add_custom_command\): + No TARGET 'foobar' has been created in this directory\. Call Stack \(most recent call first\): - CMakeLists.txt:3 \(include\) + CMakeLists\.txt:3 \(include\)$ diff --git a/Tests/RunCMake/CMP0040/CMP0040-NEW-missing-target.cmake b/Tests/RunCMake/CMP0040/CMP0040-NEW-missing-target.cmake index a9f764cb6b..e3fdbb2a83 100644 --- a/Tests/RunCMake/CMP0040/CMP0040-NEW-missing-target.cmake +++ b/Tests/RunCMake/CMP0040/CMP0040-NEW-missing-target.cmake @@ -1,5 +1,3 @@ -cmake_policy(SET CMP0040 NEW) - add_custom_command(TARGET foobar PRE_BUILD COMMAND ${CMAKE_COMMAND} -E hello world ) diff --git a/Tests/RunCMake/CMP0040/CMP0040-OLD-existing-target-stderr.txt b/Tests/RunCMake/CMP0040/CMP0040-OLD-existing-target-stderr.txt deleted file mode 100644 index f38c03d06c..0000000000 --- a/Tests/RunCMake/CMP0040/CMP0040-OLD-existing-target-stderr.txt +++ /dev/null @@ -1,10 +0,0 @@ -^CMake Deprecation Warning at CMP0040-OLD-existing-target.cmake:1 \(cmake_policy\): - The OLD behavior for policy CMP0040 will be removed from a future version - of CMake. - - The cmake-policies\(7\) manual explains that the OLD behaviors of all - policies are deprecated and that a policy should be set to OLD only under - specific short-term circumstances. Projects should be ported to the NEW - behavior and not rely on setting a policy to OLD. -Call Stack \(most recent call first\): - CMakeLists.txt:3 \(include\)$ diff --git a/Tests/RunCMake/CMP0040/CMP0040-OLD-existing-target.cmake b/Tests/RunCMake/CMP0040/CMP0040-OLD-existing-target.cmake deleted file mode 100644 index 7a9e91e836..0000000000 --- a/Tests/RunCMake/CMP0040/CMP0040-OLD-existing-target.cmake +++ /dev/null @@ -1,7 +0,0 @@ -cmake_policy(SET CMP0040 OLD) - -add_library(foobar empty.cpp) - -add_custom_command(TARGET foobar PRE_BUILD - COMMAND ${CMAKE_COMMAND} -E echo hello world -) diff --git a/Tests/RunCMake/CMP0040/CMP0040-OLD-missing-target-stderr.txt b/Tests/RunCMake/CMP0040/CMP0040-OLD-missing-target-stderr.txt deleted file mode 100644 index 61f4f035db..0000000000 --- a/Tests/RunCMake/CMP0040/CMP0040-OLD-missing-target-stderr.txt +++ /dev/null @@ -1,10 +0,0 @@ -^CMake Deprecation Warning at CMP0040-OLD-missing-target.cmake:1 \(cmake_policy\): - The OLD behavior for policy CMP0040 will be removed from a future version - of CMake. - - The cmake-policies\(7\) manual explains that the OLD behaviors of all - policies are deprecated and that a policy should be set to OLD only under - specific short-term circumstances. Projects should be ported to the NEW - behavior and not rely on setting a policy to OLD. -Call Stack \(most recent call first\): - CMakeLists.txt:3 \(include\)$ diff --git a/Tests/RunCMake/CMP0040/CMP0040-OLD-missing-target.cmake b/Tests/RunCMake/CMP0040/CMP0040-OLD-missing-target.cmake deleted file mode 100644 index 0f5cd1522e..0000000000 --- a/Tests/RunCMake/CMP0040/CMP0040-OLD-missing-target.cmake +++ /dev/null @@ -1,5 +0,0 @@ -cmake_policy(SET CMP0040 OLD) - -add_custom_command(TARGET foobar PRE_BUILD - COMMAND ${CMAKE_COMMAND} -E echo hello world -) diff --git a/Tests/RunCMake/CMP0040/CMP0040-WARN-missing-target-result.txt b/Tests/RunCMake/CMP0040/CMP0040-WARN-missing-target-result.txt deleted file mode 100644 index 573541ac97..0000000000 --- a/Tests/RunCMake/CMP0040/CMP0040-WARN-missing-target-result.txt +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/Tests/RunCMake/CMP0040/CMP0040-WARN-missing-target-stderr.txt b/Tests/RunCMake/CMP0040/CMP0040-WARN-missing-target-stderr.txt deleted file mode 100644 index 70ed05ba1d..0000000000 --- a/Tests/RunCMake/CMP0040/CMP0040-WARN-missing-target-stderr.txt +++ /dev/null @@ -1,10 +0,0 @@ -CMake Warning \(dev\) at CMP0040-WARN-missing-target.cmake:2 \(add_custom_command\): - Policy CMP0040 is not set: The target in the TARGET signature of - add_custom_command\(\) must exist and must be defined in the current - directory. Run "cmake --help-policy CMP0040" for policy details. Use the - cmake_policy command to set the policy and suppress this warning. -+ - No TARGET 'foobar' has been created in this directory. -Call Stack \(most recent call first\): - CMakeLists.txt:3 \(include\) -This warning is for project developers. Use -Wno-dev to suppress it. diff --git a/Tests/RunCMake/CMP0040/CMP0040-WARN-missing-target.cmake b/Tests/RunCMake/CMP0040/CMP0040-WARN-missing-target.cmake deleted file mode 100644 index 4efeaae52c..0000000000 --- a/Tests/RunCMake/CMP0040/CMP0040-WARN-missing-target.cmake +++ /dev/null @@ -1,4 +0,0 @@ - -add_custom_command(TARGET foobar PRE_BUILD - COMMAND ${CMAKE_COMMAND} -E hello world -) diff --git a/Tests/RunCMake/CMP0040/CMakeLists.txt b/Tests/RunCMake/CMP0040/CMakeLists.txt index a06591c31f..c814f14935 100644 --- a/Tests/RunCMake/CMP0040/CMakeLists.txt +++ b/Tests/RunCMake/CMP0040/CMakeLists.txt @@ -1,3 +1,3 @@ -cmake_minimum_required(VERSION 2.8.12) +cmake_minimum_required(VERSION 3.10) project(${RunCMake_TEST} CXX) include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/CMP0040/RunCMakeTest.cmake b/Tests/RunCMake/CMP0040/RunCMakeTest.cmake index e5e6c3759d..b6fd89914f 100644 --- a/Tests/RunCMake/CMP0040/RunCMakeTest.cmake +++ b/Tests/RunCMake/CMP0040/RunCMakeTest.cmake @@ -1,9 +1,4 @@ include(RunCMake) -set(RunCMake_IGNORE_POLICY_VERSION_DEPRECATION ON) -run_cmake(CMP0040-OLD-missing-target) run_cmake(CMP0040-NEW-missing-target) -run_cmake(CMP0040-WARN-missing-target) - -run_cmake(CMP0040-OLD-existing-target) run_cmake(CMP0040-NEW-existing-target)