summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKuba Brecka <kuba.brecka@gmail.com>2014-09-10 17:23:58 +0000
committerKuba Brecka <kuba.brecka@gmail.com>2014-09-10 17:23:58 +0000
commitc86ae35a2d37d0c284561e9b58abf2acbcf6915d (patch)
treed46a87ee214a0ba32b82aa8fc9f12ac0c9becce4
parentd5298331ccee20aa6ca52b36b9169cb73ca1f435 (diff)
Make compiler-rt tests work with relocatable SDKs on OS X
Reviewed at http://reviews.llvm.org/D4047 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@217523 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--cmake/Modules/CompilerRTCompile.cmake41
-rw-r--r--lib/sanitizer_common/tests/CMakeLists.txt2
2 files changed, 43 insertions, 0 deletions
diff --git a/cmake/Modules/CompilerRTCompile.cmake b/cmake/Modules/CompilerRTCompile.cmake
index 2d1dd22e3..6aab527a9 100644
--- a/cmake/Modules/CompilerRTCompile.cmake
+++ b/cmake/Modules/CompilerRTCompile.cmake
@@ -11,6 +11,9 @@ macro(clang_compile object_file source)
if(NOT COMPILER_RT_STANDALONE_BUILD)
list(APPEND SOURCE_DEPS clang)
endif()
+ if (TARGET CompilerRTUnitTestCheckCxx)
+ list(APPEND SOURCE_DEPS CompilerRTUnitTestCheckCxx)
+ endif()
string(REGEX MATCH "[.](cc|cpp)$" is_cxx ${source_rpath})
if(is_cxx)
string(REPLACE " " ";" global_flags "${CMAKE_CXX_FLAGS}")
@@ -36,3 +39,41 @@ macro(clang_compile object_file source)
MAIN_DEPENDENCY ${source}
DEPENDS ${SOURCE_DEPS})
endmacro()
+
+# On Darwin, there are no system-wide C++ headers and the just-built clang is
+# therefore not able to compile C++ files unless they are copied/symlinked into
+# ${LLVM_BINARY_DIR}/include/c++
+# The just-built clang is used to build compiler-rt unit tests. Let's detect
+# this before we try to build the tests and print out a suggestion how to fix
+# it.
+# On other platforms, this is currently not an issue.
+macro(clang_compiler_add_cxx_check)
+ if (APPLE)
+ set(CMD
+ "echo '#include <iostream>' | ${COMPILER_RT_TEST_COMPILER} -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.'"
+ " echo 'You should copy or symlink your system C++ headers into ${LLVM_BINARY_DIR}/include/c++'"
+ " if [ -d $(dirname $(dirname $(xcrun -f clang)))/include/c++ ]"
+ " then echo 'e.g. with:'"
+ " echo ' cp -r' $(dirname $(dirname $(xcrun -f clang)))/include/c++ '${LLVM_BINARY_DIR}/include/'"
+ " elif [ -d $(dirname $(dirname $(xcrun -f clang)))/lib/c++ ]"
+ " then echo 'e.g. with:'"
+ " echo ' cp -r' $(dirname $(dirname $(xcrun -f clang)))/lib/c++ '${LLVM_BINARY_DIR}/include/'"
+ " fi"
+ " echo 'This can also be fixed by checking out the libcxx project from llvm.org and installing the headers'"
+ " echo 'into your build directory:'"
+ " echo ' cd ${LLVM_SOURCE_DIR}/projects && svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx'"
+ " echo ' cd ${LLVM_BINARY_DIR} && make -C ${LLVM_SOURCE_DIR}/projects/libcxx installheaders HEADER_DIR=${LLVM_BINARY_DIR}/include'"
+ " echo"
+ " false"
+ "fi"
+ )
+ add_custom_target(CompilerRTUnitTestCheckCxx
+ COMMAND bash -c "${CMD}"
+ COMMENT "Checking that just-built clang can find C++ headers..."
+ DEPENDS clang
+ VERBATIM)
+ endif()
+endmacro()
diff --git a/lib/sanitizer_common/tests/CMakeLists.txt b/lib/sanitizer_common/tests/CMakeLists.txt
index 30dec3cd9..480badda0 100644
--- a/lib/sanitizer_common/tests/CMakeLists.txt
+++ b/lib/sanitizer_common/tests/CMakeLists.txt
@@ -1,5 +1,7 @@
include(CompilerRTCompile)
+clang_compiler_add_cxx_check()
+
set(SANITIZER_UNITTESTS
sanitizer_allocator_test.cc
sanitizer_atomic_test.cc