blob: 9bdd9726de41573ef8d3a03d86a389eaa12fecb9 [file] [log] [blame]
Chandler Carruthd51e0a02012-04-04 22:12:04 +00001# 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
10include(LLVMParseArguments)
11
12# FIXME: Below we assume that the target build of LLVM/Clang is x86, which is
13# not at all valid. Much of this can be fixed just by switching to use
14# a just-built-clang binary for the compiles.
15
16# Detect whether the current target platform is 32-bit or 64-bit, and setup
17# the correct commandline flags needed to attempt to target 32-bit and 64-bit.
18if(CMAKE_SIZEOF_VOID_P EQUAL 4)
19 set(TARGET_X86_64_CFLAGS "-m64")
20 set(TARGET_I386_CFLAGS "")
21else()
22 if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
23 message(FATAL_ERROR "Please use a sane architecture with 4 or 8 byte pointers.")
24 endif()
25 set(TARGET_X86_64_CFLAGS "")
26 set(TARGET_I386_CFLAGS "-m32")
27endif()
28
29# Try to compile a very simple source file to ensure we can target the given
30# platform. We use the results of these tests to build only the various target
31# runtime libraries supported by our current compilers cross-compiling
32# abilities.
33set(SIMPLE_SOURCE64 ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/simple64.c)
34file(WRITE ${SIMPLE_SOURCE64} "#include <stdlib.h>\nint main() {}")
35try_compile(CAN_TARGET_X86_64 ${CMAKE_BINARY_DIR} ${SIMPLE_SOURCE64}
36 COMPILE_DEFINITIONS "${TARGET_X86_64_CFLAGS}"
37 CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS:STRING=${TARGET_X86_64_CFLAGS}")
38
39set(SIMPLE_SOURCE32 ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/simple32.c)
40file(WRITE ${SIMPLE_SOURCE32} "#include <stdlib.h>\nint main() {}")
41try_compile(CAN_TARGET_I386 ${CMAKE_BINARY_DIR} ${SIMPLE_SOURCE32}
42 COMPILE_DEFINITIONS "${TARGET_I386_CFLAGS}"
43 CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS:STRING=${TARGET_I386_CFLAGS}")
44
45add_subdirectory(lib)
46
47if(LLVM_INCLUDE_TESTS)
48 add_subdirectory(test)
49endif()