2 include(LLVMParseArguments)
3 include(CompilerRTUtils)
5 # Tries to add "object library" target for a given architecture
6 # with name "<name>.<arch>" if architecture can be targeted.
7 # add_compiler_rt_object_library(<name> <arch>
8 # SOURCES <source files>
9 # CFLAGS <compile flags>
10 # DEFS <compile definitions>)
11 macro(add_compiler_rt_object_library name arch)
12 if(CAN_TARGET_${arch})
13 parse_arguments(LIB "SOURCES;CFLAGS;DEFS" "" ${ARGN})
14 add_library(${name}.${arch} OBJECT ${LIB_SOURCES})
15 set_target_compile_flags(${name}.${arch}
16 ${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS})
17 set_property(TARGET ${name}.${arch} APPEND PROPERTY
18 COMPILE_DEFINITIONS ${LIB_DEFS})
20 message(FATAL_ERROR "Archtecture ${arch} can't be targeted")
24 # Same as above, but adds universal osx library for either OSX or iOS simulator
25 # with name "<name>.<os>" targeting multiple architectures.
26 # add_compiler_rt_darwin_object_library(<name> <os> ARCH <architectures>
27 # SOURCES <source files>
28 # CFLAGS <compile flags>
29 # DEFS <compile definitions>)
30 macro(add_compiler_rt_darwin_object_library name os)
31 parse_arguments(LIB "ARCH;SOURCES;CFLAGS;DEFS" "" ${ARGN})
32 set(libname "${name}.${os}")
33 add_library(${libname} OBJECT ${LIB_SOURCES})
34 set_target_compile_flags(${libname} ${LIB_CFLAGS} ${DARWIN_${os}_CFLAGS})
35 set_target_properties(${libname} PROPERTIES OSX_ARCHITECTURES "${LIB_ARCH}")
36 set_property(TARGET ${libname} APPEND PROPERTY
37 COMPILE_DEFINITIONS ${LIB_DEFS})
40 # Adds static runtime for a given architecture and puts it in the proper
41 # directory in the build and install trees.
42 # add_compiler_rt_static_runtime(<name> <arch>
43 # SOURCES <source files>
44 # CFLAGS <compile flags>
45 # DEFS <compile definitions>)
46 macro(add_compiler_rt_static_runtime name arch)
47 if(CAN_TARGET_${arch})
48 parse_arguments(LIB "SOURCES;CFLAGS;DEFS" "" ${ARGN})
49 add_library(${name} STATIC ${LIB_SOURCES})
50 # Setup compile flags and definitions.
51 set_target_compile_flags(${name}
52 ${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS})
53 set_property(TARGET ${name} APPEND PROPERTY
54 COMPILE_DEFINITIONS ${LIB_DEFS})
55 # Setup correct output directory in the build tree.
56 set_target_properties(${name} PROPERTIES
57 ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
58 # Add installation command.
59 install(TARGETS ${name}
60 ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
61 add_dependencies(compiler-rt ${name})
63 message(FATAL_ERROR "Archtecture ${arch} can't be targeted")
67 # Same as add_compiler_rt_static_runtime, but creates a universal library
68 # for several architectures.
69 # add_compiler_rt_osx_static_runtime(<name> ARCH <architectures>
70 # SOURCES <source files>
71 # CFLAGS <compile flags>
72 # DEFS <compile definitions>)
73 macro(add_compiler_rt_osx_static_runtime name)
74 parse_arguments(LIB "ARCH;SOURCES;CFLAGS;DEFS" "" ${ARGN})
75 add_library(${name} STATIC ${LIB_SOURCES})
76 set_target_compile_flags(${name} ${LIB_CFLAGS})
77 set_property(TARGET ${name} APPEND PROPERTY
78 COMPILE_DEFINITIONS ${LIB_DEFS})
79 set_target_properties(${name} PROPERTIES
80 OSX_ARCHITECTURES "${LIB_ARCH}"
81 ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
82 install(TARGETS ${name}
83 ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
84 add_dependencies(compiler-rt ${name})
87 # Adds dynamic runtime library on osx/iossim, which supports multiple
89 # add_compiler_rt_darwin_dynamic_runtime(<name> <os>
90 # ARCH <architectures>
91 # SOURCES <source files>
92 # CFLAGS <compile flags>
93 # DEFS <compile definitions>
94 # LINKFLAGS <link flags>)
95 macro(add_compiler_rt_darwin_dynamic_runtime name os)
96 parse_arguments(LIB "ARCH;SOURCES;CFLAGS;DEFS;LINKFLAGS" "" ${ARGN})
97 add_library(${name} SHARED ${LIB_SOURCES})
98 set_target_compile_flags(${name} ${LIB_CFLAGS} ${DARWIN_${os}_CFLAGS})
99 set_target_link_flags(${name} ${LIB_LINKFLAGS} ${DARWIN_${os}_LINKFLAGS})
100 set_property(TARGET ${name} APPEND PROPERTY
101 COMPILE_DEFINITIONS ${LIB_DEFS})
102 set_target_properties(${name} PROPERTIES
103 OSX_ARCHITECTURES "${LIB_ARCH}"
104 LIBRARY_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
105 install(TARGETS ${name}
106 LIBRARY DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
107 add_dependencies(compiler-rt ${name})
111 set(COMPILER_RT_GTEST_PATH ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest)
112 set(COMPILER_RT_GTEST_SOURCE ${COMPILER_RT_GTEST_PATH}/src/gtest-all.cc)
113 set(COMPILER_RT_GTEST_INCLUDE_CFLAGS
114 -DGTEST_NO_LLVM_RAW_OSTREAM=1
115 -I${COMPILER_RT_GTEST_PATH}/include
116 -I${COMPILER_RT_GTEST_PATH}
119 # Use Clang to link objects into a single executable with just-built
120 # Clang, using specific link flags. Make executable a part of provided
122 # add_compiler_rt_test(<test_suite> <test_name>
123 # OBJECTS <object files>
124 # DEPS <deps (e.g. runtime libs)>
125 # LINK_FLAGS <link flags>)
126 macro(add_compiler_rt_test test_suite test_name)
127 parse_arguments(TEST "OBJECTS;DEPS;LINK_FLAGS" "" ${ARGN})
128 set(output_bin "${CMAKE_CURRENT_BINARY_DIR}/${test_name}")
129 add_custom_target(${test_name}
130 COMMAND clang ${TEST_OBJECTS} -o "${output_bin}"
132 DEPENDS clang ${TEST_DEPS})
133 # Make the test suite depend on the binary.
134 add_dependencies(${test_suite} ${test_name})
137 macro(add_compiler_rt_resource_file target_name file_name)
138 set(src_file "${CMAKE_CURRENT_SOURCE_DIR}/${file_name}")
139 set(dst_file "${CLANG_RESOURCE_DIR}/${file_name}")
140 add_custom_target(${target_name}
141 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src_file} ${dst_file}
142 DEPENDS ${file_name})
143 # Install in Clang resource directory.
144 install(FILES ${file_name} DESTINATION ${LIBCLANG_INSTALL_PATH})