浏览代码

CMP0050: Remove support for OLD behavior

Brad King 11 月之前
父节点
当前提交
6973f8304e
共有 29 个文件被更改,包括 18 次插入226 次删除
  1. 5 4
      Help/policy/CMP0050.rst
  2. 4 39
      Source/cmAddCustomCommandCommand.cxx
  3. 0 66
      Source/cmMakefile.cxx
  4. 0 6
      Source/cmMakefile.h
  5. 1 1
      Source/cmPolicies.h
  6. 0 10
      Tests/Complex/CMakeLists.txt
  7. 3 3
      Tests/Complex/Executable/CMakeLists.txt
  8. 0 10
      Tests/ComplexOneConfig/CMakeLists.txt
  9. 3 3
      Tests/ComplexOneConfig/Executable/CMakeLists.txt
  10. 0 13
      Tests/RunCMake/CMP0050/CMP0050-NEW.cmake
  11. 0 10
      Tests/RunCMake/CMP0050/CMP0050-OLD-stderr.txt
  12. 0 13
      Tests/RunCMake/CMP0050/CMP0050-OLD.cmake
  13. 0 1
      Tests/RunCMake/CMP0050/CMP0050-WARN-result.txt
  14. 0 9
      Tests/RunCMake/CMP0050/CMP0050-WARN-stderr.txt
  15. 0 3
      Tests/RunCMake/CMP0050/CMakeLists.txt
  16. 0 6
      Tests/RunCMake/CMP0050/RunCMakeTest.cmake
  17. 0 10
      Tests/RunCMake/CMP0050/empty.cpp
  18. 0 2
      Tests/RunCMake/CMP0050/input.h.in
  19. 0 1
      Tests/RunCMake/CMakeLists.txt
  20. 1 2
      Tests/RunCMake/add_custom_command/RunCMakeTest.cmake
  21. 0 0
      Tests/RunCMake/add_custom_command/SOURCE-result.txt
  22. 1 1
      Tests/RunCMake/add_custom_command/SOURCE-stderr.txt
  23. 0 1
      Tests/RunCMake/add_custom_command/SOURCE.cmake
  24. 0 1
      Tests/RunCMake/add_custom_command/SourceByproducts-result.txt
  25. 0 4
      Tests/RunCMake/add_custom_command/SourceByproducts-stderr.txt
  26. 0 1
      Tests/RunCMake/add_custom_command/SourceByproducts.cmake
  27. 0 1
      Tests/RunCMake/add_custom_command/SourceUsesTerminal-result.txt
  28. 0 4
      Tests/RunCMake/add_custom_command/SourceUsesTerminal-stderr.txt
  29. 0 1
      Tests/RunCMake/add_custom_command/SourceUsesTerminal.cmake

+ 5 - 4
Help/policy/CMP0050.rst

@@ -1,6 +1,9 @@
 CMP0050
 -------
 
+.. |REMOVED_IN_CMAKE_VERSION| replace:: 4.0
+.. include:: REMOVED_PROLOGUE.txt
+
 Disallow add_custom_command SOURCE signatures.
 
 CMake 2.8.12 and lower allowed a signature for :command:`add_custom_command`
@@ -13,7 +16,5 @@ The ``OLD`` behavior for this policy is to allow the use of
 policy is to issue an error if such a signature is used.
 
 .. |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

+ 4 - 39
Source/cmAddCustomCommandCommand.cxx

@@ -5,7 +5,6 @@
 #include <algorithm>
 #include <iterator>
 #include <set>
-#include <sstream>
 #include <unordered_set>
 #include <utility>
 
