[Cmake-commits] CMake branch, next, updated. v3.5.2-1575-g1d515e5

Brad King brad.king at kitware.com
Wed May 25 09:41:05 EDT 2016


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  1d515e50baa2f096f85d3ba97a67592fcfd149f9 (commit)
       via  d256ba078a10001883487ed6af746af5b9cd9608 (commit)
       via  fb4791b37ccea1f38b8625b31df952408ab942f3 (commit)
      from  dbb18b7656652b8da15d34eb1c1516dcb80bfd17 (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 -----------------------------------------------------------------
https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=1d515e50baa2f096f85d3ba97a67592fcfd149f9
commit 1d515e50baa2f096f85d3ba97a67592fcfd149f9
Merge: dbb18b7 d256ba0
Author:     Brad King <brad.king at kitware.com>
AuthorDate: Wed May 25 09:41:04 2016 -0400
Commit:     CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Wed May 25 09:41:04 2016 -0400

    Merge topic 'try_compile-custom-variables' into next
    
    d256ba07 try_compile: Optionally forward custom platform variables to test project
    fb4791b3 cmCoreTryCompile: Refactor forwarding of variables to test project


https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=d256ba078a10001883487ed6af746af5b9cd9608
commit d256ba078a10001883487ed6af746af5b9cd9608
Author:     Brad King <brad.king at kitware.com>
AuthorDate: Tue May 24 15:33:34 2016 -0400
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Wed May 25 09:36:19 2016 -0400

    try_compile: Optionally forward custom platform variables to test project
    
    Add a `CMAKE_TRY_COMPILE_PLATFORM_VARIABLES` variable to specify a list
    of custom variables to be forwarded to a `try_compile` test project.
    This will be useful for platform information modules or toolchain files
    to forward some platform-specific set of variables from the host project
    (perhaps set in its cache) to the test project so that it can build the
    same way.

diff --git a/Help/command/try_compile.rst b/Help/command/try_compile.rst
index 78b1bc7..7830deb 100644
--- a/Help/command/try_compile.rst
+++ b/Help/command/try_compile.rst
@@ -115,3 +115,7 @@ a build configuration.
 
 Set the :variable:`CMAKE_TRY_COMPILE_TARGET_TYPE` variable to specify
 the type of target used for the source file signature.
+
+Set the :variable:`CMAKE_TRY_COMPILE_PLATFORM_VARIABLES` variable to specify
+variables that must be propagated into the test project.  This variable is
+meant for use only in toolchain files.
diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst
index b8c8bea..85b8eae 100644
--- a/Help/manual/cmake-variables.7.rst
+++ b/Help/manual/cmake-variables.7.rst
@@ -298,6 +298,7 @@ Variables that Control the Build
    /variable/CMAKE_STATIC_LINKER_FLAGS_CONFIG
    /variable/CMAKE_STATIC_LINKER_FLAGS
    /variable/CMAKE_TRY_COMPILE_CONFIGURATION
+   /variable/CMAKE_TRY_COMPILE_PLATFORM_VARIABLES
    /variable/CMAKE_TRY_COMPILE_TARGET_TYPE
    /variable/CMAKE_USE_RELATIVE_PATHS
    /variable/CMAKE_VISIBILITY_INLINES_HIDDEN
diff --git a/Help/release/dev/try_compile-custom-variables.rst b/Help/release/dev/try_compile-custom-variables.rst
new file mode 100644
index 0000000..539b364
--- /dev/null
+++ b/Help/release/dev/try_compile-custom-variables.rst
@@ -0,0 +1,7 @@
+try_compile-custom-variables
+----------------------------
+
+* A :variable:`CMAKE_TRY_COMPILE_PLATFORM_VARIABLES` variable was
+  added for use by toolchain files to specify platform-specific
+  variables that must be propagated by the :command:`try_compile`
+  command into test projects.
diff --git a/Help/variable/CMAKE_TRY_COMPILE_PLATFORM_VARIABLES.rst b/Help/variable/CMAKE_TRY_COMPILE_PLATFORM_VARIABLES.rst
new file mode 100644
index 0000000..8e43465
--- /dev/null
+++ b/Help/variable/CMAKE_TRY_COMPILE_PLATFORM_VARIABLES.rst
@@ -0,0 +1,10 @@
+CMAKE_TRY_COMPILE_PLATFORM_VARIABLES
+------------------------------------
+
+List of variables that the :command:`try_compile` command source file signature
+must propagate into the test project in order to target the same platform as
+the host project.
+
+This variable should not be set by project code.  It is meant to be set by
+CMake's platform information modules for the current toolchain, or by a
+toolchain file when used with :variable:`CMAKE_TOOLCHAIN_FILE`.
diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx
index bd9fd87..0149fdf 100644
--- a/Source/cmCoreTryCompile.cxx
+++ b/Source/cmCoreTryCompile.cxx
@@ -41,6 +41,8 @@ static std::string const kCMAKE_POSITION_INDEPENDENT_CODE =
 static std::string const kCMAKE_SYSROOT = "CMAKE_SYSROOT";
 static std::string const kCMAKE_TRY_COMPILE_OSX_ARCHITECTURES =
   "CMAKE_TRY_COMPILE_OSX_ARCHITECTURES";
+static std::string const kCMAKE_TRY_COMPILE_PLATFORM_VARIABLES =
+  "CMAKE_TRY_COMPILE_PLATFORM_VARIABLES";
 
 int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
                                      bool isTryRun)
