Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 1 | include(AddLLVM) |
Alexey Samsonov | 2e8e441 | 2014-05-09 22:11:03 +0000 | [diff] [blame] | 2 | include(ExternalProject) |
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 | |
Chris Bieneman | 5c2fd24 | 2015-06-10 23:55:07 +0000 | [diff] [blame] | 5 | # Tries to add an "object library" target for a given list of OSs and/or |
| 6 | # architectures with name "<name>.<arch>" for non-Darwin platforms if |
| 7 | # architecture can be targeted, and "<name>.<os>" for Darwin platforms. |
| 8 | # add_compiler_rt_object_libraries(<name> |
Filipe Cabecinhas | c309de7 | 2015-06-19 03:39:24 +0000 | [diff] [blame^] | 9 | # OS <os names> |
| 10 | # ARCHS <architectures> |
Chris Bieneman | 5c2fd24 | 2015-06-10 23:55:07 +0000 | [diff] [blame] | 11 | # SOURCES <source files> |
| 12 | # CFLAGS <compile flags> |
| 13 | # DEFS <compile definitions>) |
| 14 | function(add_compiler_rt_object_libraries name) |
Filipe Cabecinhas | c309de7 | 2015-06-19 03:39:24 +0000 | [diff] [blame^] | 15 | cmake_parse_arguments(LIB "" "" "OS;ARCHS;SOURCES;CFLAGS;DEFS" ${ARGN}) |
Chris Bieneman | 5c2fd24 | 2015-06-10 23:55:07 +0000 | [diff] [blame] | 16 | set(libnames) |
| 17 | if(APPLE) |
| 18 | foreach(os ${LIB_OS}) |
| 19 | set(libname "${name}.${os}") |
| 20 | set(libnames ${libnames} ${libname}) |
| 21 | set(extra_cflags_${libname} ${DARWIN_${os}_CFLAGS}) |
| 22 | endforeach() |
Alexey Samsonov | 392c50d | 2013-01-18 16:05:21 +0000 | [diff] [blame] | 23 | else() |
Filipe Cabecinhas | c309de7 | 2015-06-19 03:39:24 +0000 | [diff] [blame^] | 24 | foreach(arch ${LIB_ARCHS}) |
Chris Bieneman | 5c2fd24 | 2015-06-10 23:55:07 +0000 | [diff] [blame] | 25 | set(libname "${name}.${arch}") |
| 26 | set(libnames ${libnames} ${libname}) |
| 27 | set(extra_cflags_${libname} ${TARGET_${arch}_CFLAGS}) |
| 28 | if(NOT CAN_TARGET_${arch}) |
| 29 | message(FATAL_ERROR "Archtecture ${arch} can't be targeted") |
| 30 | return() |
| 31 | endif() |
| 32 | endforeach() |
Alexey Samsonov | 392c50d | 2013-01-18 16:05:21 +0000 | [diff] [blame] | 33 | endif() |
Chris Bieneman | 5c2fd24 | 2015-06-10 23:55:07 +0000 | [diff] [blame] | 34 | |
| 35 | foreach(libname ${libnames}) |
| 36 | add_library(${libname} OBJECT ${LIB_SOURCES}) |
| 37 | set_target_compile_flags(${libname} |
| 38 | ${CMAKE_CXX_FLAGS} ${extra_cflags_${libname}} ${LIB_CFLAGS}) |
| 39 | set_property(TARGET ${libname} APPEND PROPERTY |
| 40 | COMPILE_DEFINITIONS ${LIB_DEFS}) |
| 41 | if(APPLE) |
Filipe Cabecinhas | c309de7 | 2015-06-19 03:39:24 +0000 | [diff] [blame^] | 42 | set_target_properties(${libname} PROPERTIES OSX_ARCHITECTURES "${LIB_ARCHS}") |
Chris Bieneman | 5c2fd24 | 2015-06-10 23:55:07 +0000 | [diff] [blame] | 43 | endif() |
| 44 | endforeach() |
| 45 | endfunction() |
Alexey Samsonov | 5162314 | 2013-01-20 14:36:12 +0000 | [diff] [blame] | 46 | |
Alexey Samsonov | e18b785 | 2014-03-31 13:45:36 +0000 | [diff] [blame] | 47 | # Adds static or shared runtime for a given architecture and puts it in the |
| 48 | # proper directory in the build and install trees. |
| 49 | # add_compiler_rt_runtime(<name> <arch> {STATIC,SHARED} |
| 50 | # SOURCES <source files> |
| 51 | # CFLAGS <compile flags> |
Evgeniy Stepanov | 4401473 | 2014-09-29 13:18:55 +0000 | [diff] [blame] | 52 | # DEFS <compile definitions> |
| 53 | # OUTPUT_NAME <output library name>) |
Alexey Samsonov | e18b785 | 2014-03-31 13:45:36 +0000 | [diff] [blame] | 54 | macro(add_compiler_rt_runtime name arch type) |
Alexey Samsonov | e16af95 | 2013-01-20 13:58:10 +0000 | [diff] [blame] | 55 | if(CAN_TARGET_${arch}) |
Filipe Cabecinhas | c309de7 | 2015-06-19 03:39:24 +0000 | [diff] [blame^] | 56 | cmake_parse_arguments(LIB "" "OUTPUT_NAME" "SOURCES;CFLAGS;LINKFLAGS;DEFS" ${ARGN}) |
Alexey Samsonov | e18b785 | 2014-03-31 13:45:36 +0000 | [diff] [blame] | 57 | add_library(${name} ${type} ${LIB_SOURCES}) |
Alexey Samsonov | e16af95 | 2013-01-20 13:58:10 +0000 | [diff] [blame] | 58 | # Setup compile flags and definitions. |
| 59 | set_target_compile_flags(${name} |
| 60 | ${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS}) |
Aaron Ballman | 208eae3 | 2014-10-29 19:25:20 +0000 | [diff] [blame] | 61 | set_target_link_flags(${name} |
Evgeniy Stepanov | 976974a | 2015-05-05 20:13:39 +0000 | [diff] [blame] | 62 | ${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS} ${LIB_LINKFLAGS}) |
Alexey Samsonov | e16af95 | 2013-01-20 13:58:10 +0000 | [diff] [blame] | 63 | set_property(TARGET ${name} APPEND PROPERTY |
| 64 | COMPILE_DEFINITIONS ${LIB_DEFS}) |
| 65 | # Setup correct output directory in the build tree. |
| 66 | set_target_properties(${name} PROPERTIES |
Alexey Samsonov | e18b785 | 2014-03-31 13:45:36 +0000 | [diff] [blame] | 67 | ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR} |
Hans Wennborg | b89adc4 | 2014-12-04 21:01:49 +0000 | [diff] [blame] | 68 | LIBRARY_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR} |
| 69 | RUNTIME_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}) |
Evgeniy Stepanov | 4401473 | 2014-09-29 13:18:55 +0000 | [diff] [blame] | 70 | if ("${LIB_OUTPUT_NAME}" STREQUAL "") |
| 71 | set_target_properties(${name} PROPERTIES |
| 72 | OUTPUT_NAME ${name}${COMPILER_RT_OS_SUFFIX}) |
| 73 | else() |
Alexey Samsonov | d6535ea | 2014-04-01 13:16:30 +0000 | [diff] [blame] | 74 | set_target_properties(${name} PROPERTIES |
| 75 | OUTPUT_NAME ${LIB_OUTPUT_NAME}) |
| 76 | endif() |
Alexey Samsonov | e16af95 | 2013-01-20 13:58:10 +0000 | [diff] [blame] | 77 | # Add installation command. |
| 78 | install(TARGETS ${name} |
Alexey Samsonov | e18b785 | 2014-03-31 13:45:36 +0000 | [diff] [blame] | 79 | ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR} |
Hans Wennborg | b89adc4 | 2014-12-04 21:01:49 +0000 | [diff] [blame] | 80 | LIBRARY DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR} |
| 81 | RUNTIME DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}) |
Alexey Samsonov | e16af95 | 2013-01-20 13:58:10 +0000 | [diff] [blame] | 82 | else() |
| 83 | message(FATAL_ERROR "Archtecture ${arch} can't be targeted") |
| 84 | endif() |
| 85 | endmacro() |
| 86 | |
Alexey Samsonov | e18b785 | 2014-03-31 13:45:36 +0000 | [diff] [blame] | 87 | # Same as add_compiler_rt_runtime(... STATIC), but creates a universal library |
Alexey Samsonov | 2aad7c1 | 2013-01-21 08:12:20 +0000 | [diff] [blame] | 88 | # for several architectures. |
Filipe Cabecinhas | c309de7 | 2015-06-19 03:39:24 +0000 | [diff] [blame^] | 89 | # add_compiler_rt_osx_static_runtime(<name> ARCHS <architectures> |
Alexey Samsonov | 2aad7c1 | 2013-01-21 08:12:20 +0000 | [diff] [blame] | 90 | # SOURCES <source files> |
| 91 | # CFLAGS <compile flags> |
| 92 | # DEFS <compile definitions>) |
| 93 | macro(add_compiler_rt_osx_static_runtime name) |
Filipe Cabecinhas | c309de7 | 2015-06-19 03:39:24 +0000 | [diff] [blame^] | 94 | cmake_parse_arguments(LIB "" "" "ARCHS;SOURCES;CFLAGS;DEFS" ${ARGN}) |
Alexey Samsonov | 2aad7c1 | 2013-01-21 08:12:20 +0000 | [diff] [blame] | 95 | add_library(${name} STATIC ${LIB_SOURCES}) |
| 96 | set_target_compile_flags(${name} ${LIB_CFLAGS}) |
| 97 | set_property(TARGET ${name} APPEND PROPERTY |
| 98 | COMPILE_DEFINITIONS ${LIB_DEFS}) |
| 99 | set_target_properties(${name} PROPERTIES |
Filipe Cabecinhas | c309de7 | 2015-06-19 03:39:24 +0000 | [diff] [blame^] | 100 | OSX_ARCHITECTURES "${LIB_ARCHS}" |
Alexey Samsonov | 2aad7c1 | 2013-01-21 08:12:20 +0000 | [diff] [blame] | 101 | ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}) |
| 102 | install(TARGETS ${name} |
| 103 | ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}) |
| 104 | endmacro() |
| 105 | |
Alexander Potapenko | 4949674 | 2013-11-07 10:08:19 +0000 | [diff] [blame] | 106 | # Adds dynamic runtime library on osx/iossim, which supports multiple |
| 107 | # architectures. |
| 108 | # add_compiler_rt_darwin_dynamic_runtime(<name> <os> |
Filipe Cabecinhas | c309de7 | 2015-06-19 03:39:24 +0000 | [diff] [blame^] | 109 | # ARCHS <architectures> |
Alexander Potapenko | 4949674 | 2013-11-07 10:08:19 +0000 | [diff] [blame] | 110 | # SOURCES <source files> |
| 111 | # CFLAGS <compile flags> |
| 112 | # DEFS <compile definitions> |
| 113 | # LINKFLAGS <link flags>) |
| 114 | macro(add_compiler_rt_darwin_dynamic_runtime name os) |
Filipe Cabecinhas | c309de7 | 2015-06-19 03:39:24 +0000 | [diff] [blame^] | 115 | cmake_parse_arguments(LIB "" "" "ARCHS;SOURCES;CFLAGS;DEFS;LINKFLAGS" ${ARGN}) |
Alexey Samsonov | 2aad7c1 | 2013-01-21 08:12:20 +0000 | [diff] [blame] | 116 | add_library(${name} SHARED ${LIB_SOURCES}) |
Alexander Potapenko | 4949674 | 2013-11-07 10:08:19 +0000 | [diff] [blame] | 117 | set_target_compile_flags(${name} ${LIB_CFLAGS} ${DARWIN_${os}_CFLAGS}) |
| 118 | set_target_link_flags(${name} ${LIB_LINKFLAGS} ${DARWIN_${os}_LINKFLAGS}) |
Alexey Samsonov | 2aad7c1 | 2013-01-21 08:12:20 +0000 | [diff] [blame] | 119 | set_property(TARGET ${name} APPEND PROPERTY |
| 120 | COMPILE_DEFINITIONS ${LIB_DEFS}) |
| 121 | set_target_properties(${name} PROPERTIES |
Filipe Cabecinhas | c309de7 | 2015-06-19 03:39:24 +0000 | [diff] [blame^] | 122 | OSX_ARCHITECTURES "${LIB_ARCHS}" |
Alexey Samsonov | 2aad7c1 | 2013-01-21 08:12:20 +0000 | [diff] [blame] | 123 | LIBRARY_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}) |
| 124 | install(TARGETS ${name} |
| 125 | LIBRARY DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}) |
| 126 | endmacro() |
| 127 | |
Timur Iskhodzhanov | a73e9db | 2014-05-30 12:42:57 +0000 | [diff] [blame] | 128 | set(COMPILER_RT_TEST_CFLAGS) |
| 129 | |
Alexey Samsonov | 392c50d | 2013-01-18 16:05:21 +0000 | [diff] [blame] | 130 | # Unittests support. |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 131 | set(COMPILER_RT_GTEST_PATH ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest) |
Chandler Carruth | ace5350 | 2013-11-15 10:21:15 +0000 | [diff] [blame] | 132 | 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] | 133 | set(COMPILER_RT_GTEST_CFLAGS |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 134 | -DGTEST_NO_LLVM_RAW_OSTREAM=1 |
Timur Iskhodzhanov | 402bcb5 | 2014-05-28 08:38:13 +0000 | [diff] [blame] | 135 | -DGTEST_HAS_RTTI=0 |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 136 | -I${COMPILER_RT_GTEST_PATH}/include |
Chandler Carruth | ace5350 | 2013-11-15 10:21:15 +0000 | [diff] [blame] | 137 | -I${COMPILER_RT_GTEST_PATH} |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 138 | ) |
| 139 | |
Alexey Samsonov | 001d038 | 2015-01-06 20:58:40 +0000 | [diff] [blame] | 140 | append_list_if(COMPILER_RT_DEBUG -DSANITIZER_DEBUG=1 COMPILER_RT_TEST_CFLAGS) |
| 141 | |
Timur Iskhodzhanov | 402bcb5 | 2014-05-28 08:38:13 +0000 | [diff] [blame] | 142 | if(MSVC) |
Timur Iskhodzhanov | a73e9db | 2014-05-30 12:42:57 +0000 | [diff] [blame] | 143 | # clang doesn't support exceptions on Windows yet. |
Alexey Samsonov | 001d038 | 2015-01-06 20:58:40 +0000 | [diff] [blame] | 144 | list(APPEND COMPILER_RT_TEST_CFLAGS -D_HAS_EXCEPTIONS=0) |
Timur Iskhodzhanov | a73e9db | 2014-05-30 12:42:57 +0000 | [diff] [blame] | 145 | |
| 146 | # We should teach clang to understand "#pragma intrinsic", see PR19898. |
| 147 | list(APPEND COMPILER_RT_TEST_CFLAGS -Wno-undefined-inline) |
| 148 | |
Timur Iskhodzhanov | 402bcb5 | 2014-05-28 08:38:13 +0000 | [diff] [blame] | 149 | # Clang doesn't support SEH on Windows yet. |
| 150 | list(APPEND COMPILER_RT_GTEST_CFLAGS -DGTEST_HAS_SEH=0) |
Timur Iskhodzhanov | a73e9db | 2014-05-30 12:42:57 +0000 | [diff] [blame] | 151 | |
| 152 | # gtest use a lot of stuff marked as deprecated on Windows. |
| 153 | list(APPEND COMPILER_RT_GTEST_CFLAGS -Wno-deprecated-declarations) |
Ehsan Akhgari | 1c4db80 | 2014-09-15 11:33:50 +0000 | [diff] [blame] | 154 | |
| 155 | # Visual Studio 2012 only supports up to 8 template parameters in |
| 156 | # std::tr1::tuple by default, but gtest requires 10 |
| 157 | if(MSVC_VERSION EQUAL 1700) |
Ehsan Akhgari | 494410f | 2014-09-25 20:42:49 +0000 | [diff] [blame] | 158 | list(APPEND COMPILER_RT_GTEST_CFLAGS -D_VARIADIC_MAX=10) |
Ehsan Akhgari | 1c4db80 | 2014-09-15 11:33:50 +0000 | [diff] [blame] | 159 | endif() |
Timur Iskhodzhanov | 402bcb5 | 2014-05-28 08:38:13 +0000 | [diff] [blame] | 160 | endif() |
| 161 | |
Alexey Samsonov | 17cf7c5 | 2014-02-19 13:01:03 +0000 | [diff] [blame] | 162 | # Link objects into a single executable with COMPILER_RT_TEST_COMPILER, |
| 163 | # using specified link flags. Make executable a part of provided |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 164 | # test_suite. |
| 165 | # add_compiler_rt_test(<test_suite> <test_name> |
Alexey Samsonov | 431f94d | 2014-12-17 23:14:01 +0000 | [diff] [blame] | 166 | # SUBDIR <subdirectory for binary> |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 167 | # OBJECTS <object files> |
| 168 | # DEPS <deps (e.g. runtime libs)> |
| 169 | # LINK_FLAGS <link flags>) |
| 170 | macro(add_compiler_rt_test test_suite test_name) |
Filipe Cabecinhas | c309de7 | 2015-06-19 03:39:24 +0000 | [diff] [blame^] | 171 | cmake_parse_arguments(TEST "" "SUBDIR" "OBJECTS;DEPS;LINK_FLAGS" "" ${ARGN}) |
Alexey Samsonov | 431f94d | 2014-12-17 23:14:01 +0000 | [diff] [blame] | 172 | if(TEST_SUBDIR) |
| 173 | set(output_bin "${CMAKE_CURRENT_BINARY_DIR}/${TEST_SUBDIR}/${test_name}") |
| 174 | else() |
| 175 | set(output_bin "${CMAKE_CURRENT_BINARY_DIR}/${test_name}") |
| 176 | endif() |
Timur Iskhodzhanov | 00b915c | 2015-01-22 14:54:22 +0000 | [diff] [blame] | 177 | if(MSVC) |
| 178 | set(output_bin "${output_bin}.exe") |
| 179 | endif() |
Alexey Samsonov | 17cf7c5 | 2014-02-19 13:01:03 +0000 | [diff] [blame] | 180 | # Use host compiler in a standalone build, and just-built Clang otherwise. |
| 181 | if(NOT COMPILER_RT_STANDALONE_BUILD) |
| 182 | list(APPEND TEST_DEPS clang) |
| 183 | endif() |
Chandler Carruth | 272eef9 | 2014-05-15 16:33:58 +0000 | [diff] [blame] | 184 | # If we're not on MSVC, include the linker flags from CMAKE but override them |
| 185 | # with the provided link flags. This ensures that flags which are required to |
| 186 | # link programs at all are included, but the changes needed for the test |
| 187 | # trump. With MSVC we can't do that because CMake is set up to run link.exe |
| 188 | # when linking, not the compiler. Here, we hack it to use the compiler |
| 189 | # because we want to use -fsanitize flags. |
| 190 | if(NOT MSVC) |
| 191 | set(TEST_LINK_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${TEST_LINK_FLAGS}") |
| 192 | separate_arguments(TEST_LINK_FLAGS) |
| 193 | endif() |
Alexey Samsonov | a74424e | 2013-01-28 09:07:30 +0000 | [diff] [blame] | 194 | add_custom_target(${test_name} |
Timur Iskhodzhanov | 7c70734 | 2014-05-12 08:55:20 +0000 | [diff] [blame] | 195 | COMMAND ${COMPILER_RT_TEST_COMPILER} ${TEST_OBJECTS} |
Timur Iskhodzhanov | 402bcb5 | 2014-05-28 08:38:13 +0000 | [diff] [blame] | 196 | -o "${output_bin}" |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 197 | ${TEST_LINK_FLAGS} |
Alexey Samsonov | 17cf7c5 | 2014-02-19 13:01:03 +0000 | [diff] [blame] | 198 | DEPENDS ${TEST_DEPS}) |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 199 | # Make the test suite depend on the binary. |
| 200 | add_dependencies(${test_suite} ${test_name}) |
| 201 | endmacro() |
Alexey Samsonov | c1caace | 2013-05-21 13:48:27 +0000 | [diff] [blame] | 202 | |
| 203 | macro(add_compiler_rt_resource_file target_name file_name) |
| 204 | set(src_file "${CMAKE_CURRENT_SOURCE_DIR}/${file_name}") |
Alexey Samsonov | a52e2dc | 2014-02-18 14:28:53 +0000 | [diff] [blame] | 205 | set(dst_file "${COMPILER_RT_OUTPUT_DIR}/${file_name}") |
Alexey Samsonov | 41bf0bc | 2014-02-27 07:22:59 +0000 | [diff] [blame] | 206 | add_custom_command(OUTPUT ${dst_file} |
| 207 | DEPENDS ${src_file} |
Alexey Samsonov | c1caace | 2013-05-21 13:48:27 +0000 | [diff] [blame] | 208 | COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src_file} ${dst_file} |
Alexey Samsonov | 41bf0bc | 2014-02-27 07:22:59 +0000 | [diff] [blame] | 209 | COMMENT "Copying ${file_name}...") |
| 210 | add_custom_target(${target_name} DEPENDS ${dst_file}) |
Alexey Samsonov | c1caace | 2013-05-21 13:48:27 +0000 | [diff] [blame] | 211 | # Install in Clang resource directory. |
Alexey Samsonov | a52e2dc | 2014-02-18 14:28:53 +0000 | [diff] [blame] | 212 | install(FILES ${file_name} DESTINATION ${COMPILER_RT_INSTALL_PATH}) |
Alexey Samsonov | c1caace | 2013-05-21 13:48:27 +0000 | [diff] [blame] | 213 | endmacro() |
Evgeniy Stepanov | 9514ed1 | 2014-02-27 08:41:40 +0000 | [diff] [blame] | 214 | |
| 215 | macro(add_compiler_rt_script name) |
| 216 | set(dst ${COMPILER_RT_EXEC_OUTPUT_DIR}/${name}) |
| 217 | set(src ${CMAKE_CURRENT_SOURCE_DIR}/${name}) |
| 218 | add_custom_command(OUTPUT ${dst} |
| 219 | DEPENDS ${src} |
| 220 | COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst} |
| 221 | COMMENT "Copying ${name}...") |
| 222 | add_custom_target(${name} DEPENDS ${dst}) |
| 223 | install(FILES ${dst} |
| 224 | PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE |
| 225 | DESTINATION ${COMPILER_RT_INSTALL_PATH}/bin) |
| 226 | endmacro(add_compiler_rt_script src name) |
Alexey Samsonov | 2e8e441 | 2014-05-09 22:11:03 +0000 | [diff] [blame] | 227 | |
| 228 | # Builds custom version of libc++ and installs it in <prefix>. |
| 229 | # Can be used to build sanitized versions of libc++ for running unit tests. |
| 230 | # add_custom_libcxx(<name> <prefix> |
| 231 | # DEPS <list of build deps> |
| 232 | # CFLAGS <list of compile flags>) |
| 233 | macro(add_custom_libcxx name prefix) |
| 234 | if(NOT COMPILER_RT_HAS_LIBCXX_SOURCES) |
| 235 | message(FATAL_ERROR "libcxx not found!") |
| 236 | endif() |
| 237 | |
Filipe Cabecinhas | c309de7 | 2015-06-19 03:39:24 +0000 | [diff] [blame^] | 238 | cmake_parse_arguments(LIBCXX "" "" "DEPS;CFLAGS" ${ARGN}) |
Alexey Samsonov | 2e8e441 | 2014-05-09 22:11:03 +0000 | [diff] [blame] | 239 | foreach(flag ${LIBCXX_CFLAGS}) |
| 240 | set(flagstr "${flagstr} ${flag}") |
| 241 | endforeach() |
| 242 | set(LIBCXX_CFLAGS ${flagstr}) |
| 243 | |
| 244 | if(NOT COMPILER_RT_STANDALONE_BUILD) |
| 245 | list(APPEND LIBCXX_DEPS clang) |
| 246 | endif() |
| 247 | |
| 248 | ExternalProject_Add(${name} |
| 249 | PREFIX ${prefix} |
| 250 | SOURCE_DIR ${COMPILER_RT_LIBCXX_PATH} |
| 251 | CMAKE_ARGS -DCMAKE_C_COMPILER=${COMPILER_RT_TEST_COMPILER} |
| 252 | -DCMAKE_CXX_COMPILER=${COMPILER_RT_TEST_COMPILER} |
| 253 | -DCMAKE_C_FLAGS=${LIBCXX_CFLAGS} |
| 254 | -DCMAKE_CXX_FLAGS=${LIBCXX_CFLAGS} |
| 255 | -DCMAKE_BUILD_TYPE=Release |
| 256 | -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR> |
Alexey Samsonov | 19de1ba | 2014-05-12 21:07:28 +0000 | [diff] [blame] | 257 | LOG_BUILD 1 |
| 258 | LOG_CONFIGURE 1 |
| 259 | LOG_INSTALL 1 |
Alexey Samsonov | 2e8e441 | 2014-05-09 22:11:03 +0000 | [diff] [blame] | 260 | ) |
| 261 | |
| 262 | ExternalProject_Add_Step(${name} force-reconfigure |
| 263 | DEPENDERS configure |
| 264 | ALWAYS 1 |
| 265 | ) |
| 266 | |
| 267 | ExternalProject_Add_Step(${name} clobber |
| 268 | COMMAND ${CMAKE_COMMAND} -E remove_directory <BINARY_DIR> |
| 269 | COMMAND ${CMAKE_COMMAND} -E make_directory <BINARY_DIR> |
| 270 | COMMENT "Clobberring ${name} build directory..." |
| 271 | DEPENDERS configure |
| 272 | DEPENDS ${LIBCXX_DEPS} |
| 273 | ) |
| 274 | endmacro() |