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> |
| 9 | # CFLAGS <compile flags>) |
| 10 | macro(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() |
| 19 | endmacro() |
| 20 | |
Alexey Samsonov | 5162314 | 2013-01-20 14:36:12 +0000 | [diff] [blame] | 21 | # 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>) |
| 26 | macro(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 Samsonov | 2aad7c1 | 2013-01-21 08:12:20 +0000 | [diff] [blame] | 31 | set_target_properties(${libname} PROPERTIES OSX_ARCHITECTURES "${LIB_ARCH}") |
Alexey Samsonov | 5162314 | 2013-01-20 14:36:12 +0000 | [diff] [blame] | 32 | endmacro() |
| 33 | |
Alexey Samsonov | e16af95 | 2013-01-20 13:58:10 +0000 | [diff] [blame] | 34 | # 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 Smith | a06fe91 | 2013-03-23 00:31:07 +0000 | [diff] [blame] | 39 | # DEFS <compile definitions> |
| 40 | # SYMS <symbols file>) |
Alexey Samsonov | e16af95 | 2013-01-20 13:58:10 +0000 | [diff] [blame] | 41 | macro(add_compiler_rt_static_runtime name arch) |
| 42 | if(CAN_TARGET_${arch}) |
Richard Smith | a06fe91 | 2013-03-23 00:31:07 +0000 | [diff] [blame] | 43 | parse_arguments(LIB "SOURCES;CFLAGS;DEFS;SYMS" "" ${ARGN}) |
Alexey Samsonov | e16af95 | 2013-01-20 13:58:10 +0000 | [diff] [blame] | 44 | 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 Samsonov | 2aad7c1 | 2013-01-21 08:12:20 +0000 | [diff] [blame] | 52 | ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}) |
Alexey Samsonov | e16af95 | 2013-01-20 13:58:10 +0000 | [diff] [blame] | 53 | # Add installation command. |
| 54 | install(TARGETS ${name} |
| 55 | ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}) |
Richard Smith | a06fe91 | 2013-03-23 00:31:07 +0000 | [diff] [blame] | 56 | # 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 Samsonov | e16af95 | 2013-01-20 13:58:10 +0000 | [diff] [blame] | 63 | else() |
| 64 | message(FATAL_ERROR "Archtecture ${arch} can't be targeted") |
| 65 | endif() |
| 66 | endmacro() |
| 67 | |
Alexey Samsonov | 2aad7c1 | 2013-01-21 08:12:20 +0000 | [diff] [blame] | 68 | # 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>) |
| 74 | macro(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}) |
| 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}) |
| 105 | endmacro() |
| 106 | |
Alexey Samsonov | 392c50d | 2013-01-18 16:05:21 +0000 | [diff] [blame] | 107 | # Unittests support. |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 108 | set(COMPILER_RT_GTEST_PATH ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest) |
| 109 | set(COMPILER_RT_GTEST_SOURCE ${COMPILER_RT_GTEST_PATH}/gtest-all.cc) |
| 110 | set(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>) |
| 122 | macro(add_compiler_rt_test test_suite test_name) |
| 123 | parse_arguments(TEST "OBJECTS;DEPS;LINK_FLAGS" "" ${ARGN}) |
Alexey Samsonov | f6acafc | 2013-01-28 07:16:22 +0000 | [diff] [blame] | 124 | set(output_bin "${CMAKE_CURRENT_BINARY_DIR}/${test_name}") |
Alexey Samsonov | a74424e | 2013-01-28 09:07:30 +0000 | [diff] [blame] | 125 | add_custom_target(${test_name} |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 126 | COMMAND clang ${TEST_OBJECTS} -o "${output_bin}" |
| 127 | ${TEST_LINK_FLAGS} |
Alexey Samsonov | 32b8991 | 2012-12-21 08:56:14 +0000 | [diff] [blame] | 128 | DEPENDS clang ${TEST_DEPS}) |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 129 | # Make the test suite depend on the binary. |
| 130 | add_dependencies(${test_suite} ${test_name}) |
| 131 | endmacro() |
Alexey Samsonov | c1caace | 2013-05-21 13:48:27 +0000 | [diff] [blame] | 132 | |
| 133 | macro(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}) |
| 141 | endmacro() |