@@ -421,6 +423,13 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
       vars.insert(kCMAKE_POSITION_INDEPENDENT_CODE);
       vars.insert(kCMAKE_SYSROOT);
 
+      if (const char* varListStr = this->Makefile->GetDefinition(
+            kCMAKE_TRY_COMPILE_PLATFORM_VARIABLES)) {
+        std::vector<std::string> varList;
+        cmSystemTools::ExpandListArgument(varListStr, varList);
+        vars.insert(varList.begin(), varList.end());
+      }
+
       /* for the TRY_COMPILEs we want to be able to specify the architecture.
          So the user can set CMAKE_OSX_ARCHITECTURES to i386;ppc and then set
          CMAKE_TRY_COMPILE_OSX_ARCHITECTURES first to i386 and then to ppc to
diff --git a/Tests/RunCMake/try_compile/PlatformVariables.cmake b/Tests/RunCMake/try_compile/PlatformVariables.cmake
new file mode 100644
index 0000000..54da645
--- /dev/null
+++ b/Tests/RunCMake/try_compile/PlatformVariables.cmake
@@ -0,0 +1,23 @@
+enable_language(C)
+
+# Normally this variable should be set by a platform information module or
+# a toolchain file, but for purposes of this test we simply set it here.
+set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES MY_CUSTOM_VARIABLE)
+
+set(MY_CUSTOM_VARIABLE SOME_VALUE)
+
+try_compile(result ${CMAKE_CURRENT_BINARY_DIR}
+  SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src.c
+  OUTPUT_VARIABLE out
+  )
+if(NOT result)
+  message(FATAL_ERROR "try_compile failed:\n${out}")
+endif()
+
+# Check that the cache was populated with our custom variable.
+file(STRINGS ${CMAKE_BINARY_DIR}/CMakeFiles/CMakeTmp/CMakeCache.txt entries
+  REGEX MY_CUSTOM_VARIABLE:UNINITIALIZED=${MY_CUSTOM_VARIABLE}
+  )
+if(NOT entries)
+  message(FATAL_ERROR "try_compile did not populate cache as expected")
+endif()
diff --git a/Tests/RunCMake/try_compile/RunCMakeTest.cmake b/Tests/RunCMake/try_compile/RunCMakeTest.cmake
index 4b1d92a..ec099fe 100644
--- a/Tests/RunCMake/try_compile/RunCMakeTest.cmake
+++ b/Tests/RunCMake/try_compile/RunCMakeTest.cmake
@@ -16,6 +16,10 @@ run_cmake(BadSources2)
 run_cmake(NonSourceCopyFile)
 run_cmake(NonSourceCompileDefinitions)
 
+set(RunCMake_TEST_OPTIONS --debug-trycompile)
+run_cmake(PlatformVariables)
+unset(RunCMake_TEST_OPTIONS)
+
 run_cmake(TargetTypeExe)
 run_cmake(TargetTypeInvalid)
 run_cmake(TargetTypeStatic)

https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=fb4791b37ccea1f38b8625b31df952408ab942f3
commit fb4791b37ccea1f38b8625b31df952408ab942f3
Author:     Brad King <brad.king at kitware.com>
AuthorDate: Tue May 24 15:09:11 2016 -0400
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Wed May 25 09:36:19 2016 -0400

    cmCoreTryCompile: Refactor forwarding of variables to test project
    
    De-duplicate the logic that constructs the cmake `-D` flag used to pass
    variables into the test project cache.  Also subsume variables that were
    propagated by generating `set()` commands in the project and pass them
    as cache entries instead.

diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx
index 9d83624..bd9fd87 100644
--- a/Source/cmCoreTryCompile.cxx
+++ b/Source/cmCoreTryCompile.cxx
@@ -20,6 +20,28 @@
 
 #include <assert.h>
 
+static std::string const kCMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN =
+  "CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN";
+static std::string const kCMAKE_C_COMPILER_TARGET = "CMAKE_C_COMPILER_TARGET";
+static std::string const kCMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN =
+  "CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN";
+static std::string const kCMAKE_CXX_COMPILER_TARGET =
+  "CMAKE_CXX_COMPILER_TARGET";
+static std::string const kCMAKE_ENABLE_EXPORTS = "CMAKE_ENABLE_EXPORTS";
+static std::string const kCMAKE_LINK_SEARCH_END_STATIC =
+  "CMAKE_LINK_SEARCH_END_STATIC";
+static std::string const kCMAKE_LINK_SEARCH_START_STATIC =
+  "CMAKE_LINK_SEARCH_START_STATIC";
+static std::string const kCMAKE_OSX_ARCHITECTURES = "CMAKE_OSX_ARCHITECTURES";
+static std::string const kCMAKE_OSX_DEPLOYMENT_TARGET =
+  "CMAKE_OSX_DEPLOYMENT_TARGET";
+static std::string const kCMAKE_OSX_SYSROOT = "CMAKE_OSX_SYSROOT";
+static std::string const kCMAKE_POSITION_INDEPENDENT_CODE =
+  "CMAKE_POSITION_INDEPENDENT_CODE";
+static std::string const kCMAKE_SYSROOT = "CMAKE_SYSROOT";
+static std::string const kCMAKE_TRY_COMPILE_OSX_ARCHITECTURES =
+  "CMAKE_TRY_COMPILE_OSX_ARCHITECTURES";
+
 int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
                                      bool isTryRun)
 {
@@ -383,76 +405,44 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
               fname.c_str());
     }
 
-    /* for the TRY_COMPILEs we want to be able to specify the architecture.
-      So the user can set CMAKE_OSX_ARCHITECTURES to i386;ppc and then set
-      CMAKE_TRY_COMPILE_OSX_ARCHITECTURES first to i386 and then to ppc to
-      have the tests run for each specific architecture. Since
-      cmLocalGenerator doesn't allow building for "the other"
-      architecture only via CMAKE_OSX_ARCHITECTURES.
-      */
-    if (this->Makefile->GetDefinition("CMAKE_TRY_COMPILE_OSX_ARCHITECTURES") !=
-        0) {
-      std::string flag = "-DCMAKE_OSX_ARCHITECTURES=";
-      flag += this->Makefile->GetSafeDefinition(
-        "CMAKE_TRY_COMPILE_OSX_ARCHITECTURES");
-      cmakeFlags.push_back(flag);
-    } else if (this->Makefile->GetDefinition("CMAKE_OSX_ARCHITECTURES") != 0) {
-      std::string flag = "-DCMAKE_OSX_ARCHITECTURES=";
-      flag += this->Makefile->GetSafeDefinition("CMAKE_OSX_ARCHITECTURES");
-      cmakeFlags.push_back(flag);
-    }
-    /* on APPLE also pass CMAKE_OSX_SYSROOT to the try_compile */
-    if (this->Makefile->GetDefinition("CMAKE_OSX_SYSROOT") != 0) {
-      std::string flag = "-DCMAKE_OSX_SYSROOT=";
-      flag += this->Makefile->GetSafeDefinition("CMAKE_OSX_SYSROOT");
-      cmakeFlags.push_back(flag);
-    }
-    /* on APPLE also pass CMAKE_OSX_DEPLOYMENT_TARGET to the try_compile */
-    if (this->Makefile->GetDefinition("CMAKE_OSX_DEPLOYMENT_TARGET") != 0) {
-      std::string flag = "-DCMAKE_OSX_DEPLOYMENT_TARGET=";
-      flag += this->Makefile->GetSafeDefinition("CMAKE_OSX_DEPLOYMENT_TARGET");
-      cmakeFlags.push_back(flag);
-    }
-    if (const char* cxxDef =
-          this->Makefile->GetDefinition("CMAKE_CXX_COMPILER_TARGET")) {
-      std::string flag = "-DCMAKE_CXX_COMPILER_TARGET=";
-      flag += cxxDef;
-      cmakeFlags.push_back(flag);
-    }
-    if (const char* cDef =
-          this->Makefile->GetDefinition("CMAKE_C_COMPILER_TARGET")) {
-      std::string flag = "-DCMAKE_C_COMPILER_TARGET=";
-      flag += cDef;
-      cmakeFlags.push_back(flag);
-    }
-    if (const char* tcxxDef = this->Makefile->GetDefinition(
-          "CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN")) {
-      std::string flag = "-DCMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN=";
-      flag += tcxxDef;
-      cmakeFlags.push_back(flag);
-    }
-    if (const char* tcDef = this->Makefile->GetDefinition(
-          "CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN")) {
-      std::string flag = "-DCMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN=";
-      flag += tcDef;
-      cmakeFlags.push_back(flag);
-    }
-    if (const char* rootDef = this->Makefile->GetDefinition("CMAKE_SYSROOT")) {
-      std::string flag = "-DCMAKE_SYSROOT=";
-      flag += rootDef;
-      cmakeFlags.push_back(flag);
-    }
-    if (this->Makefile->GetDefinition("CMAKE_POSITION_INDEPENDENT_CODE") !=
-        0) {
-      fprintf(fout, "set(CMAKE_POSITION_INDEPENDENT_CODE \"ON\")\n");
-    }
-    if (const char* lssDef =
-          this->Makefile->GetDefinition("CMAKE_LINK_SEARCH_START_STATIC")) {
-      fprintf(fout, "set(CMAKE_LINK_SEARCH_START_STATIC \"%s\")\n", lssDef);
-    }
-    if (const char* lssDef =
-          this->Makefile->GetDefinition("CMAKE_LINK_SEARCH_END_STATIC")) {
-      fprintf(fout, "set(CMAKE_LINK_SEARCH_END_STATIC \"%s\")\n", lssDef);
+    // Forward a set of variables to the inner project cache.
+    {
+      std::set<std::string> vars;
+      vars.insert(kCMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN);
+      vars.insert(kCMAKE_C_COMPILER_TARGET);
+      vars.insert(kCMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN);
+      vars.insert(kCMAKE_CXX_COMPILER_TARGET);
+      vars.insert(kCMAKE_ENABLE_EXPORTS);
+      vars.insert(kCMAKE_LINK_SEARCH_END_STATIC);
+      vars.insert(kCMAKE_LINK_SEARCH_START_STATIC);
+      vars.insert(kCMAKE_OSX_ARCHITECTURES);
+      vars.insert(kCMAKE_OSX_DEPLOYMENT_TARGET);
+      vars.insert(kCMAKE_OSX_SYSROOT);
+      vars.insert(kCMAKE_POSITION_INDEPENDENT_CODE);
+      vars.insert(kCMAKE_SYSROOT);
+
+      /* for the TRY_COMPILEs we want to be able to specify the architecture.
+         So the user can set CMAKE_OSX_ARCHITECTURES to i386;ppc and then set
+         CMAKE_TRY_COMPILE_OSX_ARCHITECTURES first to i386 and then to ppc to
+         have the tests run for each specific architecture. Since
+         cmLocalGenerator doesn't allow building for "the other"
+         architecture only via CMAKE_OSX_ARCHITECTURES.
+         */
+      if (const char* tcArchs = this->Makefile->GetDefinition(
+            kCMAKE_TRY_COMPILE_OSX_ARCHITECTURES)) {
+        vars.erase(kCMAKE_OSX_ARCHITECTURES);
+        std::string flag = "-DCMAKE_OSX_ARCHITECTURES=" + std::string(tcArchs);
+        cmakeFlags.push_back(flag);
+      }
+
+      for (std::set<std::string>::iterator vi = vars.begin(); vi != vars.end();
+           ++vi) {
+        std::string const& var = *vi;
+        if (const char* val = this->Makefile->GetDefinition(var)) {
+          std::string flag = "-D" + var + "=" + val;
+          cmakeFlags.push_back(flag);
+        }
+      }
     }
 
     /* Set the appropriate policy information for ENABLE_EXPORTS */
@@ -461,10 +451,6 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
                 cmPolicies::NEW
               ? "NEW"
               : "OLD");
