Explorar o código

CMP0043: Remove support for OLD behavior

Note that per-source `COMPILE_DEFINITIONS_<CONFIG>` are not covered by
the policy, and are still supported.
Brad King hai 11 meses
pai
achega
ed99370f63

+ 5 - 4
Help/policy/CMP0043.rst

@@ -1,6 +1,9 @@
 CMP0043
 -------
 
+.. |REMOVED_IN_CMAKE_VERSION| replace:: 4.0
+.. include:: REMOVED_PROLOGUE.txt
+
 Ignore COMPILE_DEFINITIONS_<Config> properties
 
 CMake 2.8.12 and lower allowed setting the
@@ -41,7 +44,5 @@ compilation command. The ``NEW`` behavior for this policy is to ignore the conte
 of the :prop_tgt:`COMPILE_DEFINITIONS_<CONFIG>` target property .
 
 .. |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

+ 1 - 4
Source/cmGeneratorTarget.cxx

@@ -5450,11 +5450,8 @@ bool cmGeneratorTarget::AddHeaderSetVerification()
             verifyTarget->SetProperty("DISABLE_PRECOMPILE_HEADERS", "ON");
             verifyTarget->SetProperty("UNITY_BUILD", "OFF");
             verifyTarget->SetProperty("CXX_SCAN_FOR_MODULES", "OFF");
-            cm::optional<std::map<std::string, cmValue>>
-              perConfigCompileDefinitions;
             verifyTarget->FinalizeTargetConfiguration(
-              this->Makefile->GetCompileDefinitionsEntries(),
-              perConfigCompileDefinitions);
+              this->Makefile->GetCompileDefinitionsEntries());
 
             if (!allVerifyTarget) {
               allVerifyTarget = this->GlobalGenerator->GetMakefiles()

+ 0 - 27
Source/cmGeneratorTarget_Options.cxx

@@ -4,8 +4,6 @@
 #include "cmGeneratorTarget.h"
 /* clang-format on */
 
-#include "cmConfigure.h"
-
 #include <algorithm>
 #include <iterator>
 #include <map>
@@ -336,31 +334,6 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetCompileDefinitions(
   AddInterfaceEntries(this, config, "INTERFACE_COMPILE_DEFINITIONS", language,
                       &dagChecker, entries, IncludeRuntimeInterface::Yes);
 
-  if (!config.empty()) {
-    std::string configPropName =
-      "COMPILE_DEFINITIONS_" + cmSystemTools::UpperCase(config);
-    cmValue configProp = this->GetProperty(configPropName);
-    if (configProp) {
-      switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0043)) {
-        case cmPolicies::WARN: {
-          this->LocalGenerator->IssueMessage(
-            MessageType::AUTHOR_WARNING,
-            cmPolicies::GetPolicyWarning(cmPolicies::CMP0043));
-          CM_FALLTHROUGH;
-        }
-        case cmPolicies::OLD: {
-          std::unique_ptr<TargetPropertyEntry> entry =
-            TargetPropertyEntry::Create(
-              *this->LocalGenerator->GetCMakeInstance(), *configProp);
-          entries.Entries.emplace_back(EvaluateTargetPropertyEntry(
-            this, config, language, &dagChecker, *entry));
-        } break;
-        case cmPolicies::NEW:
-          break;
-      }
-    }
-  }
-
   processOptions(this, entries, list, uniqueOptions, debugDefines,
                  "compile definitions", OptionsParse::None);
 

+ 0 - 7
Source/cmGeneratorTarget_TransitiveProperty.cxx

@@ -202,13 +202,6 @@ cmGeneratorTarget::IsTransitiveProperty(cm::string_view prop,
         result->Usage = cmGeneratorTarget::UseTo::Compile;
       }
     }
