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 | |
Alexey Samsonov | 5162314 | 2013-01-20 14:36:12 +0000 | [diff] [blame] | 24 | # Same as above, but adds universal osx library with name "<name>.osx" |
| 25 | # targeting multiple architectures. |
| 26 | # add_compiler_rt_osx_object_library(<name> ARCH <architectures> |
| 27 | # SOURCES <source files> |
| 28 | # CFLAGS <compile flags>) |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 29 | # DEFS <compile definitions>) |
Alexey Samsonov | 5162314 | 2013-01-20 14:36:12 +0000 | [diff] [blame] | 30 | macro(add_compiler_rt_osx_object_library name) |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 31 | parse_arguments(LIB "ARCH;SOURCES;CFLAGS;DEFS" "" ${ARGN}) |
Alexey Samsonov | 5162314 | 2013-01-20 14:36:12 +0000 | [diff] [blame] | 32 | set(libname "${name}.osx") |
| 33 | add_library(${libname} OBJECT ${LIB_SOURCES}) |
| 34 | set_target_compile_flags(${libname} ${LIB_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 | e16af95 | 2013-01-20 13:58:10 +0000 | [diff] [blame] | 40 | # 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 Samsonov | e5fa243 | 2013-08-27 15:08:02 +0000 | [diff] [blame] | 45 | # DEFS <compile definitions>) |
Alexey Samsonov | e16af95 | 2013-01-20 13:58:10 +0000 | [diff] [blame] | 46 | macro(add_compiler_rt_static_runtime name arch) |
| 47 | if(CAN_TARGET_${arch}) |
Alexey Samsonov | e5fa243 | 2013-08-27 15:08:02 +0000 | [diff] [blame] | 48 | parse_arguments(LIB "SOURCES;CFLAGS;DEFS" "" ${ARGN}) |
Alexey Samsonov | e16af95 | 2013-01-20 13:58:10 +0000 | [diff] [blame] | 49 | 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 Samsonov | 2aad7c1 | 2013-01-21 08:12:20 +0000 | [diff] [blame] | 57 | ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}) |
Alexey Samsonov | e16af95 | 2013-01-20 13:58:10 +0000 | [diff] [blame] | 58 | # Add installation command. |
| 59 | install(TARGETS ${name} |
| 60 | ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}) |
Alexey Samsonov | c349466 | 2013-10-01 12:52:15 +0000 | [diff] [blame] | 61 | add_dependencies(compiler-rt ${name}) |
Alexey Samsonov | e16af95 | 2013-01-20 13:58:10 +0000 | [diff] [blame] | 62 | else() |
| 63 | message(FATAL_ERROR "Archtecture ${arch} can't be targeted") |
| 64 | endif() |
| 65 | endmacro() |
| 66 | |
Alexey Samsonov | 2aad7c1 | 2013-01-21 08:12:20 +0000 | [diff] [blame] | 67 | # 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>) |
| 73 | macro(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 Samsonov | c349466 | 2013-10-01 12:52:15 +0000 | [diff] [blame] | 84 | add_dependencies(compiler-rt ${name}) |
Alexey Samsonov | 2aad7c1 | 2013-01-21 08:12:20 +0000 | [diff] [blame] | 85 | endmacro() |
| 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>) |
| 93 | macro(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}) |
Alexey Samsonov | c349466 | 2013-10-01 12:52:15 +0000 | [diff] [blame] | 105 | add_dependencies(compiler-rt ${name}) |
Alexey Samsonov | 2aad7c1 | 2013-01-21 08:12:20 +0000 | [diff] [blame] | 106 | endmacro() |
| 107 | |
Alexey Samsonov | 392c50d | 2013-01-18 16:05:21 +0000 | [diff] [blame] | 108 | # Unittests support. |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 109 | set(COMPILER_RT_GTEST_PATH ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest) |
| 110 | set(COMPILER_RT_GTEST_SOURCE ${COMPILER_RT_GTEST_PATH}/gtest-all.cc) |
| 111 | set(COMPILER_RT_GTEST_INCLUDE_CFLAGS |
| 112 | -DGTEST_NO_LLVM_RAW_OSTREAM=1 |
| 113 | -I${COMPILER_RT_GTEST_PATH}/include |
| 114 | ) |
| 115 | |
| 116 | # Use Clang to link objects into a single executable with just-built |
| 117 | # Clang, using specific link flags. Make executable a part of provided |
| 118 | # test_suite. |
| 119 | # add_compiler_rt_test(<test_suite> <test_name> |
| 120 | # OBJECTS <object files> |
| 121 | # DEPS <deps (e.g. runtime libs)> |
| 122 | # LINK_FLAGS <link flags>) |
| 123 | macro(add_compiler_rt_test test_suite test_name) |
| 124 | parse_arguments(TEST "OBJECTS;DEPS;LINK_FLAGS" "" ${ARGN}) |
Alexey Samsonov | f6acafc | 2013-01-28 07:16:22 +0000 | [diff] [blame] | 125 | set(output_bin "${CMAKE_CURRENT_BINARY_DIR}/${test_name}") |
Alexey Samsonov | a74424e | 2013-01-28 09:07:30 +0000 | [diff] [blame] | 126 | add_custom_target(${test_name} |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 127 | COMMAND clang ${TEST_OBJECTS} -o "${output_bin}" |
| 128 | ${TEST_LINK_FLAGS} |
Alexey Samsonov | 32b8991 | 2012-12-21 08:56:14 +0000 | [diff] [blame] | 129 | DEPENDS clang ${TEST_DEPS}) |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 130 | # Make the test suite depend on the binary. |
| 131 | add_dependencies(${test_suite} ${test_name}) |
| 132 | endmacro() |
Alexey Samsonov | c1caace | 2013-05-21 13:48:27 +0000 | [diff] [blame] | 133 | |
| 134 | macro(add_compiler_rt_resource_file target_name file_name) |
| 135 | set(src_file "${CMAKE_CURRENT_SOURCE_DIR}/${file_name}") |
| 136 | set(dst_file "${CLANG_RESOURCE_DIR}/${file_name}") |
| 137 | add_custom_target(${target_name} |
| 138 | COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src_file} ${dst_file} |
| 139 | DEPENDS ${file_name}) |
| 140 | # Install in Clang resource directory. |
| 141 | install(FILES ${file_name} DESTINATION ${LIBCLANG_INSTALL_PATH}) |
| 142 | endmacro() |