Browse Source

CMP0056: Remove support for OLD behavior

Brad King 1 year ago
parent
commit
cbe7fc4b81

+ 2 - 3
Help/command/try_compile.rst

@@ -320,15 +320,14 @@ Other Behavior Settings
 
   * :variable:`CMAKE_CUDA_RUNTIME_LIBRARY`
   * :variable:`CMAKE_ENABLE_EXPORTS`
+  * :variable:`CMAKE_EXE_LINKER_FLAGS`, unless using CMake versions
+    prior to 4.0 without policy :policy:`CMP0056` set to ``NEW``
   * :variable:`CMAKE_LINK_SEARCH_START_STATIC`
   * :variable:`CMAKE_LINK_SEARCH_END_STATIC`
   * :variable:`CMAKE_MSVC_RUNTIME_LIBRARY`
   * :variable:`CMAKE_POSITION_INDEPENDENT_CODE`
   * :variable:`CMAKE_WATCOM_RUNTIME_LIBRARY`
 
-  If :policy:`CMP0056` is set to ``NEW``, then
-  :variable:`CMAKE_EXE_LINKER_FLAGS` is passed in as well.
-
 .. versionchanged:: 3.14
   If :policy:`CMP0083` is set to ``NEW``, then in order to obtain correct
   behavior at link time, the ``check_pie_supported()`` command from the

+ 6 - 5
Help/policy/CMP0056.rst

@@ -1,6 +1,9 @@
 CMP0056
 -------
 
+.. |REMOVED_IN_CMAKE_VERSION| replace:: 4.0
+.. include:: REMOVED_PROLOGUE.txt
+
 .. versionadded:: 3.2
 
 Honor link flags in :command:`try_compile` source-file signature.
@@ -28,11 +31,9 @@ set it on the command line by defining the
 variable in the cache.
 
 .. |INTRODUCED_IN_CMAKE_VERSION| replace:: 3.2
-.. |WARNS_OR_DOES_NOT_WARN| replace:: does *not* warn by default
-.. include:: STANDARD_ADVICE.txt
+.. |WARNED_OR_DID_NOT_WARN| replace:: did *not* warn by default
+.. include:: REMOVED_EPILOGUE.txt
 
 See documentation of the
 :variable:`CMAKE_POLICY_WARNING_CMP0056 <CMAKE_POLICY_WARNING_CMP<NNNN>>`
-variable to control the warning.
-
-.. include:: DEPRECATED.txt
+variable to control the warning in CMake versions before 4.0.

+ 2 - 2
Help/variable/CMAKE_POLICY_WARNING_CMPNNNN.rst

@@ -10,8 +10,8 @@ only for the policies that do not warn by default:
   policy :policy:`CMP0025` in CMake versions before 4.0.
 * ``CMAKE_POLICY_WARNING_CMP0047`` controlled the warning for
   policy :policy:`CMP0047` in CMake versions before 4.0.
-* ``CMAKE_POLICY_WARNING_CMP0056`` controls the warning for
-  policy :policy:`CMP0056`.
+* ``CMAKE_POLICY_WARNING_CMP0056`` controlled the warning for
+  policy :policy:`CMP0056` in CMake versions before 4.0.
 * ``CMAKE_POLICY_WARNING_CMP0060`` controls the warning for
   policy :policy:`CMP0060`.
 * ``CMAKE_POLICY_WARNING_CMP0065`` controls the warning for

+ 1 - 6
Modules/FortranCInterface.cmake

@@ -348,12 +348,7 @@ function(FortranCInterface_VERIFY)
       set(_FortranCInterface_OSX_ARCH "")
     endif()
 
-    cmake_policy(GET CMP0056 _FortranCInterface_CMP0056)
-    if(_FortranCInterface_CMP0056 STREQUAL "NEW")
-      set(_FortranCInterface_EXE_LINKER_FLAGS "-DCMAKE_EXE_LINKER_FLAGS:STRING=${CMAKE_EXE_LINKER_FLAGS}")
-    else()
-      set(_FortranCInterface_EXE_LINKER_FLAGS "")
-    endif()
+    set(_FortranCInterface_EXE_LINKER_FLAGS "-DCMAKE_EXE_LINKER_FLAGS:STRING=${CMAKE_EXE_LINKER_FLAGS}")
 
     # Build a sample project which reports symbols.
     set(CMAKE_TRY_COMPILE_CONFIGURATION Release)

