[Cmake-commits] CMake branch, next, updated. v3.3.1-2354-ga545cec

Chuck Atkins chuck.atkins at kitware.com
Mon Aug 24 09:14:03 EDT 2015


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".

The branch, next has been updated
       via  a545cecbf50d59685021f45c51b6f34052b55f82 (commit)
       via  8354d1e6ce354692d0b5a157531c1428530d2737 (commit)
      from  4e4b0eedf8184e832991b63e8109b1b04c925da5 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=a545cecbf50d59685021f45c51b6f34052b55f82
commit a545cecbf50d59685021f45c51b6f34052b55f82
Merge: 4e4b0ee 8354d1e
Author:     Chuck Atkins <chuck.atkins at kitware.com>
AuthorDate: Mon Aug 24 09:14:01 2015 -0400
Commit:     CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Mon Aug 24 09:14:01 2015 -0400

    Merge topic 'add-shared-link-flags-to-try_compile' into next
    
    8354d1e6 try_compile: Pass hared library link flags into test project


http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=8354d1e6ce354692d0b5a157531c1428530d2737
commit 8354d1e6ce354692d0b5a157531c1428530d2737
Author:     Chuck Atkins <chuck.atkins at kitware.com>
AuthorDate: Fri Aug 21 14:34:51 2015 -0400
Commit:     Chuck Atkins <chuck.atkins at kitware.com>
CommitDate: Fri Aug 21 14:55:55 2015 -0400

    try_compile: Pass hared library link flags into test project
    
    Copy CMAKE_SHARED_LIBRARY_LINK_<LANG>_FLAGS into the test project
    generated by try_compile, just like we already copy
    CMAKE_EXE_LINK_FLAGS (see policy CMP0056).
    
    For various compatibility reasons, the
    CMAKE_SHARED_LIBRARY_LINK_<LANG>_FLAGS are always used on executables.
    While these flags are usually set by the appropriate Platform and / or
    Toolchain file, a project may wish to override them (e.g. remove
    -rdynamic when linking agains a static runtime).  In such a case, the
    project defined flags were not getting used for try_compile operations.
    Now they are.
    
    Add CMake Policy CMP0065 to activate this behavior in the same way that
    CMP0056 passes the CMAKE_EXE_LINK_FLAGS.
    
    Extend the RunCMake.try_compile test with a case covering this behavior
    for each policy setting.

diff --git a/Help/command/try_compile.rst b/Help/command/try_compile.rst
index 1ed24df..3131bdc 100644
--- a/Help/command/try_compile.rst
+++ b/Help/command/try_compile.rst
@@ -105,7 +105,10 @@ default values:
 * :variable:`CMAKE_POSITION_INDEPENDENT_CODE`
 
 If :policy:`CMP0056` is set to ``NEW``, then
-:variable:`CMAKE_EXE_LINKER_FLAGS` is passed in as well.
+:variable:`CMAKE_EXE_LINKER_FLAGS` is passed in.
+
+If :policy:`CMP0065` is set to ``NEW``, then
+:variable:`CMAKE_SHARED_LIBRARY_LINK_<LANG>_FLAGS` is also passed in.
 
 Set the :variable:`CMAKE_TRY_COMPILE_CONFIGURATION` variable to choose
 a build configuration.
diff --git a/Help/manual/cmake-policies.7.rst b/Help/manual/cmake-policies.7.rst
index 590f10d..ae5354f 100644
--- a/Help/manual/cmake-policies.7.rst
+++ b/Help/manual/cmake-policies.7.rst
@@ -122,3 +122,4 @@ All Policies
    /policy/CMP0062
    /policy/CMP0063
    /policy/CMP0064