-  } else if (cmHasLiteralPrefix(prop, "COMPILE_DEFINITIONS_")) {
-    cmPolicies::PolicyStatus cmp0043 =
-      lg->GetPolicyStatus(cmPolicies::CMP0043);
-    if (cmp0043 == cmPolicies::WARN || cmp0043 == cmPolicies::OLD) {
-      result = TransitiveProperty{ "INTERFACE_COMPILE_DEFINITIONS"_s,
-                                   UseTo::Compile };
-    }
   } else if (!evaluatingLinkLibraries) {
     // Honor TRANSITIVE_COMPILE_PROPERTIES and TRANSITIVE_LINK_PROPERTIES
     // from the link closure when we are not evaluating the closure itself.

+ 2 - 5
Source/cmGlobalGenerator.cxx

@@ -1938,14 +1938,11 @@ void cmGlobalGenerator::FinalizeTargetConfiguration()
 
   // Construct per-target generator information.
   for (const auto& mf : this->Makefiles) {
-    const cmBTStringRange noConfigCompileDefinitions =
+    const cmBTStringRange compileDefinitions =
       mf->GetCompileDefinitionsEntries();
-    cm::optional<std::map<std::string, cmValue>> perConfigCompileDefinitions;
-
     for (auto& target : mf->GetTargets()) {
       cmTarget* t = &target.second;
-      t->FinalizeTargetConfiguration(noConfigCompileDefinitions,
-                                     perConfigCompileDefinitions);
+      t->FinalizeTargetConfiguration(compileDefinitions);
     }
 
     // The standard include directories for each language

+ 0 - 15
Source/cmMakefile.cxx

@@ -1435,21 +1435,6 @@ void cmMakefile::InitializeFromParent(cmMakefile* parent)
     this->SetProperty(prop, parent->GetProperty(prop));
   }
 
-  // compile definitions property and per-config versions
-  cmPolicies::PolicyStatus polSt = this->GetPolicyStatus(cmPolicies::CMP0043);
-  if (polSt == cmPolicies::WARN || polSt == cmPolicies::OLD) {
-    this->SetProperty("COMPILE_DEFINITIONS",
-                      parent->GetProperty("COMPILE_DEFINITIONS"));
-    std::vector<std::string> configs =
-      this->GetGeneratorConfigs(cmMakefile::ExcludeEmptyConfig);
-    for (std::string const& config : configs) {
-      std::string defPropName =
-        cmStrCat("COMPILE_DEFINITIONS_", cmSystemTools::UpperCase(config));
-      cmValue prop = parent->GetProperty(defPropName);
-      this->SetProperty(defPropName, prop);
-    }
-  }
-
   // labels
   this->SetProperty("LABELS", parent->GetProperty("LABELS"));
 

+ 1 - 1
Source/cmPolicies.h

@@ -132,7 +132,7 @@ class cmMakefile;
   SELECT(POLICY, CMP0042, "MACOSX_RPATH is enabled by default.", 3, 0, 0,     \
          NEW)                                                                 \
   SELECT(POLICY, CMP0043, "Ignore COMPILE_DEFINITIONS_<Config> properties.",  \
-         3, 0, 0, WARN)                                                       \
+         3, 0, 0, NEW)                                                        \
   SELECT(POLICY, CMP0044,                                                     \
          "Case sensitive <LANG>_COMPILER_ID generator expressions.", 3, 0, 0, \
          WARN)                                                                \

+ 2 - 29
Source/cmTarget.cxx