@@ -590,44 +589,10 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args,
     cc->SetImplicitDepends(implicit_depends);
     mf.AddCustomCommandToOutput(std::move(cc));
   } else {
-    if (!byproducts.empty()) {
-      status.SetError(
-        "BYPRODUCTS may not be specified with SOURCE signatures");
-      return false;
-    }
-
-    if (uses_terminal) {
-      status.SetError("USES_TERMINAL may not be used with SOURCE signatures");
-      return false;
-    }
-
-    bool issueMessage = true;
-    std::ostringstream e;
-    MessageType messageType = MessageType::AUTHOR_WARNING;
-    switch (mf.GetPolicyStatus(cmPolicies::CMP0050)) {
-      case cmPolicies::WARN:
-        e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0050) << "\n";
-        break;
-      case cmPolicies::OLD:
-        issueMessage = false;
-        break;
-      case cmPolicies::NEW:
-        messageType = MessageType::FATAL_ERROR;
-        break;
-    }
-
-    if (issueMessage) {
-      e << "The SOURCE signatures of add_custom_command are no longer "
-           "supported.";
-      mf.IssueMessage(messageType, e.str());
-      if (messageType == MessageType::FATAL_ERROR) {
-        return false;
-      }
-    }
-
-    // Use the old-style mode for backward compatibility.
-    mf.AddCustomCommandOldStyle(target, outputs, depends, source, commandLines,
-                                comment);
+    mf.IssueMessage(
+      MessageType::FATAL_ERROR,
+      "The SOURCE signatures of add_custom_command are no longer supported.");
+    return false;
   }
 
   return true;

+ 0 - 66
Source/cmMakefile.cxx

@@ -1180,72 +1180,6 @@ void cmMakefile::AddCustomCommandToOutput(
     });
 }
 