+   /policy/CMP0065
diff --git a/Help/policy/CMP0065.rst b/Help/policy/CMP0065.rst
new file mode 100644
index 0000000..cbabd69
--- /dev/null
+++ b/Help/policy/CMP0065.rst
@@ -0,0 +1,38 @@
+CMP0065
+-------
+
+Honor shared library link flags in :command:`try_compile` source-file
+signature.
+
+The :command:`try_compile` command source-file signature generates a
+``CMakeLists.txt`` file to build the source file into an executable.
+In order to compile the source the same way as it might be compiled
+by the calling project, the generated project sets the value of the
+:variable:`CMAKE_<LANG>_FLAGS` variable to that in the calling project.
+The value of the :variable:`CMAKE_SHARED_LIBRARY_LINK_<LANG>_FLAGS`
+variable may be needed in some cases, when it's changed from the
+default settings in the Platform or Toolchain file, but CMake 3.3.1 and
+lower did not set it in the generated project.  CMake 3.3.2 and above
+prefer to set it so that the additional linker flags are honored as
+well as compiler flags.  This policy provides compatibility with the
+pre-3.3.2 behavior.
+
+The OLD behavior for this policy is to not set the value of the
+:variable:`CMAKE_SHARED_LIBRARY_LINK_<LANG>_FLAGS` variable in the
+generated test project and just rely on the values loaded from the
+Platform file.  The NEW behavior for this policy is to set the value of
+the :variable:`CMAKE_SHARED_LIBRARY_LINK_<LANG>_FLAGS` variable in the
+test project to the same as it is in the calling project.
+
+If the project code does not set the policy explicitly, users may
+set it on the command line by defining the
+:variable:`CMAKE_POLICY_DEFAULT_CMP0065 <CMAKE_POLICY_DEFAULT_CMP<NNNN>>`
+variable in the cache.
+
+This policy was introduced in CMake version 3.3.2.  Unlike most policies,
+CMake version |release| does *not* warn by default when this policy
+is not set and simply uses OLD behavior.  See documentation of the
+:variable:`CMAKE_POLICY_WARNING_CMP0065 <CMAKE_POLICY_WARNING_CMP<NNNN>>`
+variable to control the warning.
+
+.. include:: DEPRECATED.txt
diff --git a/Help/variable/CMAKE_POLICY_WARNING_CMPNNNN.rst b/Help/variable/CMAKE_POLICY_WARNING_CMPNNNN.rst
index 8de0d56..582f9e4 100644
--- a/Help/variable/CMAKE_POLICY_WARNING_CMPNNNN.rst
+++ b/Help/variable/CMAKE_POLICY_WARNING_CMPNNNN.rst
@@ -13,6 +13,8 @@ warn by default:
   policy :policy:`CMP0056`.
 * ``CMAKE_POLICY_WARNING_CMP0060`` controls the warning for
   policy :policy:`CMP0060`.
+* ``CMAKE_POLICY_WARNING_CMP0065`` controls the warning for
+  policy :policy:`CMP0065`.
 
 This variable should not be set by a project in CMake code.  Project
 developers running CMake may set this variable in their cache to
diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx
index 9411555..a2d12a7 100644
--- a/Source/cmCoreTryCompile.cxx
+++ b/Source/cmCoreTryCompile.cxx
@@ -326,6 +326,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv)
       fprintf(fout, "set(CMAKE_%s_FLAGS \"${CMAKE_%s_FLAGS}"
               " ${COMPILE_DEFINITIONS}\")\n", li->c_str(), li->c_str());
       }
+
     switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0056))
       {
       case cmPolicies::WARN:
@@ -361,6 +362,44 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv)
       }
     fprintf(fout, "set(CMAKE_EXE_LINKER_FLAGS \"${CMAKE_EXE_LINKER_FLAGS}"
             " ${EXE_LINKER_FLAGS}\")\n");
