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

Summary:
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)

Reviewers: compnerd, silvas, beanz, brad.king

Reviewed By: compnerd

Subscribers: mgorny, llvm-commits

Differential Revision: https://reviews.llvm.org/D41568

llvm-svn: 321434
This commit is contained in:
Don Hinton 2017-12-25 01:23:09 +00:00
parent 18c5d6d384
commit 130f9a4a59
3 changed files with 3 additions and 3 deletions

View File

@ -17,7 +17,7 @@ include(HandleLLVMStdlib)
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

View File

@ -8,7 +8,7 @@ INCLUDE(CheckLibraryExists)
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;

View File

@ -28,7 +28,7 @@ if(NOT DEFINED LLVM_COMPILER_CHECKED)
# 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);