-    if (const char* ee =
-          this->Makefile->GetDefinition("CMAKE_ENABLE_EXPORTS")) {
-      fprintf(fout, "set(CMAKE_ENABLE_EXPORTS %s)\n", ee);
-    }
 
     if (targetType == cmState::EXECUTABLE) {
       /* Put the executable at a known location (for COPY_FILE).  */

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

Summary of changes:
 Help/command/try_compile.rst                       |    4 +
 Help/manual/cmake-variables.7.rst                  |    1 +
 Help/release/dev/try_compile-custom-variables.rst  |    7 +
 .../CMAKE_TRY_COMPILE_PLATFORM_VARIABLES.rst       |   10 ++
 Source/cmCoreTryCompile.cxx                        |  143 ++++++++++----------
 Tests/RunCMake/try_compile/PlatformVariables.cmake |   23 ++++
 Tests/RunCMake/try_compile/RunCMakeTest.cmake      |    4 +
 7 files changed, 118 insertions(+), 74 deletions(-)
 create mode 100644 Help/release/dev/try_compile-custom-variables.rst
 create mode 100644 Help/variable/CMAKE_TRY_COMPILE_PLATFORM_VARIABLES.rst
 create mode 100644 Tests/RunCMake/try_compile/PlatformVariables.cmake


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list