+
+    switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0065))
+      {
+      case cmPolicies::WARN:
+        if(this->Makefile->PolicyOptionalWarningEnabled(
+             "CMAKE_POLICY_WARNING_CMP0065"))
+          {
+          std::ostringstream w;
+          w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0065) << "\n"
+            "For compatibility with older versions of CMake, try_compile "
+            "is not honoring caller link flags (e.g. "
+            "CMAKE_SHARED_LIBRARY_LINK_<LANG>_FLAGS) in the test project."
+            ;
+          this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
+          }
+      case cmPolicies::OLD:
+        // OLD behavior is to do nothing.
+        break;
+      case cmPolicies::REQUIRED_IF_USED:
+      case cmPolicies::REQUIRED_ALWAYS:
+        this->Makefile->IssueMessage(
+          cmake::FATAL_ERROR,
+          cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0065)
+          );
+      case cmPolicies::NEW:
+        // NEW behavior is to pass linker flags.
+        {
+        for(std::set<std::string>::iterator li = testLangs.begin();
+            li != testLangs.end(); ++li)
+          {
+          std::string var = "CMAKE_SHARED_LIBRARY_LINK_" + *li + "_FLAGS";
+          const char* val = this->Makefile->GetDefinition(var);
+          fprintf(fout, "set(%s %s)\n", var.c_str(),
+                  cmOutputConverter::EscapeForCMake(val?val:"").c_str());
+          }
+        } break;
+      }
+
     fprintf(fout, "include_directories(${INCLUDE_DIRECTORIES})\n");
     fprintf(fout, "set(CMAKE_SUPPRESS_REGENERATION 1)\n");
     fprintf(fout, "link_directories(${LINK_DIRECTORIES})\n");
diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h
index a791b89..5063249 100644
--- a/Source/cmPolicies.h
+++ b/Source/cmPolicies.h
@@ -195,7 +195,7 @@ class cmPolicy;
     "Strict checking for break() command.", \
     3, 2, 0, cmPolicies::WARN) \
   SELECT(POLICY, CMP0056, \
-    "Honor link flags in try_compile() source-file signature.", \
+    "Honor exe link flags in try_compile() source-file signature.", \
     3, 2, 0, cmPolicies::WARN) \
   SELECT(POLICY, CMP0057, \
     "Support new IN_LIST if() operator.", \
@@ -220,7 +220,10 @@ class cmPolicy;
     3, 3, 0, cmPolicies::WARN) \
   SELECT(POLICY, CMP0064, \
     "Support new TEST if() operator.", \
-    3, 3, 0, cmPolicies::WARN)
+    3, 3, 0, cmPolicies::WARN) \
+  SELECT(POLICY, CMP0065, \
+    "Honor shared lib link flags in try_compile() source-file signature.", \
+    3, 2, 0, cmPolicies::WARN)
 
 #define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1)
 #define CM_FOR_EACH_POLICY_ID(POLICY) \
