blob: 1ece3eb90933ee04359f42e1d360b9066f4a65c0 [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>
Alexey Samsonove5fa2432013-08-27 15:08:02 +000039# DEFS <compile definitions>)
Alexey Samsonove16af952013-01-20 13:58:10 +000040macro(add_compiler_rt_static_runtime name arch)
41 if(CAN_TARGET_${arch})
Alexey Samsonove5fa2432013-08-27 15:08:02 +000042 parse_arguments(LIB "SOURCES;CFLAGS;DEFS" "" ${ARGN})
Alexey Samsonove16af952013-01-20 13:58:10 +000043 add_library(${name} STATIC ${LIB_SOURCES})
44 # Setup compile flags and definitions.
45 set_target_compile_flags(${name}
46 ${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS})
47 set_property(TARGET ${name} APPEND PROPERTY
48 COMPILE_DEFINITIONS ${LIB_DEFS})
49 # Setup correct output directory in the build tree.
50 set_target_properties(${name} PROPERTIES
Alexey Samsonov2aad7c12013-01-21 08:12:20 +000051 ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
Alexey Samsonove16af952013-01-20 13:58:10 +000052 # Add installation command.
53 install(TARGETS ${name}
54 ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
55 else()
56 message(FATAL_ERROR "Archtecture ${arch} can't be targeted")
57 endif()
58endmacro()
59
Alexey Samsonov2aad7c12013-01-21 08:12:20 +000060# Same as add_compiler_rt_static_runtime, but creates a universal library
61# for several architectures.
62# add_compiler_rt_osx_static_runtime(<name> ARCH <architectures>
63# SOURCES <source files>
64# CFLAGS <compile flags>
65# DEFS <compile definitions>)
66macro(add_compiler_rt_osx_static_runtime name)
67 parse_arguments(LIB "ARCH;SOURCES;CFLAGS;DEFS" "" ${ARGN})
68 add_library(${name} STATIC ${LIB_SOURCES})
69 set_target_compile_flags(${name} ${LIB_CFLAGS})
70 set_property(TARGET ${name} APPEND PROPERTY
71 COMPILE_DEFINITIONS ${LIB_DEFS})
72 set_target_properties(${name} PROPERTIES
73 OSX_ARCHITECTURES "${LIB_ARCH}"
74 ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
75 install(TARGETS ${name}
76 ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
77endmacro()
78
79# Adds dynamic runtime library on osx, which supports multiple architectures.
80# add_compiler_rt_osx_dynamic_runtime(<name> ARCH <architectures>
81# SOURCES <source files>
82# CFLAGS <compile flags>
83# DEFS <compile definitions>
84# LINKFLAGS <link flags>)
85macro(add_compiler_rt_osx_dynamic_runtime name)
86 parse_arguments(LIB "ARCH;SOURCES;CFLAGS;DEFS;LINKFLAGS" "" ${ARGN})
87 add_library(${name} SHARED ${LIB_SOURCES})
88 set_target_compile_flags(${name} ${LIB_CFLAGS})
89 set_target_link_flags(${name} ${LIB_LINKFLAGS})
90 set_property(TARGET ${name} APPEND PROPERTY
91 COMPILE_DEFINITIONS ${LIB_DEFS})
92 set_target_properties(${name} PROPERTIES
93 OSX_ARCHITECTURES "${LIB_ARCH}"
94 LIBRARY_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
95 install(TARGETS ${name}
96 LIBRARY DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
97endmacro()
98
Alexey Samsonov392c50d2013-01-18 16:05:21 +000099# Unittests support.
Alexey Samsonov02dcc632012-12-19 12:33:39 +0000100set(COMPILER_RT_GTEST_PATH ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest)
101set(COMPILER_RT_GTEST_SOURCE ${COMPILER_RT_GTEST_PATH}/gtest-all.cc)
102set(COMPILER_RT_GTEST_INCLUDE_CFLAGS
103 -DGTEST_NO_LLVM_RAW_OSTREAM=1
104 -I${COMPILER_RT_GTEST_PATH}/include
105)
106
107# Use Clang to link objects into a single executable with just-built
108# Clang, using specific link flags. Make executable a part of provided
109# test_suite.
110# add_compiler_rt_test(<test_suite> <test_name>
111# OBJECTS <object files>
112# DEPS <deps (e.g. runtime libs)>
113# LINK_FLAGS <link flags>)
114macro(add_compiler_rt_test test_suite test_name)
115 parse_arguments(TEST "OBJECTS;DEPS;LINK_FLAGS" "" ${ARGN})
Alexey Samsonovf6acafc2013-01-28 07:16:22 +0000116 set(output_bin "${CMAKE_CURRENT_BINARY_DIR}/${test_name}")
Alexey Samsonova74424e2013-01-28 09:07:30 +0000117 add_custom_target(${test_name}
Alexey Samsonov02dcc632012-12-19 12:33:39 +0000118 COMMAND clang ${TEST_OBJECTS} -o "${output_bin}"
119 ${TEST_LINK_FLAGS}
Alexey Samsonov32b89912012-12-21 08:56:14 +0000120 DEPENDS clang ${TEST_DEPS})
Alexey Samsonov02dcc632012-12-19 12:33:39 +0000121 # Make the test suite depend on the binary.
122 add_dependencies(${test_suite} ${test_name})
123endmacro()
Alexey Samsonovc1caace2013-05-21 13:48:27 +0000124
125macro(add_compiler_rt_resource_file target_name file_name)
126 set(src_file "${CMAKE_CURRENT_SOURCE_DIR}/${file_name}")
127 set(dst_file "${CLANG_RESOURCE_DIR}/${file_name}")
128 add_custom_target(${target_name}
129 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src_file} ${dst_file}
130 DEPENDS ${file_name})
131 # Install in Clang resource directory.
132 install(FILES ${file_name} DESTINATION ${LIBCLANG_INSTALL_PATH})
133endmacro()