blob: bf114a401ef063ce500861bb162a9e4a4e8c67ff [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>
9# CFLAGS <compile flags>)
10macro(add_compiler_rt_object_library name arch)
11 if(CAN_TARGET_${arch})
12 parse_arguments(LIB "SOURCES;CFLAGS" "" ${ARGN})
13 add_library(${name}.${arch} OBJECT ${LIB_SOURCES})
14 set_target_compile_flags(${name}.${arch}
15 ${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS})
16 else()
17 message(FATAL_ERROR "Archtecture ${arch} can't be targeted")
18 endif()
19endmacro()
20
Alexey Samsonov51623142013-01-20 14:36:12 +000021# Same as above, but adds universal osx library with name "<name>.osx"
22# targeting multiple architectures.
23# add_compiler_rt_osx_object_library(<name> ARCH <architectures>
24# SOURCES <source files>
25# CFLAGS <compile flags>)
26macro(add_compiler_rt_osx_object_library name)
27 parse_arguments(LIB "ARCH;SOURCES;CFLAGS" "" ${ARGN})
28 set(libname "${name}.osx")
29 add_library(${libname} OBJECT ${LIB_SOURCES})
30 set_target_compile_flags(${libname} ${LIB_CFLAGS})
Alexey Samsonov2aad7c12013-01-21 08:12:20 +000031 set_target_properties(${libname} PROPERTIES OSX_ARCHITECTURES "${LIB_ARCH}")
Alexey Samsonov51623142013-01-20 14:36:12 +000032endmacro()
33
Alexey Samsonove16af952013-01-20 13:58:10 +000034# Adds static runtime for a given architecture and puts it in the proper
35# directory in the build and install trees.
36# add_compiler_rt_static_runtime(<name> <arch>
37# SOURCES <source files>
38# CFLAGS <compile flags>
Richard Smitha06fe912013-03-23 00:31:07 +000039# DEFS <compile definitions>
40# SYMS <symbols file>)
Alexey Samsonove16af952013-01-20 13:58:10 +000041macro(add_compiler_rt_static_runtime name arch)
42 if(CAN_TARGET_${arch})
Richard Smitha06fe912013-03-23 00:31:07 +000043 parse_arguments(LIB "SOURCES;CFLAGS;DEFS;SYMS" "" ${ARGN})
Alexey Samsonove16af952013-01-20 13:58:10 +000044 add_library(${name} STATIC ${LIB_SOURCES})
45 # Setup compile flags and definitions.
46 set_target_compile_flags(${name}
47 ${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS})
48 set_property(TARGET ${name} APPEND PROPERTY
49 COMPILE_DEFINITIONS ${LIB_DEFS})
50 # Setup correct output directory in the build tree.
51 set_target_properties(${name} PROPERTIES
Alexey Samsonov2aad7c12013-01-21 08:12:20 +000052 ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
Alexey Samsonove16af952013-01-20 13:58:10 +000053 # Add installation command.
54 install(TARGETS ${name}
55 ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
Richard Smitha06fe912013-03-23 00:31:07 +000056 # Generate the .syms file if possible.
57 if(LIB_SYMS)
58 get_target_property(libfile ${name} LOCATION)
59 configure_file(${LIB_SYMS} ${libfile}.syms)
60 install(FILES ${libfile}.syms
61 DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
62 endif(LIB_SYMS)
Alexey Samsonove16af952013-01-20 13:58:10 +000063 else()
64 message(FATAL_ERROR "Archtecture ${arch} can't be targeted")
65 endif()
66endmacro()
67
Alexey Samsonov2aad7c12013-01-21 08:12:20 +000068# Same as add_compiler_rt_static_runtime, but creates a universal library
69# for several architectures.
70# add_compiler_rt_osx_static_runtime(<name> ARCH <architectures>
71# SOURCES <source files>
72# CFLAGS <compile flags>
73# DEFS <compile definitions>)
74macro(add_compiler_rt_osx_static_runtime name)
75 parse_arguments(LIB "ARCH;SOURCES;CFLAGS;DEFS" "" ${ARGN})
76 add_library(${name} STATIC ${LIB_SOURCES})
77 set_target_compile_flags(${name} ${LIB_CFLAGS})
78 set_property(TARGET ${name} APPEND PROPERTY
79 COMPILE_DEFINITIONS ${LIB_DEFS})
80 set_target_properties(${name} PROPERTIES
81 OSX_ARCHITECTURES "${LIB_ARCH}"
82 ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
83 install(TARGETS ${name}
84 ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
85endmacro()
86
87# Adds dynamic runtime library on osx, which supports multiple architectures.
88# add_compiler_rt_osx_dynamic_runtime(<name> ARCH <architectures>
89# SOURCES <source files>
90# CFLAGS <compile flags>
91# DEFS <compile definitions>
92# LINKFLAGS <link flags>)
93macro(add_compiler_rt_osx_dynamic_runtime name)
94 parse_arguments(LIB "ARCH;SOURCES;CFLAGS;DEFS;LINKFLAGS" "" ${ARGN})
95 add_library(${name} SHARED ${LIB_SOURCES})
96 set_target_compile_flags(${name} ${LIB_CFLAGS})
97 set_target_link_flags(${name} ${LIB_LINKFLAGS})
98 set_property(TARGET ${name} APPEND PROPERTY
99 COMPILE_DEFINITIONS ${LIB_DEFS})
100 set_target_properties(${name} PROPERTIES
101 OSX_ARCHITECTURES "${LIB_ARCH}"
102 LIBRARY_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
103 install(TARGETS ${name}
104 LIBRARY DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
105endmacro()
106
Alexey Samsonov392c50d2013-01-18 16:05:21 +0000107# Unittests support.
Alexey Samsonov02dcc632012-12-19 12:33:39 +0000108set(COMPILER_RT_GTEST_PATH ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest)
109set(COMPILER_RT_GTEST_SOURCE ${COMPILER_RT_GTEST_PATH}/gtest-all.cc)
110set(COMPILER_RT_GTEST_INCLUDE_CFLAGS
111 -DGTEST_NO_LLVM_RAW_OSTREAM=1
112 -I${COMPILER_RT_GTEST_PATH}/include
113)
114
115# Use Clang to link objects into a single executable with just-built
116# Clang, using specific link flags. Make executable a part of provided
117# test_suite.
118# add_compiler_rt_test(<test_suite> <test_name>
119# OBJECTS <object files>
120# DEPS <deps (e.g. runtime libs)>
121# LINK_FLAGS <link flags>)
122macro(add_compiler_rt_test test_suite test_name)
123 parse_arguments(TEST "OBJECTS;DEPS;LINK_FLAGS" "" ${ARGN})
Alexey Samsonovf6acafc2013-01-28 07:16:22 +0000124 set(output_bin "${CMAKE_CURRENT_BINARY_DIR}/${test_name}")
Alexey Samsonova74424e2013-01-28 09:07:30 +0000125 add_custom_target(${test_name}
Alexey Samsonov02dcc632012-12-19 12:33:39 +0000126 COMMAND clang ${TEST_OBJECTS} -o "${output_bin}"
127 ${TEST_LINK_FLAGS}
Alexey Samsonov32b89912012-12-21 08:56:14 +0000128 DEPENDS clang ${TEST_DEPS})
Alexey Samsonov02dcc632012-12-19 12:33:39 +0000129 # Make the test suite depend on the binary.
130 add_dependencies(${test_suite} ${test_name})
131endmacro()
Alexey Samsonovc1caace2013-05-21 13:48:27 +0000132
133macro(add_compiler_rt_resource_file target_name file_name)
134 set(src_file "${CMAKE_CURRENT_SOURCE_DIR}/${file_name}")
135 set(dst_file "${CLANG_RESOURCE_DIR}/${file_name}")
136 add_custom_target(${target_name}
137 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src_file} ${dst_file}
138 DEPENDS ${file_name})
139 # Install in Clang resource directory.
140 install(FILES ${file_name} DESTINATION ${LIBCLANG_INSTALL_PATH})
141endmacro()