[compiler-rt] r245581 - [CMake] [OS X] Don't require command line tools installations for running compiler-rt tests.

Chris Bieneman via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 20 10:35:56 PDT 2015


Author: cbieneman
Date: Thu Aug 20 12:35:56 2015
New Revision: 245581

URL: http://llvm.org/viewvc/llvm-project?rev=245581&view=rev
Log:
[CMake] [OS X] Don't require command line tools installations for running compiler-rt tests.

If you're on an Apple platform and /usr/include doesn't exist, we should set a sysroot flag when calling clang.

Modified:
    compiler-rt/trunk/cmake/Modules/CompilerRTCompile.cmake

Modified: compiler-rt/trunk/cmake/Modules/CompilerRTCompile.cmake
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/cmake/Modules/CompilerRTCompile.cmake?rev=245581&r1=245580&r2=245581&view=diff
==============================================================================
--- compiler-rt/trunk/cmake/Modules/CompilerRTCompile.cmake (original)
+++ compiler-rt/trunk/cmake/Modules/CompilerRTCompile.cmake Thu Aug 20 12:35:56 2015
@@ -24,6 +24,19 @@ function(translate_msvc_cflags out_flags
   set(${out_flags} "${clang_flags}" PARENT_SCOPE)
 endfunction()
 
+if (APPLE)
+  # On Darwin if /usr/include doesn't exist, the user probably has Xcode but not
+  # the command line tools. If this is the case, we need to find the OS X
+  # sysroot to pass to clang.
+  if(NOT EXISTS /usr/include)
+    execute_process(COMMAND xcodebuild -version -sdk macosx Path
+       OUTPUT_VARIABLE OSX_SYSROOT
+       ERROR_QUIET
+       OUTPUT_STRIP_TRAILING_WHITESPACE)
+    set(OSX_SYSROOT_FLAG "-isysroot ${OSX_SYSROOT}")
+  endif()
+endif()
+
 # Compile a source into an object file with COMPILER_RT_TEST_COMPILER using
 # a provided compile flags and dependenices.
 # clang_compile(<object> <source>
@@ -49,6 +62,10 @@ macro(clang_compile object_file source)
     translate_msvc_cflags(global_flags "${global_flags}")
   endif()
 
+  if (APPLE)
+    set(global_flags ${OSX_SYSROOT_FLAG} ${global_flags})
+  endif()
+
   # Ignore unknown warnings. CMAKE_CXX_FLAGS may contain GCC-specific options
   # which are not supported by Clang.
   list(APPEND global_flags -Wno-unknown-warning-option)
@@ -72,7 +89,7 @@ endmacro()
 macro(clang_compiler_add_cxx_check)
   if (APPLE)
     set(CMD
-      "echo '#include <iostream>' | ${COMPILER_RT_TEST_COMPILER} -E -x c++ - > /dev/null"
+      "echo '#include <iostream>' | ${COMPILER_RT_TEST_COMPILER} ${OSX_SYSROOT_FLAG} -E -x c++ - > /dev/null"
       "if [ $? != 0 ] "
       "  then echo"
       "  echo 'Your just-built clang cannot find C++ headers, which are needed to build and run compiler-rt tests.'"




More information about the llvm-commits mailing list