[builtins] Make sure builtin compile tests respect CMAKE_C_COMPILER_TARGET
authorFrancis Ricci <francisjricci@gmail.com>
Thu, 25 Aug 2016 16:15:45 +0000 (16:15 +0000)
committerFrancis Ricci <francisjricci@gmail.com>
Thu, 25 Aug 2016 16:15:45 +0000 (16:15 +0000)
Summary:
Since we generate the compiler invocation on our own, we need to
manually add -target if CMAKE_C_COMPILER_TARGET has been specified.

Reviewers: compnerd, beanz

Subscribers: llvm-commits

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

llvm-svn: 279747

compiler-rt/cmake/Modules/BuiltinTests.cmake

index 6bbf449..5f3cc7e 100644 (file)
@@ -11,7 +11,13 @@ function(try_compile_only output)
   file(WRITE ${SIMPLE_C} "${ARG_SOURCE}\n")
   string(REGEX MATCHALL "<[A-Za-z0-9_]*>" substitutions
          ${CMAKE_C_COMPILE_OBJECT})
-  string(REPLACE ";" " " extra_flags "${ARG_FLAGS}")
+
+  set(TRY_COMPILE_FLAGS "${ARG_FLAGS}")
+  if(CMAKE_C_COMPILER_ID MATCHES Clang AND CMAKE_C_COMPILER_TARGET)
+    list(APPEND TRY_COMPILE_FLAGS "-target ${CMAKE_C_COMPILER_TARGET}")
+  endif()
+
+  string(REPLACE ";" " " extra_flags "${TRY_COMPILE_FLAGS}")
 
   set(test_compile_command "${CMAKE_C_COMPILE_OBJECT}")
   foreach(substitution ${substitutions})