+ 1 - 7
Modules/FortranCInterface/Detect.cmake

@@ -36,13 +36,7 @@ else()
   set(_FortranCInterface_OSX_ARCH "")
 endif()
 
-cmake_policy(GET CMP0056 _FortranCInterface_CMP0056)
-if(_FortranCInterface_CMP0056 STREQUAL "NEW")
-  set(_FortranCInterface_EXE_LINKER_FLAGS "-DCMAKE_EXE_LINKER_FLAGS:STRING=${CMAKE_EXE_LINKER_FLAGS}")
-else()
-  set(_FortranCInterface_EXE_LINKER_FLAGS "")
-endif()
-unset(_FortranCInterface_CMP0056)
+set(_FortranCInterface_EXE_LINKER_FLAGS "-DCMAKE_EXE_LINKER_FLAGS:STRING=${CMAKE_EXE_LINKER_FLAGS}")
 
 # Build a sample project which reports symbols.
 set(CMAKE_TRY_COMPILE_CONFIGURATION Release)

+ 8 - 30
Source/cmCoreTryCompile.cxx

@@ -786,36 +786,14 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode(
         }
       } break;
     }
-    switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0056)) {
-      case cmPolicies::WARN:
-        if (this->Makefile->PolicyOptionalWarningEnabled(
-              "CMAKE_POLICY_WARNING_CMP0056")) {
-          std::ostringstream w;
-          /* clang-format off */
-          w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0056) << "\n"
-            "For compatibility with older versions of CMake, try_compile "
-            "is not honoring caller link flags (e.g. CMAKE_EXE_LINKER_FLAGS) "
-            "in the test project."
-            ;
-          /* clang-format on */
-          this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, w.str());
-        }
-        CM_FALLTHROUGH;
-      case cmPolicies::OLD:
-        // OLD behavior is to do nothing.
-        break;
-      case cmPolicies::NEW:
-        // NEW behavior is to pass linker flags.
-        {
-          cmValue exeLinkFlags =
-            this->Makefile->GetDefinition("CMAKE_EXE_LINKER_FLAGS");
-          fprintf(fout, "set(CMAKE_EXE_LINKER_FLAGS %s)\n",
-                  cmOutputConverter::EscapeForCMake(*exeLinkFlags).c_str());
-          if (exeLinkFlags) {
-            cmakeVariables.emplace("CMAKE_EXE_LINKER_FLAGS", *exeLinkFlags);
-          }
-        }
-        break;
+    {
+      cmValue exeLinkFlags =
+        this->Makefile->GetDefinition("CMAKE_EXE_LINKER_FLAGS");
+      fprintf(fout, "set(CMAKE_EXE_LINKER_FLAGS %s)\n",
+              cmOutputConverter::EscapeForCMake(*exeLinkFlags).c_str());
+      if (exeLinkFlags) {
+        cmakeVariables.emplace("CMAKE_EXE_LINKER_FLAGS", *exeLinkFlags);
+      }
     }
     fprintf(fout,
             "set(CMAKE_EXE_LINKER_FLAGS \"${CMAKE_EXE_LINKER_FLAGS}"

+ 1 - 1
Source/cmPolicies.h

@@ -167,7 +167,7 @@ class cmMakefile;
          NEW)                                                                 \
   SELECT(POLICY, CMP0056,                                                     \
          "Honor link flags in try_compile() source-file signature.", 3, 2, 0, \
-         WARN)                                                                \
+         NEW)                                                                 \
   SELECT(POLICY, CMP0057, "Support new IN_LIST if() operator.", 3, 3, 0,      \
          WARN)                                                                \
   SELECT(POLICY, CMP0058,                                                     \

+ 0 - 24
Tests/RunCMake/try_compile/CMP0056-stderr.txt

@@ -1,24 +0,0 @@
-before try_compile with CMP0056 WARN-default
-after try_compile with CMP0056 WARN-default
-*
-CMake Warning \(dev\) at CMP0056.cmake:[0-9]+ \(try_compile\):
-  Policy CMP0056 is not set: Honor link flags in try_compile\(\) source-file
-  signature.  Run "cmake --help-policy CMP0056" for policy details.  Use the
-  cmake_policy command to set the policy and suppress this warning.
-
-  For compatibility with older versions of CMake, try_compile is not honoring
-  caller link flags \(e.g.  CMAKE_EXE_LINKER_FLAGS\) in the test project.
-Call Stack \(most recent call first\):
-  CMakeLists.txt:[0-9]+ \(include\)
-This warning is for project developers.  Use -Wno-dev to suppress it.
-
-CMake Deprecation Warning at CMP0056.cmake:[0-9]+ \(cmake_policy\):
-  The OLD behavior for policy CMP0056 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:[0-9]+ \(include\)$

+ 0 - 3
Tests/RunCMake/try_compile/CMP0056-stdout.txt

@@ -1,4 +1 @@
--- try_compile with CMP0056 WARN-default worked as expected
--- try_compile with CMP0056 WARN-enabled worked as expected
--- try_compile with CMP0056 OLD worked as expected
 -- try_compile with CMP0056 NEW worked as expected

+ 0 - 48
Tests/RunCMake/try_compile/CMP0056.cmake

@@ -1,4 +1,3 @@
-cmake_policy(VERSION 3.1)
 enable_language(C)
 set(obj "${CMAKE_C_OUTPUT_EXTENSION}")
 if(BORLAND)
@@ -7,53 +6,6 @@ endif()
 set(CMAKE_EXE_LINKER_FLAGS ${pre}BADFLAG${obj})
 
 #-----------------------------------------------------------------------------
-message("before try_compile with CMP0056 WARN-default")
-try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR}
-  ${CMAKE_CURRENT_SOURCE_DIR}/src.c
-  OUTPUT_VARIABLE out
-  )
-string(REPLACE "\n" "\n  " out "  ${out}")
-if(NOT RESULT)
-  message(FATAL_ERROR "try_compile failed but should have passed:\n${out}")
-elseif("x${out}" MATCHES "BADFLAG")
-  message(FATAL_ERROR "try_compile output mentions BADFLAG:\n${out}")
-else()
-  message(STATUS "try_compile with CMP0056 WARN-default worked as expected")
-endif()
-message("after try_compile with CMP0056 WARN-default")
-
-#-----------------------------------------------------------------------------
-set(CMAKE_POLICY_WARNING_CMP0056 ON)
-try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR}
-  ${CMAKE_CURRENT_SOURCE_DIR}/src.c
-  OUTPUT_VARIABLE out
-  )
-string(REPLACE "\n" "\n  " out "  ${out}")
-if(NOT RESULT)
-  message(FATAL_ERROR "try_compile failed but should have passed:\n${out}")
-elseif("x${out}" MATCHES "BADFLAG")
-  message(FATAL_ERROR "try_compile output mentions BADFLAG:\n${out}")
-else()
-  message(STATUS "try_compile with CMP0056 WARN-enabled worked as expected")
-endif()
-
-#-----------------------------------------------------------------------------
-cmake_policy(SET CMP0056 OLD)
-try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR}
-  ${CMAKE_CURRENT_SOURCE_DIR}/src.c
-  OUTPUT_VARIABLE out
-  )
-string(REPLACE "\n" "\n  " out "  ${out}")
-if(NOT RESULT)
-  message(FATAL_ERROR "try_compile failed but should have passed:\n${out}")
-elseif("x${out}" MATCHES "BADFLAG")
-  message(FATAL_ERROR "try_compile output mentions BADFLAG:\n${out}")
-else()
-  message(STATUS "try_compile with CMP0056 OLD worked as expected")
-endif()
-
-#-----------------------------------------------------------------------------
-cmake_policy(SET CMP0056 NEW)
 try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR}
   ${CMAKE_CURRENT_SOURCE_DIR}/src.c
   OUTPUT_VARIABLE out