[PATCH] D41568: [cmake] Always respect existing CMAKE_REQUIRED_FLAGS when adding additional ones.

Don Hinton via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 24 13:09:29 PST 2017


hintonda created this revision.
hintonda added reviewers: compnerd, silvas, beanz.
Herald added a subscriber: mgorny.

Always respect existing CMAKE_REQUIRED_FLAGS when adding
additional ones.  This is important when cross compiling where
--sysroot and -target were already added.

In particular, this is needed when cross compiling from Darwin to
Linux, since --sysroot is required to find headers and libraries.

Cmake has a similar bug in check_include_file[_cxx] where
CMAKE_REQUIRED_LIBRARIES isn't passed, which causes
try_compile to fail.
(please see https://gitlab.kitware.com/cmake/cmake/merge_requests/1620)


https://reviews.llvm.org/D41568

Files:
  cmake/config-ix.cmake
  cmake/modules/CheckAtomic.cmake
  cmake/modules/CheckCompilerVersion.cmake


Index: cmake/modules/CheckCompilerVersion.cmake
===================================================================
--- cmake/modules/CheckCompilerVersion.cmake
+++ cmake/modules/CheckCompilerVersion.cmake
@@ -28,7 +28,7 @@
         # bug in libstdc++4.6 that is fixed in libstdc++4.7.
         set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
         set(OLD_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
-        set(CMAKE_REQUIRED_FLAGS "-std=c++0x")
+        set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++0x")
         check_cxx_source_compiles("
 #include <atomic>
 std::atomic<float> x(0.0f);
Index: cmake/modules/CheckAtomic.cmake
===================================================================
--- cmake/modules/CheckAtomic.cmake
+++ cmake/modules/CheckAtomic.cmake
@@ -8,7 +8,7 @@
 
 function(check_working_cxx_atomics varname)
   set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
-  set(CMAKE_REQUIRED_FLAGS "-std=c++11")
+  set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++11")
   CHECK_CXX_SOURCE_COMPILES("
 #include <atomic>
 std::atomic<int> x;
Index: cmake/config-ix.cmake
===================================================================
--- cmake/config-ix.cmake
+++ cmake/config-ix.cmake
@@ -17,7 +17,7 @@
 
 if( UNIX AND NOT (BEOS OR HAIKU) )
   # Used by check_symbol_exists:
-  set(CMAKE_REQUIRED_LIBRARIES m)
+  list(APPEND CMAKE_REQUIRED_LIBRARIES "m")
 endif()
 # x86_64 FreeBSD 9.2 requires libcxxrt to be specified explicitly.
 if( CMAKE_SYSTEM MATCHES "FreeBSD-9.2-RELEASE" AND


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41568.128118.patch
Type: text/x-patch
Size: 1551 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171224/90cb07f2/attachment.bin>


More information about the llvm-commits mailing list