-void cmMakefile::AddCustomCommandOldStyle(
-  const std::string& target, const std::vector<std::string>& outputs,
-  const std::vector<std::string>& depends, const std::string& source,
-  const cmCustomCommandLines& commandLines, const char* comment)
-{
-  auto cc = cm::make_unique<cmCustomCommand>();
-  cc->SetDepends(depends);
-  cc->SetCommandLines(commandLines);
-  cc->SetComment(comment);
-
-  // Translate the old-style signature to one of the new-style
-  // signatures.
-  if (source == target) {
-    // In the old-style signature if the source and target were the
-    // same then it added a post-build rule to the target.  Preserve
-    // this behavior.
-    this->AddCustomCommandToTarget(target, cmCustomCommandType::POST_BUILD,
-                                   std::move(cc));
-    return;
-  }
-
-  auto ti = this->Targets.find(target);
-  cmTarget* t = ti != this->Targets.end() ? &ti->second : nullptr;
-
-  auto addRuleFileToTarget = [=](cmSourceFile* sf) {
-    // If the rule was added to the source (and not a .rule file),
-    // then add the source to the target to make sure the rule is
-    // included.
-    if (!sf->GetPropertyAsBool("__CMAKE_RULE")) {
-      if (t) {
-        t->AddSource(sf->ResolveFullPath());
-      } else {
-        cmSystemTools::Error("Attempt to add a custom rule to a target "
-                             "that does not exist yet for target " +
-                             target);
-      }
-    }
-  };
-
-  // Each output must get its own copy of this rule.
-  cmsys::RegularExpression sourceFiles(
-    "\\.(C|M|c|c\\+\\+|cc|cpp|cxx|mpp|ixx|cppm|ccm|cxxm|c\\+\\+m|cu|m|mm|"
-    "rc|def|r|odl|idl|hpj|bat|h|h\\+\\+|"
-    "hm|hpp|hxx|in|txx|inl)$");
-
-  // Choose whether to use a main dependency.
-  if (sourceFiles.find(source)) {
-    // The source looks like a real file.  Use it as the main dependency.
-    for (std::string const& output : outputs) {
-      auto cc1 = cm::make_unique<cmCustomCommand>(*cc);
-      cc1->SetOutputs(output);
-      cc1->SetMainDependency(source);
-      this->AddCustomCommandToOutput(std::move(cc1), addRuleFileToTarget);
-    }
-  } else {
-    cc->AppendDepends({ source });
-
-    // The source may not be a real file.  Do not use a main dependency.
-    for (std::string const& output : outputs) {
-      auto cc1 = cm::make_unique<cmCustomCommand>(*cc);
-      cc1->SetOutputs(output);
-      this->AddCustomCommandToOutput(std::move(cc1), addRuleFileToTarget);
-    }
-  }
-}
-
 void cmMakefile::AppendCustomCommandToOutput(
   const std::string& output, const std::vector<std::string>& depends,
   const cmImplicitDependsList& implicit_depends,

+ 0 - 6
Source/cmMakefile.h

@@ -235,12 +235,6 @@ public:
   void AddCustomCommandToOutput(
     std::unique_ptr<cmCustomCommand> cc,
     const CommandSourceCallback& callback = nullptr, bool replace = false);
-  void AddCustomCommandOldStyle(const std::string& target,
-                                const std::vector<std::string>& outputs,
-                                const std::vector<std::string>& depends,
-                                const std::string& source,
-                                const cmCustomCommandLines& commandLines,
-                                const char* comment);
   void AppendCustomCommandToOutput(
     const std::string& output, const std::vector<std::string>& depends,
     const cmImplicitDependsList& implicit_depends,

+ 1 - 1
Source/cmPolicies.h

@@ -149,7 +149,7 @@ class cmMakefile;
   SELECT(POLICY, CMP0049,                                                     \
          "Do not expand variables in target source entries.", 3, 0, 0, NEW)   \
   SELECT(POLICY, CMP0050, "Disallow add_custom_command SOURCE signatures.",   \
-         3, 0, 0, WARN)                                                       \
+         3, 0, 0, NEW)                                                        \
   SELECT(POLICY, CMP0051, "List TARGET_OBJECTS in SOURCES target property.",  \
          3, 1, 0, WARN)                                                       \
   SELECT(POLICY, CMP0052,                                                     \

+ 0 - 10
Tests/Complex/CMakeLists.txt

@@ -19,16 +19,6 @@ function(message)
 endfunction()
 message("message")
 
-# It is not recommended to set a policy to OLD, but this test
-# covers the OLD behavior of some policies.
-foreach(p
-    CMP0050
-    )
-  if(POLICY ${p})
-    cmake_policy(SET ${p} OLD)
-  endif()
-endforeach()
-
 # Test building without per-rule echo lines in Makefiles.
 set_property(GLOBAL PROPERTY RULE_MESSAGES OFF)
 

+ 3 - 3
Tests/Complex/Executable/CMakeLists.txt

@@ -110,14 +110,14 @@ set_source_files_properties(complex
 )
 set_target_properties(complex PROPERTIES COMPILE_FLAGS "-DCOMPLEX_TARGET_FLAG")
 add_custom_command(
-  TARGET complex
-  SOURCE ${Complex_SOURCE_DIR}/cmTestGeneratedHeader.h.in
+  MAIN_DEPENDENCY ${Complex_SOURCE_DIR}/cmTestGeneratedHeader.h.in
   COMMAND ${CMAKE_COMMAND}
   ARGS -E copy ${Complex_SOURCE_DIR}/cmTestGeneratedHeader.h.in
                ${Complex_BINARY_DIR}/cmTestGeneratedHeader.h
-  OUTPUTS ${Complex_BINARY_DIR}/cmTestGeneratedHeader.h
+  OUTPUT ${Complex_BINARY_DIR}/cmTestGeneratedHeader.h
   DEPENDS ${CMAKE_COMMAND}
 )
+target_sources(complex PRIVATE ${Complex_BINARY_DIR}/cmTestGeneratedHeader.h)
 
 # Test creating an executable that is not built by default.
 add_executable(notInAllExe EXCLUDE_FROM_ALL notInAllExe.cxx)

+ 0 - 10
Tests/ComplexOneConfig/CMakeLists.txt

@@ -12,16 +12,6 @@ string(APPEND CMAKE_CXX_FLAGS_RELWITHDEBINFO " -DCOMPLEX_NDEBUG")
 string(APPEND CMAKE_C_FLAGS_MINSIZEREL " -DCOMPLEX_NDEBUG")
 string(APPEND CMAKE_CXX_FLAGS_MINSIZEREL " -DCOMPLEX_NDEBUG")
 
-# It is not recommended to set a policy to OLD, but this test
-# covers the OLD behavior of some policies.
-foreach(p
-    CMP0050
-    )
-  if(POLICY ${p})
-    cmake_policy(SET ${p} OLD)
-  endif()
-endforeach()
-
 # Test building without per-rule echo lines in Makefiles.
 set_property(GLOBAL PROPERTY RULE_MESSAGES OFF)
 

+ 3 - 3
Tests/ComplexOneConfig/Executable/CMakeLists.txt

@@ -110,14 +110,14 @@ set_source_files_properties(complex
 )
 set_target_properties(complex PROPERTIES COMPILE_FLAGS "-DCOMPLEX_TARGET_FLAG")
 add_custom_command(
-  TARGET complex
-  SOURCE ${Complex_SOURCE_DIR}/cmTestGeneratedHeader.h.in
+  MAIN_DEPENDENCY ${Complex_SOURCE_DIR}/cmTestGeneratedHeader.h.in
   COMMAND ${CMAKE_COMMAND}
   ARGS -E copy ${Complex_SOURCE_DIR}/cmTestGeneratedHeader.h.in
                ${Complex_BINARY_DIR}/cmTestGeneratedHeader.h
-  OUTPUTS ${Complex_BINARY_DIR}/cmTestGeneratedHeader.h
+  OUTPUT ${Complex_BINARY_DIR}/cmTestGeneratedHeader.h
   DEPENDS ${CMAKE_COMMAND}
 )
+target_sources(complex PRIVATE ${Complex_BINARY_DIR}/cmTestGeneratedHeader.h)
 
 # Test creating an executable that is not built by default.
 add_executable(notInAllExe EXCLUDE_FROM_ALL notInAllExe.cxx)

+ 0 - 13
Tests/RunCMake/CMP0050/CMP0050-NEW.cmake

@@ -1,13 +0,0 @@
-
-cmake_policy(SET CMP0050 NEW)
-
-add_library(empty empty.cpp)
-add_custom_command(
-  TARGET empty
-  SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/input.h.in
-  COMMAND ${CMAKE_COMMAND}
-  ARGS -E copy ${CMAKE_CURRENT_SOURCE_DIR}/input.h.in
-               ${CMAKE_CURRENT_BINARY_DIR}/input.h
-  OUTPUTS ${CMAKE_CURRENT_BINARY_DIR}/input.h
-  DEPENDS ${CMAKE_COMMAND}
-)

+ 0 - 10
Tests/RunCMake/CMP0050/CMP0050-OLD-stderr.txt

@@ -1,10 +0,0 @@
-^CMake Deprecation Warning at CMP0050-OLD.cmake:2 \(cmake_policy\):
-  The OLD behavior for policy CMP0050 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\)$

+ 0 - 13
Tests/RunCMake/CMP0050/CMP0050-OLD.cmake

@@ -1,13 +0,0 @@
-
-cmake_policy(SET CMP0050 OLD)
-
-add_library(empty empty.cpp)
-add_custom_command(
-  TARGET empty
-  SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/input.h.in
-  COMMAND ${CMAKE_COMMAND}
-  ARGS -E copy ${CMAKE_CURRENT_SOURCE_DIR}/input.h.in
-               ${CMAKE_CURRENT_BINARY_DIR}/input.h
-  OUTPUTS ${CMAKE_CURRENT_BINARY_DIR}/input.h
-  DEPENDS ${CMAKE_COMMAND}
-)

+ 0 - 1
Tests/RunCMake/CMP0050/CMP0050-WARN-result.txt

@@ -1 +0,0 @@
-0

+ 0 - 9
Tests/RunCMake/CMP0050/CMP0050-WARN-stderr.txt

@@ -1,9 +0,0 @@
-CMake Warning \(dev\) at CMP0050-WARN.cmake:3 \(add_custom_command\):
-  Policy CMP0050 is not set: Disallow add_custom_command SOURCE signatures.
-  Run "cmake --help-policy CMP0050" for policy details.  Use the cmake_policy
-  command to set the policy and suppress this warning.
-
-  The SOURCE signatures of add_custom_command are no longer supported.
-Call Stack \(most recent call first\):
-  CMakeLists.txt:3 \(include\)
-This warning is for project developers.  Use -Wno-dev to suppress it.

+ 0 - 3
Tests/RunCMake/CMP0050/CMakeLists.txt

@@ -1,3 +0,0 @@
-cmake_minimum_required(VERSION 2.8.12)
-project(${RunCMake_TEST} CXX)
-include(${RunCMake_TEST}.cmake)

+ 0 - 6
Tests/RunCMake/CMP0050/RunCMakeTest.cmake

@@ -1,6 +0,0 @@
-include(RunCMake)
-set(RunCMake_IGNORE_POLICY_VERSION_DEPRECATION ON)
-
-run_cmake(CMP0050-OLD)
-run_cmake(CMP0050-NEW)
-run_cmake(CMP0050-WARN)

+ 0 - 10
Tests/RunCMake/CMP0050/empty.cpp

@@ -1,10 +0,0 @@
-
-#include "input.h"
-
-#ifdef _WIN32
-__declspec(dllexport)
-#endif
-  int empty()
-{
-  return 0;
-}

+ 0 - 2
Tests/RunCMake/CMP0050/input.h.in

@@ -1,2 +0,0 @@
-
-#define INPUT

+ 0 - 1
Tests/RunCMake/CMakeLists.txt

@@ -113,7 +113,6 @@ endif()
 add_RunCMake_test(CMP0045)
 add_RunCMake_test(CMP0046)
 add_RunCMake_test(CMP0049)
-add_RunCMake_test(CMP0050)
 add_RunCMake_test(CMP0051)
 add_RunCMake_test(CMP0053)
 add_RunCMake_test(CMP0054)

+ 1 - 2
Tests/RunCMake/add_custom_command/RunCMakeTest.cmake

@@ -16,8 +16,7 @@ run_cmake(LiteralQuotes)
 run_cmake(NoArguments)
 run_cmake(NoOutputOrTarget)
 run_cmake(OutputAndTarget)
-run_cmake(SourceByproducts)
-run_cmake(SourceUsesTerminal)
+run_cmake(SOURCE)
 run_cmake(TargetImported)
 run_cmake(TargetLiteralQuotes)
 run_cmake(TargetNotInDir)

+ 0 - 0
Tests/RunCMake/CMP0050/CMP0050-NEW-result.txt → Tests/RunCMake/add_custom_command/SOURCE-result.txt


+ 1 - 1
Tests/RunCMake/CMP0050/CMP0050-NEW-stderr.txt → Tests/RunCMake/add_custom_command/SOURCE-stderr.txt

@@ -1,4 +1,4 @@
-CMake Error at CMP0050-NEW.cmake:5 \(add_custom_command\):
+CMake Error at SOURCE.cmake:[0-9]+ \(add_custom_command\):
   The SOURCE signatures of add_custom_command are no longer supported.
 Call Stack \(most recent call first\):
   CMakeLists.txt:3 \(include\)

+ 0 - 1
Tests/RunCMake/CMP0050/CMP0050-WARN.cmake → Tests/RunCMake/add_custom_command/SOURCE.cmake

@@ -1,4 +1,3 @@
-
 add_library(empty empty.cpp)
 add_custom_command(
   TARGET empty

+ 0 - 1
Tests/RunCMake/add_custom_command/SourceByproducts-result.txt

@@ -1 +0,0 @@
-1

+ 0 - 4
Tests/RunCMake/add_custom_command/SourceByproducts-stderr.txt

@@ -1,4 +0,0 @@
-CMake Error at SourceByproducts.cmake:1 \(add_custom_command\):
-  add_custom_command BYPRODUCTS may not be specified with SOURCE signatures
-Call Stack \(most recent call first\):
-  CMakeLists.txt:3 \(include\)

+ 0 - 1
Tests/RunCMake/add_custom_command/SourceByproducts.cmake

@@ -1 +0,0 @@
-add_custom_command(SOURCE t TARGET t BYPRODUCTS b)

+ 0 - 1
Tests/RunCMake/add_custom_command/SourceUsesTerminal-result.txt

@@ -1 +0,0 @@
-1

+ 0 - 4
Tests/RunCMake/add_custom_command/SourceUsesTerminal-stderr.txt

@@ -1,4 +0,0 @@
-CMake Error at SourceUsesTerminal.cmake:1 \(add_custom_command\):
-  add_custom_command USES_TERMINAL may not be used with SOURCE signatures
-Call Stack \(most recent call first\):
-  CMakeLists.txt:3 \(include\)

+ 0 - 1
Tests/RunCMake/add_custom_command/SourceUsesTerminal.cmake

@@ -1 +0,0 @@
-add_custom_command(SOURCE t TARGET t USES_TERMINAL)