blob: fd117ac522cae9299eda13e9308e986487b9a6a3 [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 Samsonove16af952013-01-20 13:58:10 +000040# 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>
Alexey Samsonove5fa2432013-08-27 15:08:02 +000045# DEFS <compile definitions>)
Alexey Samsonove16af952013-01-20 13:58:10 +000046macro(add_compiler_rt_static_runtime name arch)
47 if(CAN_TARGET_${arch})
Alexey Samsonove5fa2432013-08-27 15:08:02 +000048 parse_arguments(LIB "SOURCES;CFLAGS;DEFS" "" ${ARGN})
Alexey Samsonove16af952013-01-20 13:58:10 +000049 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
Alexey Samsonov2aad7c12013-01-21 08:12:20 +000057 ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
Alexey Samsonove16af952013-01-20 13:58:10 +000058 # Add installation command.
59 install(TARGETS ${name}
60 ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
Alexey Samsonovc3494662013-10-01 12:52:15 +000061 add_dependencies(compiler-rt ${name})
Alexey Samsonove16af952013-01-20 13:58:10 +000062 else()
63 message(FATAL_ERROR "Archtecture ${arch} can't be targeted")
64 endif()
65endmacro()
66
Alexey Samsonov2aad7c12013-01-21 08:12:20 +000067# 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>)
73macro(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})
Alexey Samsonovc3494662013-10-01 12:52:15 +000084 add_dependencies(compiler-rt ${name})
Alexey Samsonov2aad7c12013-01-21 08:12:20 +000085endmacro()
86
Alexander Potapenko49496742013-11-07 10:08:19 +000087# Adds dynamic runtime library on osx/iossim, which supports multiple
88# architectures.
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>)
95macro(add_compiler_rt_darwin_dynamic_runtime name os)
Alexey Samsonov2aad7c12013-01-21 08:12:20 +000096 parse_arguments(LIB "ARCH;SOURCES;CFLAGS;DEFS;LINKFLAGS" "" ${ARGN})
97 add_library(${name} SHARED ${LIB_SOURCES})
Alexander Potapenko49496742013-11-07 10:08:19 +000098 set_target_compile_flags(${name} ${LIB_CFLAGS} ${DARWIN_${os}_CFLAGS})
99 set_target_link_flags(${name} ${LIB_LINKFLAGS} ${DARWIN_${os}_LINKFLAGS})
Alexey Samsonov2aad7c12013-01-21 08:12:20 +0000100 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})
Alexey Samsonovc3494662013-10-01 12:52:15 +0000107 add_dependencies(compiler-rt ${name})
Alexey Samsonov2aad7c12013-01-21 08:12:20 +0000108endmacro()
109
Alexey Samsonov392c50d2013-01-18 16:05:21 +0000110# Unittests support.
Alexey Samsonov02dcc632012-12-19 12:33:39 +0000111set(COMPILER_RT_GTEST_PATH ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest)
Chandler Carruthace53502013-11-15 10:21:15 +0000112set(COMPILER_RT_GTEST_SOURCE ${COMPILER_RT_GTEST_PATH}/src/gtest-all.cc)
Alexey Samsonov02dcc632012-12-19 12:33:39 +0000113set(COMPILER_RT_GTEST_INCLUDE_CFLAGS
114 -DGTEST_NO_LLVM_RAW_OSTREAM=1
115 -I${COMPILER_RT_GTEST_PATH}/include
Chandler Carruthace53502013-11-15 10:21:15 +0000116 -I${COMPILER_RT_GTEST_PATH}
Alexey Samsonov02dcc632012-12-19 12:33:39 +0000117)
118
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
121# test_suite.
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>)
126macro(add_compiler_rt_test test_suite test_name)
127 parse_arguments(TEST "OBJECTS;DEPS;LINK_FLAGS" "" ${ARGN})
Alexey Samsonovf6acafc2013-01-28 07:16:22 +0000128 set(output_bin "${CMAKE_CURRENT_BINARY_DIR}/${test_name}")
Alexey Samsonova74424e2013-01-28 09:07:30 +0000129 add_custom_target(${test_name}
Alexey Samsonov02dcc632012-12-19 12:33:39 +0000130 COMMAND clang ${TEST_OBJECTS} -o "${output_bin}"
131 ${TEST_LINK_FLAGS}
Alexey Samsonov32b89912012-12-21 08:56:14 +0000132 DEPENDS clang ${TEST_DEPS})
Alexey Samsonov02dcc632012-12-19 12:33:39 +0000133 # Make the test suite depend on the binary.
134 add_dependencies(${test_suite} ${test_name})
135endmacro()
Alexey Samsonovc1caace2013-05-21 13:48:27 +0000136
137macro(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})
145endmacro()