Chandler Carruth | d51e0a0 | 2012-04-04 22:12:04 +0000 | [diff] [blame] | 1 | # CMake build for CompilerRT. |
| 2 | # |
| 3 | # This build assumes that CompilerRT is checked out into the |
| 4 | # 'projects/compiler-rt' inside of an LLVM tree, it is not a stand-alone build |
| 5 | # system. |
| 6 | # |
| 7 | # An important constraint of the build is that it only produces libraries |
| 8 | # based on the ability of the host toolchain to target various platforms. |
| 9 | |
| 10 | include(LLVMParseArguments) |
| 11 | |
Chandler Carruth | a765ffc | 2012-06-25 08:40:10 +0000 | [diff] [blame] | 12 | # The CompilerRT build system requires CMake version 2.8.8 or higher in order |
| 13 | # to use its support for building convenience "libraries" as a collection of |
| 14 | # .o files. This is particularly useful in producing larger, more complex |
| 15 | # runtime libraries. |
| 16 | cmake_minimum_required(VERSION 2.8.8) |
| 17 | |
Chandler Carruth | d51e0a0 | 2012-04-04 22:12:04 +0000 | [diff] [blame] | 18 | # FIXME: Below we assume that the target build of LLVM/Clang is x86, which is |
| 19 | # not at all valid. Much of this can be fixed just by switching to use |
| 20 | # a just-built-clang binary for the compiles. |
| 21 | |
| 22 | # Detect whether the current target platform is 32-bit or 64-bit, and setup |
| 23 | # the correct commandline flags needed to attempt to target 32-bit and 64-bit. |
Alexey Samsonov | bd17004 | 2012-08-07 12:14:29 +0000 | [diff] [blame^] | 24 | if(CMAKE_SIZEOF_VOID_P EQUAL 4 OR LLVM_BUILD_32_BITS) |
Chandler Carruth | d51e0a0 | 2012-04-04 22:12:04 +0000 | [diff] [blame] | 25 | set(TARGET_X86_64_CFLAGS "-m64") |
| 26 | set(TARGET_I386_CFLAGS "") |
| 27 | else() |
| 28 | if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8) |
| 29 | message(FATAL_ERROR "Please use a sane architecture with 4 or 8 byte pointers.") |
| 30 | endif() |
| 31 | set(TARGET_X86_64_CFLAGS "") |
| 32 | set(TARGET_I386_CFLAGS "-m32") |
| 33 | endif() |
| 34 | |
| 35 | # Try to compile a very simple source file to ensure we can target the given |
| 36 | # platform. We use the results of these tests to build only the various target |
| 37 | # runtime libraries supported by our current compilers cross-compiling |
| 38 | # abilities. |
| 39 | set(SIMPLE_SOURCE64 ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/simple64.c) |
| 40 | file(WRITE ${SIMPLE_SOURCE64} "#include <stdlib.h>\nint main() {}") |
| 41 | try_compile(CAN_TARGET_X86_64 ${CMAKE_BINARY_DIR} ${SIMPLE_SOURCE64} |
| 42 | COMPILE_DEFINITIONS "${TARGET_X86_64_CFLAGS}" |
| 43 | CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS:STRING=${TARGET_X86_64_CFLAGS}") |
| 44 | |
| 45 | set(SIMPLE_SOURCE32 ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/simple32.c) |
| 46 | file(WRITE ${SIMPLE_SOURCE32} "#include <stdlib.h>\nint main() {}") |
| 47 | try_compile(CAN_TARGET_I386 ${CMAKE_BINARY_DIR} ${SIMPLE_SOURCE32} |
| 48 | COMPILE_DEFINITIONS "${TARGET_I386_CFLAGS}" |
| 49 | CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS:STRING=${TARGET_I386_CFLAGS}") |
| 50 | |
Chandler Carruth | 984f6cf | 2012-06-27 09:01:24 +0000 | [diff] [blame] | 51 | # Because compiler-rt spends a lot of time setting up custom compile flags, |
| 52 | # define a handy helper function for it. The compile flags setting in CMake |
| 53 | # has serious issues that make its syntax challenging at best. |
| 54 | function(set_target_compile_flags target) |
| 55 | foreach(arg ${ARGN}) |
| 56 | set(argstring "${argstring} ${arg}") |
| 57 | endforeach() |
| 58 | set_property(TARGET ${target} PROPERTY COMPILE_FLAGS "${argstring}") |
| 59 | endfunction() |
| 60 | |
Chandler Carruth | d51e0a0 | 2012-04-04 22:12:04 +0000 | [diff] [blame] | 61 | add_subdirectory(lib) |
| 62 | |
| 63 | if(LLVM_INCLUDE_TESTS) |
Chandler Carruth | 2e82a8b | 2012-06-22 20:17:27 +0000 | [diff] [blame] | 64 | # Currently the tests have not been ported to CMake, so disable this |
| 65 | # directory. |
| 66 | # |
| 67 | #add_subdirectory(test) |
Chandler Carruth | d51e0a0 | 2012-04-04 22:12:04 +0000 | [diff] [blame] | 68 | endif() |