Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 1 | include(AddLLVM) |
| 2 | include(LLVMParseArguments) |
Alexey Samsonov | 392c50d | 2013-01-18 16:05:21 +0000 | [diff] [blame] | 3 | include(CompilerRTUtils) |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 4 | |
Alexey Samsonov | 392c50d | 2013-01-18 16:05:21 +0000 | [diff] [blame] | 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> |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 9 | # CFLAGS <compile flags> |
| 10 | # DEFS <compile definitions>) |
Alexey Samsonov | 392c50d | 2013-01-18 16:05:21 +0000 | [diff] [blame] | 11 | macro(add_compiler_rt_object_library name arch) |
| 12 | if(CAN_TARGET_${arch}) |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 13 | parse_arguments(LIB "SOURCES;CFLAGS;DEFS" "" ${ARGN}) |
Alexey Samsonov | 392c50d | 2013-01-18 16:05:21 +0000 | [diff] [blame] | 14 | add_library(${name}.${arch} OBJECT ${LIB_SOURCES}) |
| 15 | set_target_compile_flags(${name}.${arch} |
| 16 | ${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS}) |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 17 | set_property(TARGET ${name}.${arch} APPEND PROPERTY |
| 18 | COMPILE_DEFINITIONS ${LIB_DEFS}) |
Alexey Samsonov | 392c50d | 2013-01-18 16:05:21 +0000 | [diff] [blame] | 19 | else() |
| 20 | message(FATAL_ERROR "Archtecture ${arch} can't be targeted") |
| 21 | endif() |
| 22 | endmacro() |
| 23 | |
Alexander Potapenko | 4949674 | 2013-11-07 10:08:19 +0000 | [diff] [blame] | 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) |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 31 | parse_arguments(LIB "ARCH;SOURCES;CFLAGS;DEFS" "" ${ARGN}) |
Alexander Potapenko | 4949674 | 2013-11-07 10:08:19 +0000 | [diff] [blame] | 32 | set(libname "${name}.${os}") |
Alexey Samsonov | 5162314 | 2013-01-20 14:36:12 +0000 | [diff] [blame] | 33 | add_library(${libname} OBJECT ${LIB_SOURCES}) |
Alexander Potapenko | 4949674 | 2013-11-07 10:08:19 +0000 | [diff] [blame] | 34 | set_target_compile_flags(${libname} ${LIB_CFLAGS} ${DARWIN_${os}_CFLAGS}) |
Alexey Samsonov | 2aad7c1 | 2013-01-21 08:12:20 +0000 | [diff] [blame] | 35 | set_target_properties(${libname} PROPERTIES OSX_ARCHITECTURES "${LIB_ARCH}") |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 36 | set_property(TARGET ${libname} APPEND PROPERTY |
| 37 | COMPILE_DEFINITIONS ${LIB_DEFS}) |
Alexey Samsonov | 5162314 | 2013-01-20 14:36:12 +0000 | [diff] [blame] | 38 | endmacro() |
| 39 | |
Alexey Samsonov | e18b785 | 2014-03-31 13:45:36 +0000 | [diff] [blame] | 40 | # 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>) |
| 46 | macro(add_compiler_rt_runtime name arch type) |
Alexey Samsonov | e16af95 | 2013-01-20 13:58:10 +0000 | [diff] [blame] | 47 | if(CAN_TARGET_${arch}) |
Alexey Samsonov | d6535ea | 2014-04-01 13:16:30 +0000 | [diff] [blame^] | 48 | parse_arguments(LIB "SOURCES;CFLAGS;DEFS;OUTPUT_NAME" "" ${ARGN}) |
Alexey Samsonov | e18b785 | 2014-03-31 13:45:36 +0000 | [diff] [blame] | 49 | add_library(${name} ${type} ${LIB_SOURCES}) |
Alexey Samsonov | e16af95 | 2013-01-20 13:58:10 +0000 | [diff] [blame] | 50 | # Setup compile flags and definitions. |
| 51 | set_target_compile_flags(${name} |
| 52 | ${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS}) |
Alexey Samsonov | e18b785 | 2014-03-31 13:45:36 +0000 | [diff] [blame] | 53 | set_target_link_flags(${name} |
| 54 | ${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS}) |
Alexey Samsonov | e16af95 | 2013-01-20 13:58:10 +0000 | [diff] [blame] | 55 | 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 Samsonov | e18b785 | 2014-03-31 13:45:36 +0000 | [diff] [blame] | 59 | ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR} |
| 60 | LIBRARY_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}) |
Alexey Samsonov | d6535ea | 2014-04-01 13:16:30 +0000 | [diff] [blame^] | 61 | if (LIB_OUTPUT_NAME) |
| 62 | set_target_properties(${name} PROPERTIES |
| 63 | OUTPUT_NAME ${LIB_OUTPUT_NAME}) |
| 64 | endif() |
Alexey Samsonov | e16af95 | 2013-01-20 13:58:10 +0000 | [diff] [blame] | 65 | # Add installation command. |
| 66 | install(TARGETS ${name} |
Alexey Samsonov | e18b785 | 2014-03-31 13:45:36 +0000 | [diff] [blame] | 67 | ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR} |
| 68 | LIBRARY DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}) |
Alexey Samsonov | e16af95 | 2013-01-20 13:58:10 +0000 | [diff] [blame] | 69 | else() |
| 70 | message(FATAL_ERROR "Archtecture ${arch} can't be targeted") |
| 71 | endif() |
| 72 | endmacro() |
| 73 | |
Alexey Samsonov | e18b785 | 2014-03-31 13:45:36 +0000 | [diff] [blame] | 74 | # Same as add_compiler_rt_runtime(... STATIC), but creates a universal library |
Alexey Samsonov | 2aad7c1 | 2013-01-21 08:12:20 +0000 | [diff] [blame] | 75 | # for several architectures. |
| 76 | # add_compiler_rt_osx_static_runtime(<name> ARCH <architectures> |
| 77 | # SOURCES <source files> |
| 78 | # CFLAGS <compile flags> |
| 79 | # DEFS <compile definitions>) |
| 80 | macro(add_compiler_rt_osx_static_runtime name) |
| 81 | parse_arguments(LIB "ARCH;SOURCES;CFLAGS;DEFS" "" ${ARGN}) |
| 82 | add_library(${name} STATIC ${LIB_SOURCES}) |
| 83 | set_target_compile_flags(${name} ${LIB_CFLAGS}) |
| 84 | set_property(TARGET ${name} APPEND PROPERTY |
| 85 | COMPILE_DEFINITIONS ${LIB_DEFS}) |
| 86 | set_target_properties(${name} PROPERTIES |
| 87 | OSX_ARCHITECTURES "${LIB_ARCH}" |
| 88 | ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}) |
| 89 | install(TARGETS ${name} |
| 90 | ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}) |
| 91 | endmacro() |
| 92 | |
Alexander Potapenko | 4949674 | 2013-11-07 10:08:19 +0000 | [diff] [blame] | 93 | # Adds dynamic runtime library on osx/iossim, which supports multiple |
| 94 | # architectures. |
| 95 | # add_compiler_rt_darwin_dynamic_runtime(<name> <os> |
| 96 | # ARCH <architectures> |
| 97 | # SOURCES <source files> |
| 98 | # CFLAGS <compile flags> |
| 99 | # DEFS <compile definitions> |
| 100 | # LINKFLAGS <link flags>) |
| 101 | macro(add_compiler_rt_darwin_dynamic_runtime name os) |
Alexey Samsonov | 2aad7c1 | 2013-01-21 08:12:20 +0000 | [diff] [blame] | 102 | parse_arguments(LIB "ARCH;SOURCES;CFLAGS;DEFS;LINKFLAGS" "" ${ARGN}) |
| 103 | add_library(${name} SHARED ${LIB_SOURCES}) |
Alexander Potapenko | 4949674 | 2013-11-07 10:08:19 +0000 | [diff] [blame] | 104 | set_target_compile_flags(${name} ${LIB_CFLAGS} ${DARWIN_${os}_CFLAGS}) |
| 105 | set_target_link_flags(${name} ${LIB_LINKFLAGS} ${DARWIN_${os}_LINKFLAGS}) |
Alexey Samsonov | 2aad7c1 | 2013-01-21 08:12:20 +0000 | [diff] [blame] | 106 | set_property(TARGET ${name} APPEND PROPERTY |
| 107 | COMPILE_DEFINITIONS ${LIB_DEFS}) |
| 108 | set_target_properties(${name} PROPERTIES |
| 109 | OSX_ARCHITECTURES "${LIB_ARCH}" |
| 110 | LIBRARY_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}) |
| 111 | install(TARGETS ${name} |
| 112 | LIBRARY DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}) |
| 113 | endmacro() |
| 114 | |
Alexey Samsonov | 392c50d | 2013-01-18 16:05:21 +0000 | [diff] [blame] | 115 | # Unittests support. |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 116 | set(COMPILER_RT_GTEST_PATH ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest) |
Chandler Carruth | ace5350 | 2013-11-15 10:21:15 +0000 | [diff] [blame] | 117 | set(COMPILER_RT_GTEST_SOURCE ${COMPILER_RT_GTEST_PATH}/src/gtest-all.cc) |
Alexey Samsonov | 1e5d8be | 2014-03-24 13:29:20 +0000 | [diff] [blame] | 118 | set(COMPILER_RT_GTEST_CFLAGS |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 119 | -DGTEST_NO_LLVM_RAW_OSTREAM=1 |
| 120 | -I${COMPILER_RT_GTEST_PATH}/include |
Chandler Carruth | ace5350 | 2013-11-15 10:21:15 +0000 | [diff] [blame] | 121 | -I${COMPILER_RT_GTEST_PATH} |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 122 | ) |
| 123 | |
Alexey Samsonov | 17cf7c5 | 2014-02-19 13:01:03 +0000 | [diff] [blame] | 124 | # Link objects into a single executable with COMPILER_RT_TEST_COMPILER, |
| 125 | # using specified link flags. Make executable a part of provided |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 126 | # test_suite. |
| 127 | # add_compiler_rt_test(<test_suite> <test_name> |
| 128 | # OBJECTS <object files> |
| 129 | # DEPS <deps (e.g. runtime libs)> |
| 130 | # LINK_FLAGS <link flags>) |
| 131 | macro(add_compiler_rt_test test_suite test_name) |
| 132 | parse_arguments(TEST "OBJECTS;DEPS;LINK_FLAGS" "" ${ARGN}) |
Alexey Samsonov | f6acafc | 2013-01-28 07:16:22 +0000 | [diff] [blame] | 133 | set(output_bin "${CMAKE_CURRENT_BINARY_DIR}/${test_name}") |
Alexey Samsonov | 17cf7c5 | 2014-02-19 13:01:03 +0000 | [diff] [blame] | 134 | # Use host compiler in a standalone build, and just-built Clang otherwise. |
| 135 | if(NOT COMPILER_RT_STANDALONE_BUILD) |
| 136 | list(APPEND TEST_DEPS clang) |
| 137 | endif() |
Alexey Samsonov | a74424e | 2013-01-28 09:07:30 +0000 | [diff] [blame] | 138 | add_custom_target(${test_name} |
Alexey Samsonov | 17cf7c5 | 2014-02-19 13:01:03 +0000 | [diff] [blame] | 139 | COMMAND ${COMPILER_RT_TEST_COMPILER} ${TEST_OBJECTS} -o "${output_bin}" |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 140 | ${TEST_LINK_FLAGS} |
Alexey Samsonov | 17cf7c5 | 2014-02-19 13:01:03 +0000 | [diff] [blame] | 141 | DEPENDS ${TEST_DEPS}) |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 142 | # Make the test suite depend on the binary. |
| 143 | add_dependencies(${test_suite} ${test_name}) |
| 144 | endmacro() |
Alexey Samsonov | c1caace | 2013-05-21 13:48:27 +0000 | [diff] [blame] | 145 | |
| 146 | macro(add_compiler_rt_resource_file target_name file_name) |
| 147 | set(src_file "${CMAKE_CURRENT_SOURCE_DIR}/${file_name}") |
Alexey Samsonov | a52e2dc | 2014-02-18 14:28:53 +0000 | [diff] [blame] | 148 | set(dst_file "${COMPILER_RT_OUTPUT_DIR}/${file_name}") |
Alexey Samsonov | 41bf0bc | 2014-02-27 07:22:59 +0000 | [diff] [blame] | 149 | add_custom_command(OUTPUT ${dst_file} |
| 150 | DEPENDS ${src_file} |
Alexey Samsonov | c1caace | 2013-05-21 13:48:27 +0000 | [diff] [blame] | 151 | COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src_file} ${dst_file} |
Alexey Samsonov | 41bf0bc | 2014-02-27 07:22:59 +0000 | [diff] [blame] | 152 | COMMENT "Copying ${file_name}...") |
| 153 | add_custom_target(${target_name} DEPENDS ${dst_file}) |
Alexey Samsonov | c1caace | 2013-05-21 13:48:27 +0000 | [diff] [blame] | 154 | # Install in Clang resource directory. |
Alexey Samsonov | a52e2dc | 2014-02-18 14:28:53 +0000 | [diff] [blame] | 155 | install(FILES ${file_name} DESTINATION ${COMPILER_RT_INSTALL_PATH}) |
Alexey Samsonov | c1caace | 2013-05-21 13:48:27 +0000 | [diff] [blame] | 156 | endmacro() |
Evgeniy Stepanov | 9514ed1 | 2014-02-27 08:41:40 +0000 | [diff] [blame] | 157 | |
| 158 | macro(add_compiler_rt_script name) |
| 159 | set(dst ${COMPILER_RT_EXEC_OUTPUT_DIR}/${name}) |
| 160 | set(src ${CMAKE_CURRENT_SOURCE_DIR}/${name}) |
| 161 | add_custom_command(OUTPUT ${dst} |
| 162 | DEPENDS ${src} |
| 163 | COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst} |
| 164 | COMMENT "Copying ${name}...") |
| 165 | add_custom_target(${name} DEPENDS ${dst}) |
| 166 | install(FILES ${dst} |
| 167 | PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE |
| 168 | DESTINATION ${COMPILER_RT_INSTALL_PATH}/bin) |
| 169 | endmacro(add_compiler_rt_script src name) |