Alexey Samsonov | ca7fcf2 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 1 | include(LLVMParseArguments) |
| 2 | |
Alexey Samsonov | 150d62a | 2014-02-19 13:01:03 +0000 | [diff] [blame] | 3 | # Compile a source into an object file with COMPILER_RT_TEST_COMPILER using |
Alexey Samsonov | ca7fcf2 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 4 | # a provided compile flags and dependenices. |
| 5 | # clang_compile(<object> <source> |
| 6 | # CFLAGS <list of compile flags> |
| 7 | # DEPS <list of dependencies>) |
| 8 | macro(clang_compile object_file source) |
| 9 | parse_arguments(SOURCE "CFLAGS;DEPS" "" ${ARGN}) |
| 10 | get_filename_component(source_rpath ${source} REALPATH) |
Alexey Samsonov | 150d62a | 2014-02-19 13:01:03 +0000 | [diff] [blame] | 11 | if(NOT COMPILER_RT_STANDALONE_BUILD) |
Alexey Samsonov | 6239ebc | 2015-01-06 20:58:40 +0000 | [diff] [blame^] | 12 | list(APPEND SOURCE_DEPS clang compiler-rt-headers) |
Alexey Samsonov | 150d62a | 2014-02-19 13:01:03 +0000 | [diff] [blame] | 13 | endif() |
Kuba Brecka | fa2de77 | 2014-09-10 17:23:58 +0000 | [diff] [blame] | 14 | if (TARGET CompilerRTUnitTestCheckCxx) |
| 15 | list(APPEND SOURCE_DEPS CompilerRTUnitTestCheckCxx) |
| 16 | endif() |
Alexey Samsonov | 1847401 | 2014-03-24 09:42:12 +0000 | [diff] [blame] | 17 | string(REGEX MATCH "[.](cc|cpp)$" is_cxx ${source_rpath}) |
| 18 | if(is_cxx) |
| 19 | string(REPLACE " " ";" global_flags "${CMAKE_CXX_FLAGS}") |
| 20 | else() |
| 21 | string(REPLACE " " ";" global_flags "${CMAKE_C_FLAGS}") |
| 22 | endif() |
Timur Iskhodzhanov | 82ee043 | 2014-05-28 08:38:13 +0000 | [diff] [blame] | 23 | # On Windows, CMAKE_*_FLAGS are built for MSVC but we use the GCC clang.exe |
| 24 | # which doesn't support flags starting with "/smth". Replace those with |
| 25 | # "-smth" equivalents. |
| 26 | if(MSVC) |
| 27 | string(REGEX REPLACE "^/" "-" global_flags "${global_flags}") |
| 28 | string(REPLACE ";/" ";-" global_flags "${global_flags}") |
| 29 | endif() |
Alexey Samsonov | 1847401 | 2014-03-24 09:42:12 +0000 | [diff] [blame] | 30 | # Ignore unknown warnings. CMAKE_CXX_FLAGS may contain GCC-specific options |
| 31 | # which are not supported by Clang. |
| 32 | list(APPEND global_flags -Wno-unknown-warning-option) |
| 33 | set(compile_flags ${global_flags} ${SOURCE_CFLAGS}) |
Alexey Samsonov | ca7fcf2 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 34 | add_custom_command( |
| 35 | OUTPUT ${object_file} |
Timur Iskhodzhanov | b0279d7 | 2014-05-12 08:55:20 +0000 | [diff] [blame] | 36 | COMMAND ${COMPILER_RT_TEST_COMPILER} ${compile_flags} -c |
Timur Iskhodzhanov | 82ee043 | 2014-05-28 08:38:13 +0000 | [diff] [blame] | 37 | -o "${object_file}" |
Alexey Samsonov | 150d62a | 2014-02-19 13:01:03 +0000 | [diff] [blame] | 38 | ${source_rpath} |
Alexey Samsonov | ca7fcf2 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 39 | MAIN_DEPENDENCY ${source} |
Alexey Samsonov | 150d62a | 2014-02-19 13:01:03 +0000 | [diff] [blame] | 40 | DEPENDS ${SOURCE_DEPS}) |
Alexey Samsonov | ca7fcf2 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 41 | endmacro() |
Kuba Brecka | fa2de77 | 2014-09-10 17:23:58 +0000 | [diff] [blame] | 42 | |
| 43 | # On Darwin, there are no system-wide C++ headers and the just-built clang is |
| 44 | # therefore not able to compile C++ files unless they are copied/symlinked into |
| 45 | # ${LLVM_BINARY_DIR}/include/c++ |
| 46 | # The just-built clang is used to build compiler-rt unit tests. Let's detect |
| 47 | # this before we try to build the tests and print out a suggestion how to fix |
| 48 | # it. |
| 49 | # On other platforms, this is currently not an issue. |
| 50 | macro(clang_compiler_add_cxx_check) |
| 51 | if (APPLE) |
| 52 | set(CMD |
| 53 | "echo '#include <iostream>' | ${COMPILER_RT_TEST_COMPILER} -E -x c++ - > /dev/null" |
| 54 | "if [ $? != 0 ] " |
| 55 | " then echo" |
| 56 | " echo 'Your just-built clang cannot find C++ headers, which are needed to build and run compiler-rt tests.'" |
| 57 | " echo 'You should copy or symlink your system C++ headers into ${LLVM_BINARY_DIR}/include/c++'" |
| 58 | " if [ -d $(dirname $(dirname $(xcrun -f clang)))/include/c++ ]" |
| 59 | " then echo 'e.g. with:'" |
| 60 | " echo ' cp -r' $(dirname $(dirname $(xcrun -f clang)))/include/c++ '${LLVM_BINARY_DIR}/include/'" |
| 61 | " elif [ -d $(dirname $(dirname $(xcrun -f clang)))/lib/c++ ]" |
| 62 | " then echo 'e.g. with:'" |
| 63 | " echo ' cp -r' $(dirname $(dirname $(xcrun -f clang)))/lib/c++ '${LLVM_BINARY_DIR}/include/'" |
| 64 | " fi" |
| 65 | " echo 'This can also be fixed by checking out the libcxx project from llvm.org and installing the headers'" |
| 66 | " echo 'into your build directory:'" |
| 67 | " echo ' cd ${LLVM_SOURCE_DIR}/projects && svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx'" |
| 68 | " echo ' cd ${LLVM_BINARY_DIR} && make -C ${LLVM_SOURCE_DIR}/projects/libcxx installheaders HEADER_DIR=${LLVM_BINARY_DIR}/include'" |
| 69 | " echo" |
| 70 | " false" |
| 71 | "fi" |
| 72 | ) |
| 73 | add_custom_target(CompilerRTUnitTestCheckCxx |
| 74 | COMMAND bash -c "${CMD}" |
| 75 | COMMENT "Checking that just-built clang can find C++ headers..." |
Kuba Brecka | fa2de77 | 2014-09-10 17:23:58 +0000 | [diff] [blame] | 76 | VERBATIM) |
Alexander Potapenko | bc4ce3a | 2014-09-25 09:30:05 +0000 | [diff] [blame] | 77 | if (TARGET clang) |
| 78 | ADD_DEPENDENCIES(CompilerRTUnitTestCheckCxx clang) |
| 79 | endif() |
Kuba Brecka | fa2de77 | 2014-09-10 17:23:58 +0000 | [diff] [blame] | 80 | endif() |
| 81 | endmacro() |