tsan: explain why pthread_cond_init() interceptor is commented out
[blocksruntime.git] / CMakeLists.txt
blob4544f15805efe4becf7da2ffe2ff75f5251e0014
1 # CMake build for CompilerRT.
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.
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.
10 include(LLVMParseArguments)
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)
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.
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.
24 if(CMAKE_SIZEOF_VOID_P EQUAL 4 OR LLVM_BUILD_32_BITS)
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()
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}")
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}")
51 function(filter_available_targets out_var)
52   set(archs)
53   foreach(arch ${ARGN})
54     if(${arch} STREQUAL "x86_64" AND CAN_TARGET_X86_64)
55       list(APPEND archs ${arch})
56     elseif (${arch} STREQUAL "i386" AND CAN_TARGET_I386)
57       list(APPEND archs ${arch})
58     endif()
59   endforeach()
60   set(${out_var} ${archs} PARENT_SCOPE)
61 endfunction()
63 # Provide some common commmandline flags for Sanitizer runtimes.
64 set(SANITIZER_COMMON_CFLAGS
65   -fPIC
66   -fno-builtin
67   -fno-exceptions
68   -fomit-frame-pointer
69   -funwind-tables
70   -O3
71   )
72 if(NOT WIN32)
73   list(APPEND SANITIZER_COMMON_CFLAGS -fvisibility=hidden)
74 endif()
75 # Build sanitizer runtimes with debug info.
76 check_cxx_compiler_flag(-gline-tables-only SUPPORTS_GLINE_TABLES_ONLY_FLAG)
77 if(SUPPORTS_GLINE_TABLES_ONLY_FLAG)
78   list(APPEND SANITIZER_COMMON_CFLAGS -gline-tables-only)
79 else()
80   list(APPEND SANITIZER_COMMON_CFLAGS -g)
81 endif()
82 # Warnings suppressions.
83 check_cxx_compiler_flag(-Wno-variadic-macros SUPPORTS_NO_VARIADIC_MACROS_FLAG)
84 if(SUPPORTS_NO_VARIADIC_MACROS_FLAG)
85   list(APPEND SANITIZER_COMMON_CFLAGS -Wno-variadic-macros)
86 endif()
87 check_cxx_compiler_flag(-Wno-c99-extensions SUPPORTS_NO_C99_EXTENSIONS_FLAG)
88 if(SUPPORTS_NO_C99_EXTENSIONS_FLAG)
89   list(APPEND SANITIZER_COMMON_CFLAGS -Wno-c99-extensions)
90 endif()
91 if(APPLE)
92   list(APPEND SANITIZER_COMMON_CFLAGS -mmacosx-version-min=10.5)
93 endif()
95 # Because compiler-rt spends a lot of time setting up custom compile flags,
96 # define a handy helper function for it. The compile flags setting in CMake
97 # has serious issues that make its syntax challenging at best.
98 function(set_target_compile_flags target)
99   foreach(arg ${ARGN})
100     set(argstring "${argstring} ${arg}")
101   endforeach()
102   set_property(TARGET ${target} PROPERTY COMPILE_FLAGS "${argstring}")
103 endfunction()
105 function(set_target_link_flags target)
106   foreach(arg ${ARGN})
107     set(argstring "${argstring} ${arg}")
108   endforeach()
109   set_property(TARGET ${target} PROPERTY LINK_FLAGS "${argstring}")
110 endfunction()
112 # Compute the Clang version from the LLVM version.
113 # FIXME: We should be able to reuse CLANG_VERSION variable calculated
114 #        in Clang cmake files, instead of copying the rules here.
115 string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION
116        ${PACKAGE_VERSION})
117 # Setup the paths where compiler-rt runtimes and headers should be stored.
118 set(LIBCLANG_INSTALL_PATH lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION})
119 string(TOLOWER ${CMAKE_SYSTEM_NAME} LIBCLANG_OS_DIR)
121 # Install compiler-rt headers.
122 install(DIRECTORY include/
123   DESTINATION ${LIBCLANG_INSTALL_PATH}/include
124   FILES_MATCHING
125   PATTERN "*.h"
126   PATTERN ".svn" EXCLUDE
127   )
129 # Call add_clang_compiler_rt_libraries to make sure that targets are built
130 # and installed in the directories where Clang driver expects to find them.
131 macro(add_clang_compiler_rt_libraries)
132   # Setup output directories so that clang in build tree works.
133   set_target_properties(${ARGN} PROPERTIES
134     ARCHIVE_OUTPUT_DIRECTORY
135       ${LLVM_BINARY_DIR}/lib/clang/${CLANG_VERSION}/lib/${LIBCLANG_OS_DIR}
136     LIBRARY_OUTPUT_DIRECTORY
137       ${LLVM_BINARY_DIR}/lib/clang/${CLANG_VERSION}/lib/${LIBCLANG_OS_DIR}
138     )
139   # Add installation command.
140   install(TARGETS ${ARGN}
141     ARCHIVE DESTINATION ${LIBCLANG_INSTALL_PATH}/lib/${LIBCLANG_OS_DIR}
142     LIBRARY DESTINATION ${LIBCLANG_INSTALL_PATH}/lib/${LIBCLANG_OS_DIR}
143     )
144 endmacro(add_clang_compiler_rt_libraries)
146 # Add the public header's directory to the includes for all of compiler-rt.
147 include_directories(include)
149 add_subdirectory(lib)
151 if(LLVM_INCLUDE_TESTS)
152   # Currently the tests have not been ported to CMake, so disable this
153   # directory.
154   #
155   #add_subdirectory(test)
156 endif()