blob: 556ada48ae793b47cfe0f0d7fd8c129a63f117f8 [file] [log] [blame]
Alexey Samsonov02dcc632012-12-19 12:33:39 +00001include(AddLLVM)
2include(LLVMParseArguments)
Alexey Samsonov392c50d2013-01-18 16:05:21 +00003include(CompilerRTUtils)
Alexey Samsonov02dcc632012-12-19 12:33:39 +00004
Alexey Samsonov392c50d2013-01-18 16:05:21 +00005# 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>
Alexey Samsonov05fa3802013-09-16 15:50:53 +00009# CFLAGS <compile flags>
10# DEFS <compile definitions>)
Alexey Samsonov392c50d2013-01-18 16:05:21 +000011macro(add_compiler_rt_object_library name arch)
12 if(CAN_TARGET_${arch})
Alexey Samsonov05fa3802013-09-16 15:50:53 +000013 parse_arguments(LIB "SOURCES;CFLAGS;DEFS" "" ${ARGN})
Alexey Samsonov392c50d2013-01-18 16:05:21 +000014 add_library(${name}.${arch} OBJECT ${LIB_SOURCES})
15 set_target_compile_flags(${name}.${arch}
16 ${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS})
Alexey Samsonov05fa3802013-09-16 15:50:53 +000017 set_property(TARGET ${name}.${arch} APPEND PROPERTY
18 COMPILE_DEFINITIONS ${LIB_DEFS})
Alexey Samsonov392c50d2013-01-18 16:05:21 +000019 else()
20 message(FATAL_ERROR "Archtecture ${arch} can't be targeted")
21 endif()
22endmacro()
23
Alexander Potapenko49496742013-11-07 10:08:19 +000024# 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>)
30macro(add_compiler_rt_darwin_object_library name os)
Alexey Samsonov05fa3802013-09-16 15:50:53 +000031 parse_arguments(LIB "ARCH;SOURCES;CFLAGS;DEFS" "" ${ARGN})
Alexander Potapenko49496742013-11-07 10:08:19 +000032 set(libname "${name}.${os}")
Alexey Samsonov51623142013-01-20 14:36:12 +000033 add_library(${libname} OBJECT ${LIB_SOURCES})
Alexander Potapenko49496742013-11-07 10:08:19 +000034 set_target_compile_flags(${libname} ${LIB_CFLAGS} ${DARWIN_${os}_CFLAGS})
Alexey Samsonov2aad7c12013-01-21 08:12:20 +000035 set_target_properties(${libname} PROPERTIES OSX_ARCHITECTURES "${LIB_ARCH}")
Alexey Samsonov05fa3802013-09-16 15:50:53 +000036 set_property(TARGET ${libname} APPEND PROPERTY
37 COMPILE_DEFINITIONS ${LIB_DEFS})
Alexey Samsonov51623142013-01-20 14:36:12 +000038endmacro()
39
Alexey Samsonove18b7852014-03-31 13:45:36 +000040# Adds static or shared runtime for a given architecture and puts it in the
41# proper directory in the build and install trees.
42# add_compiler_rt_runtime(<name> <arch> {STATIC,SHARED}
43# SOURCES <source files>
44# CFLAGS <compile flags>
45# DEFS <compile definitions>)
46macro(add_compiler_rt_runtime name arch type)
Alexey Samsonove16af952013-01-20 13:58:10 +000047 if(CAN_TARGET_${arch})
Alexey Samsonove5fa2432013-08-27 15:08:02 +000048 parse_arguments(LIB "SOURCES;CFLAGS;DEFS" "" ${ARGN})
Alexey Samsonove18b7852014-03-31 13:45:36 +000049 add_library(${name} ${type} ${LIB_SOURCES})
Alexey Samsonove16af952013-01-20 13:58:10 +000050 # Setup compile flags and definitions.
51 set_target_compile_flags(${name}
52 ${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS})
Alexey Samsonove18b7852014-03-31 13:45:36 +000053 set_target_link_flags(${name}
54 ${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS})
Alexey Samsonove16af952013-01-20 13:58:10 +000055 set_property(TARGET ${name} APPEND PROPERTY
56 COMPILE_DEFINITIONS ${LIB_DEFS})
57 # Setup correct output directory in the build tree.
58 set_target_properties(${name} PROPERTIES
Alexey Samsonove18b7852014-03-31 13:45:36 +000059 ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
60 LIBRARY_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
Alexey Samsonove16af952013-01-20 13:58:10 +000061 # Add installation command.
62 install(TARGETS ${name}
Alexey Samsonove18b7852014-03-31 13:45:36 +000063 ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}
64 LIBRARY DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
Alexey Samsonove16af952013-01-20 13:58:10 +000065 else()
66 message(FATAL_ERROR "Archtecture ${arch} can't be targeted")
67 endif()
68endmacro()
69
Alexey Samsonove18b7852014-03-31 13:45:36 +000070# Same as add_compiler_rt_runtime(... STATIC), but creates a universal library
Alexey Samsonov2aad7c12013-01-21 08:12:20 +000071# for several architectures.
72# add_compiler_rt_osx_static_runtime(<name> ARCH <architectures>
73# SOURCES <source files>
74# CFLAGS <compile flags>
75# DEFS <compile definitions>)
76macro(add_compiler_rt_osx_static_runtime name)
77 parse_arguments(LIB "ARCH;SOURCES;CFLAGS;DEFS" "" ${ARGN})
78 add_library(${name} STATIC ${LIB_SOURCES})
79 set_target_compile_flags(${name} ${LIB_CFLAGS})
80 set_property(TARGET ${name} APPEND PROPERTY
81 COMPILE_DEFINITIONS ${LIB_DEFS})
82 set_target_properties(${name} PROPERTIES
83 OSX_ARCHITECTURES "${LIB_ARCH}"
84 ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
85 install(TARGETS ${name}
86 ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
87endmacro()
88
Alexander Potapenko49496742013-11-07 10:08:19 +000089# Adds dynamic runtime library on osx/iossim, which supports multiple
90# architectures.
91# add_compiler_rt_darwin_dynamic_runtime(<name> <os>
92# ARCH <architectures>
93# SOURCES <source files>
94# CFLAGS <compile flags>
95# DEFS <compile definitions>
96# LINKFLAGS <link flags>)
97macro(add_compiler_rt_darwin_dynamic_runtime name os)
Alexey Samsonov2aad7c12013-01-21 08:12:20 +000098 parse_arguments(LIB "ARCH;SOURCES;CFLAGS;DEFS;LINKFLAGS" "" ${ARGN})
99 add_library(${name} SHARED ${LIB_SOURCES})
Alexander Potapenko49496742013-11-07 10:08:19 +0000100 set_target_compile_flags(${name} ${LIB_CFLAGS} ${DARWIN_${os}_CFLAGS})
101 set_target_link_flags(${name} ${LIB_LINKFLAGS} ${DARWIN_${os}_LINKFLAGS})
Alexey Samsonov2aad7c12013-01-21 08:12:20 +0000102 set_property(TARGET ${name} APPEND PROPERTY
103 COMPILE_DEFINITIONS ${LIB_DEFS})
104 set_target_properties(${name} PROPERTIES
105 OSX_ARCHITECTURES "${LIB_ARCH}"
106 LIBRARY_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
107 install(TARGETS ${name}
108 LIBRARY DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
109endmacro()
110
Alexey Samsonov392c50d2013-01-18 16:05:21 +0000111# Unittests support.
Alexey Samsonov02dcc632012-12-19 12:33:39 +0000112set(COMPILER_RT_GTEST_PATH ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest)
Chandler Carruthace53502013-11-15 10:21:15 +0000113set(COMPILER_RT_GTEST_SOURCE ${COMPILER_RT_GTEST_PATH}/src/gtest-all.cc)
Alexey Samsonov1e5d8be2014-03-24 13:29:20 +0000114set(COMPILER_RT_GTEST_CFLAGS
Alexey Samsonov02dcc632012-12-19 12:33:39 +0000115 -DGTEST_NO_LLVM_RAW_OSTREAM=1
116 -I${COMPILER_RT_GTEST_PATH}/include
Chandler Carruthace53502013-11-15 10:21:15 +0000117 -I${COMPILER_RT_GTEST_PATH}
Alexey Samsonov02dcc632012-12-19 12:33:39 +0000118)
119
Alexey Samsonov17cf7c52014-02-19 13:01:03 +0000120# Link objects into a single executable with COMPILER_RT_TEST_COMPILER,
121# using specified link flags. Make executable a part of provided
Alexey Samsonov02dcc632012-12-19 12:33:39 +0000122# test_suite.
123# add_compiler_rt_test(<test_suite> <test_name>
124# OBJECTS <object files>
125# DEPS <deps (e.g. runtime libs)>
126# LINK_FLAGS <link flags>)
127macro(add_compiler_rt_test test_suite test_name)
128 parse_arguments(TEST "OBJECTS;DEPS;LINK_FLAGS" "" ${ARGN})
Alexey Samsonovf6acafc2013-01-28 07:16:22 +0000129 set(output_bin "${CMAKE_CURRENT_BINARY_DIR}/${test_name}")
Alexey Samsonov17cf7c52014-02-19 13:01:03 +0000130 # Use host compiler in a standalone build, and just-built Clang otherwise.
131 if(NOT COMPILER_RT_STANDALONE_BUILD)
132 list(APPEND TEST_DEPS clang)
133 endif()
Alexey Samsonova74424e2013-01-28 09:07:30 +0000134 add_custom_target(${test_name}
Alexey Samsonov17cf7c52014-02-19 13:01:03 +0000135 COMMAND ${COMPILER_RT_TEST_COMPILER} ${TEST_OBJECTS} -o "${output_bin}"
Alexey Samsonov02dcc632012-12-19 12:33:39 +0000136 ${TEST_LINK_FLAGS}
Alexey Samsonov17cf7c52014-02-19 13:01:03 +0000137 DEPENDS ${TEST_DEPS})
Alexey Samsonov02dcc632012-12-19 12:33:39 +0000138 # Make the test suite depend on the binary.
139 add_dependencies(${test_suite} ${test_name})
140endmacro()
Alexey Samsonovc1caace2013-05-21 13:48:27 +0000141
142macro(add_compiler_rt_resource_file target_name file_name)
143 set(src_file "${CMAKE_CURRENT_SOURCE_DIR}/${file_name}")
Alexey Samsonova52e2dc2014-02-18 14:28:53 +0000144 set(dst_file "${COMPILER_RT_OUTPUT_DIR}/${file_name}")
Alexey Samsonov41bf0bc2014-02-27 07:22:59 +0000145 add_custom_command(OUTPUT ${dst_file}
146 DEPENDS ${src_file}
Alexey Samsonovc1caace2013-05-21 13:48:27 +0000147 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src_file} ${dst_file}
Alexey Samsonov41bf0bc2014-02-27 07:22:59 +0000148 COMMENT "Copying ${file_name}...")
149 add_custom_target(${target_name} DEPENDS ${dst_file})
Alexey Samsonovc1caace2013-05-21 13:48:27 +0000150 # Install in Clang resource directory.
Alexey Samsonova52e2dc2014-02-18 14:28:53 +0000151 install(FILES ${file_name} DESTINATION ${COMPILER_RT_INSTALL_PATH})
Alexey Samsonovc1caace2013-05-21 13:48:27 +0000152endmacro()
Evgeniy Stepanov9514ed12014-02-27 08:41:40 +0000153
154macro(add_compiler_rt_script name)
155 set(dst ${COMPILER_RT_EXEC_OUTPUT_DIR}/${name})
156 set(src ${CMAKE_CURRENT_SOURCE_DIR}/${name})
157 add_custom_command(OUTPUT ${dst}
158 DEPENDS ${src}
159 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst}
160 COMMENT "Copying ${name}...")
161 add_custom_target(${name} DEPENDS ${dst})
162 install(FILES ${dst}
163 PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
164 DESTINATION ${COMPILER_RT_INSTALL_PATH}/bin)
165endmacro(add_compiler_rt_script src name)