diff --git a/Tests/RunCMake/try_compile/CMP0056-stderr.txt b/Tests/RunCMake/try_compile/CMP0056-stderr.txt
index 5c1f0e4..2adc3e5 100644
--- a/Tests/RunCMake/try_compile/CMP0056-stderr.txt
+++ b/Tests/RunCMake/try_compile/CMP0056-stderr.txt
@@ -2,9 +2,10 @@ 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.
+  Policy CMP0056 is not set: Honor exe 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.
diff --git a/Tests/RunCMake/try_compile/CMP0065-stderr.txt b/Tests/RunCMake/try_compile/CMP0065-stderr.txt
new file mode 100644
index 0000000..5bf1fff
--- /dev/null
+++ b/Tests/RunCMake/try_compile/CMP0065-stderr.txt
@@ -0,0 +1,15 @@
+before try_compile with CMP0065 WARN-default
+after try_compile with CMP0065 WARN-default
+*
+CMake Warning \(dev\) at CMP0065.cmake:[0-9]+ \(try_compile\):
+  Policy CMP0065 is not set: Honor shared lib link flags in try_compile\(\)
+  source-file signature.  Run "cmake --help-policy CMP0065" 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_SHARED_LIBRARY_LINK_<LANG>_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.$
diff --git a/Tests/RunCMake/try_compile/CMP0065-stdout.txt b/Tests/RunCMake/try_compile/CMP0065-stdout.txt
new file mode 100644
index 0000000..ba03ea7
--- /dev/null
+++ b/Tests/RunCMake/try_compile/CMP0065-stdout.txt
@@ -0,0 +1,4 @@
+-- try_compile with CMP0065 WARN-default worked as expected
+-- try_compile with CMP0065 WARN-enabled worked as expected
+-- try_compile with CMP0065 OLD worked as expected
+-- try_compile with CMP0065 NEW worked as expected
diff --git a/Tests/RunCMake/try_compile/CMP0065.cmake b/Tests/RunCMake/try_compile/CMP0065.cmake
new file mode 100644
index 0000000..942f872
--- /dev/null
+++ b/Tests/RunCMake/try_compile/CMP0065.cmake
@@ -0,0 +1,67 @@
+enable_language(C)
+set(obj "${CMAKE_C_OUTPUT_EXTENSION}")
+if(BORLAND)
+  set(pre -)
+endif()
+set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS ${pre}BADFLAG${obj})
+
+#-----------------------------------------------------------------------------
+message("before try_compile with CMP0065 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 CMP0065 WARN-default worked as expected")
+endif()
+message("after try_compile with CMP0065 WARN-default")
+
+#-----------------------------------------------------------------------------
+set(CMAKE_POLICY_WARNING_CMP0065 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 CMP0065 WARN-enabled worked as expected")
+endif()
+
+#-----------------------------------------------------------------------------
+cmake_policy(SET CMP0065 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 CMP0065 OLD worked as expected")
+endif()
+
+#-----------------------------------------------------------------------------
+cmake_policy(SET CMP0065 NEW)
+try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR}
+  ${CMAKE_CURRENT_SOURCE_DIR}/src.c
+  OUTPUT_VARIABLE out
+  )
+string(REPLACE "\n" "\n  " out "  ${out}")
+if(RESULT)
+  message(FATAL_ERROR "try_compile passed but should have failed:\n${out}")
+elseif(NOT "x${out}" MATCHES "BADFLAG")
+  message(FATAL_ERROR "try_compile did not fail with BADFLAG:\n${out}")
+else()
+  message(STATUS "try_compile with CMP0065 NEW worked as expected")
+endif()
diff --git a/Tests/RunCMake/try_compile/RunCMakeTest.cmake b/Tests/RunCMake/try_compile/RunCMakeTest.cmake
index 6cdbafa..98282e4 100644
--- a/Tests/RunCMake/try_compile/RunCMakeTest.cmake
+++ b/Tests/RunCMake/try_compile/RunCMakeTest.cmake
@@ -17,6 +17,7 @@ run_cmake(NonSourceCopyFile)
 run_cmake(NonSourceCompileDefinitions)
 
 run_cmake(CMP0056)
+run_cmake(CMP0065)
 
 if(RunCMake_GENERATOR MATCHES "Make|Ninja")
   # Use a single build tree for a few tests without cleaning.

-----------------------------------------------------------------------

Summary of changes:
 Help/command/try_compile.rst                       |    5 ++-
 Help/manual/cmake-policies.7.rst                   |    1 +
 Help/policy/CMP0065.rst                            |   38 +++++++++++++++++++
 Help/variable/CMAKE_POLICY_WARNING_CMPNNNN.rst     |    2 +
 Source/cmCoreTryCompile.cxx                        |   39 ++++++++++++++++++++
 Source/cmPolicies.h                                |    7 +++-
 Tests/RunCMake/try_compile/CMP0056-stderr.txt      |    7 ++--
 Tests/RunCMake/try_compile/CMP0065-stderr.txt      |   15 ++++++++
 Tests/RunCMake/try_compile/CMP0065-stdout.txt      |    4 ++
 .../try_compile/{CMP0056.cmake => CMP0065.cmake}   |   20 +++++-----
 Tests/RunCMake/try_compile/RunCMakeTest.cmake      |    1 +
 11 files changed, 123 insertions(+), 16 deletions(-)
 create mode 100644 Help/policy/CMP0065.rst
 create mode 100644 Tests/RunCMake/try_compile/CMP0065-stderr.txt
 create mode 100644 Tests/RunCMake/try_compile/CMP0065-stdout.txt
 copy Tests/RunCMake/try_compile/{CMP0056.cmake => CMP0065.cmake} (78%)


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list