summaryrefslogtreecommitdiff
path: root/cmake/Modules
diff options
context:
space:
mode:
authorPetr Hosek <phosek@chromium.org>2018-05-22 01:01:56 +0000
committerPetr Hosek <phosek@chromium.org>2018-05-22 01:01:56 +0000
commite3c8c25f305b6013e047407818730acd83f9b3b6 (patch)
treee8b639ebbc2646e01d58de4effa70a4162f87daa /cmake/Modules
parent4f8ac50ae47ddaac5ed5a1227744f4fd29a49976 (diff)
[CMake] Use a different source depending on C++ support
When using system C++ library, assume we have a working C++ compiler and try to compile a complete C++ program. When using in tree C++ library, only check the C compiler since the C++ library likely won't have been built yet at time of running the check. Differential Revision: https://reviews.llvm.org/D47169 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@332924 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'cmake/Modules')
-rw-r--r--cmake/Modules/CompilerRTUtils.cmake17
1 files changed, 16 insertions, 1 deletions
diff --git a/cmake/Modules/CompilerRTUtils.cmake b/cmake/Modules/CompilerRTUtils.cmake
index f567202fa..506c06b60 100644
--- a/cmake/Modules/CompilerRTUtils.cmake
+++ b/cmake/Modules/CompilerRTUtils.cmake
@@ -125,6 +125,19 @@ endfunction()
# 2) simple file can be successfully built.
# If successful, saves target flags for this architecture.
macro(test_target_arch arch def)
+ string(RANDOM TARGET_${arch}_NAME)
+ set(TARGET_${arch}_NAME "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/cmTC_${TARGET_${arch}_NAME}.dir")
+ file(MAKE_DIRECTORY ${TARGET_${arch}_NAME})
+ if(SANITIZER_CXX_ABI_INTREE)
+ # We're using in tree C++ ABI, only test the C compiler for now.
+ set(TARGET_${arch}_FILENAME "${TARGET_${arch}_NAME}/CheckTarget.c")
+ file(WRITE "${TARGET_${arch}_FILENAME}" "#include <stdlib.h>\nint main() { void *p = malloc(1); return 0; }\n")
+ else()
+ # We're using the system C++ ABI, test that we can build C++ programs.
+ set(TARGET_${arch}_FILENAME "${TARGET_${arch}_NAME}/CheckTarget.cpp")
+ file(WRITE "${TARGET_${arch}_FILENAME}" "#include <new>\nint main() { int *p = new int; return 0; }\n")
+ endif()
+
set(TARGET_${arch}_CFLAGS ${ARGN})
set(TARGET_${arch}_LINK_FLAGS ${ARGN})
set(argstring "")
@@ -144,7 +157,7 @@ macro(test_target_arch arch def)
endif()
set(SAVED_CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS})
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${argstring}")
- try_compile(CAN_TARGET_${arch} ${CMAKE_BINARY_DIR} ${SIMPLE_SOURCE}
+ try_compile(CAN_TARGET_${arch} ${CMAKE_BINARY_DIR} ${TARGET_${arch}_FILENAME}
COMPILE_DEFINITIONS "${TARGET_${arch}_CFLAGS} ${FLAG_NO_EXCEPTIONS}"
OUTPUT_VARIABLE TARGET_${arch}_OUTPUT)
set(CMAKE_EXE_LINKER_FLAGS ${SAVED_CMAKE_EXE_LINKER_FLAGS})
@@ -157,6 +170,8 @@ macro(test_target_arch arch def)
# Bail out if we cannot target the architecture we plan to test.
message(FATAL_ERROR "Cannot compile for ${arch}:\n${TARGET_${arch}_OUTPUT}")
endif()
+
+ file(REMOVE_RECURSE ${TARGET_${arch}_NAME})
endmacro()
macro(detect_target_arch)