@@ -2514,8 +2514,7 @@ bool CheckLinkLibraryPattern(UsageRequirementProperty const& usage,
 }
 
 void cmTarget::FinalizeTargetConfiguration(
-  const cmBTStringRange& noConfigCompileDefinitions,
-  cm::optional<std::map<std::string, cmValue>>& perConfigCompileDefinitions)
+  const cmBTStringRange& compileDefinitions)
 {
   if (this->GetType() == cmStateEnums::GLOBAL_TARGET) {
     return;
@@ -2536,35 +2535,9 @@ void cmTarget::FinalizeTargetConfiguration(
     return;
   }
 
-  for (auto const& def : noConfigCompileDefinitions) {
+  for (auto const& def : compileDefinitions) {
     this->InsertCompileDefinition(def);
   }
-
-  auto* mf = this->GetMakefile();
-  cmPolicies::PolicyStatus polSt = mf->GetPolicyStatus(cmPolicies::CMP0043);
-  if (polSt == cmPolicies::WARN || polSt == cmPolicies::OLD) {
-    if (perConfigCompileDefinitions) {
-      for (auto const& it : *perConfigCompileDefinitions) {
-        if (cmValue val = it.second) {
-          this->AppendProperty(it.first, *val);
-        }
-      }
-    } else {
-      perConfigCompileDefinitions.emplace();
-      std::vector<std::string> configs =
-        mf->GetGeneratorConfigs(cmMakefile::ExcludeEmptyConfig);
-
-      for (std::string const& c : configs) {
-        std::string defPropName =
-          cmStrCat("COMPILE_DEFINITIONS_", cmSystemTools::UpperCase(c));
-        cmValue val = mf->GetProperty(defPropName);
-        (*perConfigCompileDefinitions)[defPropName] = val;
-        if (val) {
-          this->AppendProperty(defPropName, *val);
-        }
-      }
-    }
-  }
 }
 
 void cmTarget::InsertInclude(BT<std::string> const& entry, bool before)

+ 1 - 4
Source/cmTarget.h

@@ -5,7 +5,6 @@
 #include "cmConfigure.h" // IWYU pragma: keep
 
 #include <iosfwd>
-#include <map>
 #include <memory>
 #include <set>
 #include <string>
@@ -260,9 +259,7 @@ public:
   void InsertPrecompileHeader(BT<std::string> const& entry);
 
   void AppendBuildInterfaceIncludes();
-  void FinalizeTargetConfiguration(
-    const cmBTStringRange& noConfigCompileDefinitions,
-    cm::optional<std::map<std::string, cmValue>>& perConfigCompileDefinitions);
+  void FinalizeTargetConfiguration(const cmBTStringRange& compileDefinitions);
 
   std::string GetDebugGeneratorExpressions(const std::string& value,
                                            cmTargetLinkLibraryType llt) const;

+ 0 - 4
Tests/CompileDefinitions/compiletest.c

@@ -13,10 +13,6 @@
 #  error Unexpected LINK_LANGUAGE_IS_CXX
 #endif
 
-#ifdef DEBUG_MODE
-#  error Unexpected DEBUG_MODE
-#endif
-
 int main(void)
 {
   return 0;

+ 0 - 3
Tests/CompileDefinitions/target_prop/CMakeLists.txt

@@ -35,9 +35,6 @@ set_property(TARGET target_prop_executable APPEND PROPERTY COMPILE_DEFINITIONS
 
 add_executable(target_prop_c_executable ../compiletest.c)
 
-cmake_policy(SET CMP0043 NEW)
-set_property(TARGET target_prop_c_executable APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG DEBUG_MODE)
-
 set_property(TARGET target_prop_c_executable APPEND PROPERTY COMPILE_DEFINITIONS
     "$<$<STREQUAL:$<TARGET_PROPERTY:LINKER_LANGUAGE>,CXX>:LINK_CXX_DEFINE>"
     "$<$<STREQUAL:$<TARGET_PROPERTY:LINKER_LANGUAGE>,C>:LINK_C_DEFINE>"

+ 0 - 13
Tests/Complex/CMakeLists.txt

@@ -22,7 +22,6 @@ message("message")
 # It is not recommended to set a policy to OLD, but this test
 # covers the OLD behavior of some policies.
 foreach(p
-    CMP0043
     CMP0050
     )
   if(POLICY ${p})
@@ -101,18 +100,6 @@ endif()
 
 add_definitions(-DCMAKE_IS_FUN)
 add_definitions(-DCMAKE_IS_REALLY_FUN)
-set_property(DIRECTORY
-  PROPERTY COMPILE_DEFINITIONS_RELEASE
-  CMAKE_IS_FUN_IN_RELEASE_MODE
-  )
-set_property(DIRECTORY
-  PROPERTY COMPILE_DEFINITIONS_RELWITHDEBINFO
-  CMAKE_IS_FUN_IN_RELEASE_MODE
-  )
-set_property(DIRECTORY
-  PROPERTY COMPILE_DEFINITIONS_MINSIZEREL
-  CMAKE_IS_FUN_IN_RELEASE_MODE
-  )
 
 set(TEST_SEP "a b c")
 separate_arguments(TEST_SEP)

+ 0 - 4
Tests/Complex/Executable/complex.cxx

@@ -62,10 +62,6 @@ void cmPassed(const char* Message, const char* m2 = "")
 #  error This is a problem. Looks like ADD_DEFINITIONS and REMOVE_DEFINITIONS does not work
 #endif
 
-#if defined(COMPLEX_NDEBUG) && !defined(CMAKE_IS_FUN_IN_RELEASE_MODE)
-#  error Per-configuration directory-level definition not inherited.
-#endif
-
 // ======================================================================
 
 void TestAndRemoveFile(const char* filename)

+ 0 - 13
Tests/ComplexOneConfig/CMakeLists.txt

@@ -15,7 +15,6 @@ 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
-    CMP0043
     CMP0050
     )
   if(POLICY ${p})
@@ -88,18 +87,6 @@ endif()
 
 add_definitions(-DCMAKE_IS_FUN)
 add_definitions(-DCMAKE_IS_REALLY_FUN)
-set_property(DIRECTORY
-  PROPERTY COMPILE_DEFINITIONS_RELEASE
-  CMAKE_IS_FUN_IN_RELEASE_MODE
-  )
-set_property(DIRECTORY
-  PROPERTY COMPILE_DEFINITIONS_RELWITHDEBINFO
-  CMAKE_IS_FUN_IN_RELEASE_MODE
-  )
-set_property(DIRECTORY
-  PROPERTY COMPILE_DEFINITIONS_MINSIZEREL
-  CMAKE_IS_FUN_IN_RELEASE_MODE
-  )
 
 set(TEST_SEP "a b c")
 separate_arguments(TEST_SEP)

+ 0 - 4
Tests/ComplexOneConfig/Executable/complex.cxx

@@ -62,10 +62,6 @@ void cmPassed(const char* Message, const char* m2 = "")
 #  error This is a problem. Looks like ADD_DEFINITIONS and REMOVE_DEFINITIONS does not work
 #endif
 
-#if defined(COMPLEX_NDEBUG) && !defined(CMAKE_IS_FUN_IN_RELEASE_MODE)
-#  error Per-configuration directory-level definition not inherited.
-#endif
-
 // ======================================================================
 
 void TestAndRemoveFile(const char* filename)

+ 2 - 4
Tests/ExportImport/Import/A/CMakeLists.txt

@@ -209,10 +209,8 @@ target_link_libraries(imp_ExePlugin1b PRIVATE bld_testExeWithPluginHelper testEx
 
 # Export/CMakeLists.txt pretends the RelWithDebInfo (as well as Debug)
 # configuration should link to debug libs.
-foreach(c DEBUG RELWITHDEBINFO)
-  set_property(TARGET imp_testExe1 PROPERTY COMPILE_DEFINITIONS_${c} EXE_DBG)
-  set_property(TARGET imp_testExe1b PROPERTY COMPILE_DEFINITIONS_${c} EXE_DBG)
-endforeach()
+target_compile_definitions(imp_testExe1  PRIVATE "$<$<CONFIG:Debug,RelWithDebInfo>:EXE_DBG>")
+target_compile_definitions(imp_testExe1b PRIVATE "$<$<CONFIG:Debug,RelWithDebInfo>:EXE_DBG>")
 
 #-----------------------------------------------------------------------------
 include(${CMAKE_INSTALL_PREFIX}/lib/expAbs/expAbs.cmake)

+ 0 - 1
Tests/ExportImport/Import/CMakeLists.txt

@@ -1,5 +1,4 @@
 cmake_minimum_required (VERSION 3.10)
-cmake_policy(SET CMP0043 OLD)
 if(POLICY CMP0129)
   cmake_policy(SET CMP0129 NEW)
 endif()

+ 29 - 10
Tests/Preprocess/CMakeLists.txt

@@ -1,6 +1,4 @@
 cmake_minimum_required(VERSION 3.10)
-cmake_policy(SET CMP0043 OLD) # testing the old behavior
-
 project(Preprocess)
 
 # This test is meant both as a test and as a reference for supported
@@ -229,24 +227,45 @@ set(FILE_PATH "${Preprocess_SOURCE_DIR}/file_def.h")
 set(TARGET_PATH "${Preprocess_SOURCE_DIR}/target_def.h")
 
 # Set some definition properties.
-foreach(c "" "_DEBUG" "_RELEASE" "_RELWITHDEBINFO" "_MINSIZEREL")
-  set(FLAVOR "${c}")
+set_property(
+  DIRECTORY .
+  APPEND PROPERTY COMPILE_DEFINITIONS "DIRECTORY_DEF"
+  )
+set_property(
+  TARGET Preprocess
+  APPEND PROPERTY COMPILE_DEFINITIONS "TARGET_DEF"
+  )
+set_property(
+  SOURCE preprocess.c preprocess.cxx
+  PROPERTY COMPILE_DEFINITIONS "FILE_DEF"
+  )
+
+# Set some per-config definition properties.
+foreach(c "DEBUG" "RELEASE" "RELWITHDEBINFO" "MINSIZEREL")
   # Treat RelWithDebInfo and MinSizeRel as Release to avoid having
   # an exponential matrix of inclusions and exclusions of defines
-  if("${c}" STREQUAL "_RELWITHDEBINFO" OR "${c}" STREQUAL "_MINSIZEREL")
-    set(FLAVOR "_RELEASE")
+  if("${c}" STREQUAL "RELWITHDEBINFO" OR "${c}" STREQUAL "MINSIZEREL")
+    set(FLAVOR "RELEASE")
+  else()
+    set(FLAVOR "${c}")
   endif()
   set_property(
     DIRECTORY .
-    APPEND PROPERTY COMPILE_DEFINITIONS${c} "DIRECTORY_DEF${FLAVOR}"
+    APPEND PROPERTY COMPILE_DEFINITIONS "$<$<CONFIG:${c}>:DIRECTORY_DEF_${FLAVOR}>"
     )
   set_property(
     TARGET Preprocess
-    PROPERTY COMPILE_DEFINITIONS${c} "TARGET_DEF${FLAVOR}"
+    APPEND PROPERTY COMPILE_DEFINITIONS "$<$<CONFIG:${c}>:TARGET_DEF_${FLAVOR}>"
     )
+  if(NOT PREPROCESS_XCODE)
+    set_property(
+      SOURCE preprocess.c
+      APPEND PROPERTY COMPILE_DEFINITIONS "$<$<CONFIG:${c}>:FILE_DEF_${FLAVOR}>"
+      )
+  endif()
   set_property(
-    SOURCE preprocess.c preprocess.cxx
-    PROPERTY COMPILE_DEFINITIONS${c} "FILE_DEF${FLAVOR}"
+    SOURCE preprocess.cxx
+    PROPERTY COMPILE_DEFINITIONS_${c} "FILE_DEF_${FLAVOR}"
     )
 endforeach()
 

+ 0 - 1
Tests/RunCMake/CMP0043/CMP0043-NEW-result.txt

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

+ 0 - 7
Tests/RunCMake/CMP0043/CMP0043-NEW.cmake

@@ -1,7 +0,0 @@
-
-cmake_policy(SET CMP0043 NEW)
-
-add_library(foo empty.cpp)
-set_property(TARGET foo
-  PROPERTY COMPILE_DEFINITIONS_DEBUG "DEBUG_MODE"
-)

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

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

@@ -1,7 +0,0 @@
-
-cmake_policy(SET CMP0043 OLD)
-
-add_library(foo empty.cpp)
-set_property(TARGET foo
-  PROPERTY COMPILE_DEFINITIONS_DEBUG "DEBUG_MODE"
-)

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

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

+ 0 - 5
Tests/RunCMake/CMP0043/CMP0043-WARN-stderr.txt

@@ -1,5 +0,0 @@
-CMake Warning \(dev\) in CMakeLists.txt:
-  Policy CMP0043 is not set: Ignore COMPILE_DEFINITIONS_<Config> properties.
-  Run "cmake --help-policy CMP0043" for policy details.  Use the cmake_policy
-  command to set the policy and suppress this warning.
-This warning is for project developers.  Use -Wno-dev to suppress it.

+ 0 - 5
Tests/RunCMake/CMP0043/CMP0043-WARN.cmake

@@ -1,5 +0,0 @@
-
-add_library(foo empty.cpp)
-set_property(TARGET foo
-  PROPERTY COMPILE_DEFINITIONS_DEBUG "DEBUG_MODE"
-)

+ 0 - 7
Tests/RunCMake/CMP0043/CMakeLists.txt

@@ -1,7 +0,0 @@
-cmake_minimum_required(VERSION 2.8.12)
-project(${RunCMake_TEST} CXX)
-include(${RunCMake_TEST}.cmake NO_POLICY_SCOPE) # policy used at end of dir
-
-if(CMAKE_BUILD_TYPE)
-  # Dummy variable use
-endif()

+ 0 - 8
Tests/RunCMake/CMP0043/RunCMakeTest.cmake

@@ -1,8 +0,0 @@
-include(RunCMake)
-set(RunCMake_IGNORE_POLICY_VERSION_DEPRECATION ON)
-
-list(APPEND RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
-
-run_cmake(CMP0043-OLD)
-run_cmake(CMP0043-NEW)
-run_cmake(CMP0043-WARN)

+ 0 - 7
Tests/RunCMake/CMP0043/empty.cpp

@@ -1,7 +0,0 @@
-#ifdef _WIN32
-__declspec(dllexport)
-#endif
-  int empty()
-{
-  return 0;
-}

+ 0 - 1
Tests/RunCMake/CMakeLists.txt

@@ -110,7 +110,6 @@ add_RunCMake_test(CMP0041)
 if(CMAKE_SYSTEM_NAME MATCHES Darwin AND CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG)
   add_RunCMake_test(CMP0042)
 endif()
-add_RunCMake_test(CMP0043)
 add_RunCMake_test(CMP0045)
 add_RunCMake_test(CMP0046)
 add_RunCMake_test(CMP0049)