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}) |
Daniel Sanders | bfcbe76 | 2016-01-27 09:28:01 +0000 | [diff] [blame^] | 22 | list_intersect(LIB_ARCHS_${libname} DARWIN_${os}_ARCHS LIB_ARCHS) |
Chris Bieneman | 5c2fd24 | 2015-06-10 23:55:07 +0000 | [diff] [blame] | 23 | endforeach() |
Alexey Samsonov | 392c50d | 2013-01-18 16:05:21 +0000 | [diff] [blame] | 24 | else() |
Filipe Cabecinhas | c309de7 | 2015-06-19 03:39:24 +0000 | [diff] [blame] | 25 | foreach(arch ${LIB_ARCHS}) |
Chris Bieneman | 5c2fd24 | 2015-06-10 23:55:07 +0000 | [diff] [blame] | 26 | set(libname "${name}.${arch}") |
| 27 | set(libnames ${libnames} ${libname}) |
| 28 | set(extra_cflags_${libname} ${TARGET_${arch}_CFLAGS}) |
| 29 | if(NOT CAN_TARGET_${arch}) |
Filipe Cabecinhas | 030b590 | 2015-08-10 18:26:29 +0000 | [diff] [blame] | 30 | message(FATAL_ERROR "Architecture ${arch} can't be targeted") |
Chris Bieneman | 5c2fd24 | 2015-06-10 23:55:07 +0000 | [diff] [blame] | 31 | return() |
| 32 | endif() |
| 33 | endforeach() |
Alexey Samsonov | 392c50d | 2013-01-18 16:05:21 +0000 | [diff] [blame] | 34 | endif() |
Chris Bieneman | 5c2fd24 | 2015-06-10 23:55:07 +0000 | [diff] [blame] | 35 | |
| 36 | foreach(libname ${libnames}) |
| 37 | add_library(${libname} OBJECT ${LIB_SOURCES}) |
| 38 | set_target_compile_flags(${libname} |
| 39 | ${CMAKE_CXX_FLAGS} ${extra_cflags_${libname}} ${LIB_CFLAGS}) |
| 40 | set_property(TARGET ${libname} APPEND PROPERTY |
| 41 | COMPILE_DEFINITIONS ${LIB_DEFS}) |
| 42 | if(APPLE) |
Chris Bieneman | 19c8451 | 2015-08-13 20:38:16 +0000 | [diff] [blame] | 43 | set_target_properties(${libname} PROPERTIES |
| 44 | OSX_ARCHITECTURES "${LIB_ARCHS_${libname}}") |
Chris Bieneman | 5c2fd24 | 2015-06-10 23:55:07 +0000 | [diff] [blame] | 45 | endif() |
| 46 | endforeach() |
| 47 | endfunction() |
Alexey Samsonov | 5162314 | 2013-01-20 14:36:12 +0000 | [diff] [blame] | 48 | |
Chris Bieneman | 97c4610 | 2015-08-26 18:33:51 +0000 | [diff] [blame] | 49 | # Takes a list of object library targets, and a suffix and appends the proper |
| 50 | # TARGET_OBJECTS string to the output variable. |
| 51 | # format_object_libs(<output> <suffix> ...) |
| 52 | macro(format_object_libs output suffix) |
| 53 | foreach(lib ${ARGN}) |
| 54 | list(APPEND ${output} $<TARGET_OBJECTS:${lib}.${suffix}>) |
| 55 | endforeach() |
| 56 | endmacro() |
| 57 | |
Chris Bieneman | 0576c36 | 2015-08-25 19:53:09 +0000 | [diff] [blame] | 58 | # Adds static or shared runtime for a list of architectures and operating |
| 59 | # systems and puts it in the proper directory in the build and install trees. |
| 60 | # add_compiler_rt_runtime(<name> |
| 61 | # {STATIC|SHARED} |
| 62 | # ARCHS <architectures> |
| 63 | # OS <os list> |
Alexey Samsonov | e18b785 | 2014-03-31 13:45:36 +0000 | [diff] [blame] | 64 | # SOURCES <source files> |
| 65 | # CFLAGS <compile flags> |
Chris Bieneman | 0576c36 | 2015-08-25 19:53:09 +0000 | [diff] [blame] | 66 | # LINKFLAGS <linker flags> |
Evgeniy Stepanov | 4401473 | 2014-09-29 13:18:55 +0000 | [diff] [blame] | 67 | # DEFS <compile definitions> |
Chris Bieneman | 0576c36 | 2015-08-25 19:53:09 +0000 | [diff] [blame] | 68 | # LINK_LIBS <linked libraries> (only for shared library) |
Chris Bieneman | 97c4610 | 2015-08-26 18:33:51 +0000 | [diff] [blame] | 69 | # OBJECT_LIBS <object libraries to use as sources> |
Chris Bieneman | 0576c36 | 2015-08-25 19:53:09 +0000 | [diff] [blame] | 70 | # PARENT_TARGET <convenience parent target>) |
| 71 | function(add_compiler_rt_runtime name type) |
| 72 | if(NOT type MATCHES "^(STATIC|SHARED)$") |
| 73 | message(FATAL_ERROR "type argument must be STATIC or SHARED") |
| 74 | return() |
Alexey Samsonov | e16af95 | 2013-01-20 13:58:10 +0000 | [diff] [blame] | 75 | endif() |
Chris Bieneman | 0576c36 | 2015-08-25 19:53:09 +0000 | [diff] [blame] | 76 | cmake_parse_arguments(LIB |
| 77 | "" |
| 78 | "PARENT_TARGET" |
Chris Bieneman | 97c4610 | 2015-08-26 18:33:51 +0000 | [diff] [blame] | 79 | "OS;ARCHS;SOURCES;CFLAGS;LINKFLAGS;DEFS;LINK_LIBS;OBJECT_LIBS" |
Chris Bieneman | 0576c36 | 2015-08-25 19:53:09 +0000 | [diff] [blame] | 80 | ${ARGN}) |
| 81 | set(libnames) |
| 82 | if(APPLE) |
| 83 | foreach(os ${LIB_OS}) |
| 84 | if(type STREQUAL "STATIC") |
| 85 | set(libname "${name}_${os}") |
| 86 | else() |
| 87 | set(libname "${name}_${os}_dynamic") |
| 88 | set(extra_linkflags_${libname} ${DARWIN_${os}_LINKFLAGS} ${LIB_LINKFLAGS}) |
| 89 | endif() |
Daniel Sanders | bfcbe76 | 2016-01-27 09:28:01 +0000 | [diff] [blame^] | 90 | list_intersect(LIB_ARCHS_${libname} DARWIN_${os}_ARCHS LIB_ARCHS) |
Chris Bieneman | 0576c36 | 2015-08-25 19:53:09 +0000 | [diff] [blame] | 91 | if(LIB_ARCHS_${libname}) |
| 92 | list(APPEND libnames ${libname}) |
| 93 | set(extra_cflags_${libname} ${DARWIN_${os}_CFLAGS} ${LIB_CFLAGS}) |
| 94 | set(output_name_${libname} ${libname}${COMPILER_RT_OS_SUFFIX}) |
Chris Bieneman | 97c4610 | 2015-08-26 18:33:51 +0000 | [diff] [blame] | 95 | set(sources_${libname} ${LIB_SOURCES}) |
| 96 | format_object_libs(sources_${libname} ${os} ${LIB_OBJECT_LIBS}) |
Chris Bieneman | 0576c36 | 2015-08-25 19:53:09 +0000 | [diff] [blame] | 97 | endif() |
| 98 | endforeach() |
| 99 | else() |
| 100 | foreach(arch ${LIB_ARCHS}) |
| 101 | if(NOT CAN_TARGET_${arch}) |
| 102 | message(FATAL_ERROR "Architecture ${arch} can't be targeted") |
| 103 | return() |
| 104 | endif() |
| 105 | if(type STREQUAL "STATIC") |
| 106 | set(libname "${name}-${arch}") |
| 107 | set(output_name_${libname} ${libname}${COMPILER_RT_OS_SUFFIX}) |
| 108 | else() |
| 109 | set(libname "${name}-dynamic-${arch}") |
| 110 | set(extra_linkflags_${libname} ${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS} ${LIB_LINKFLAGS}) |
| 111 | if(WIN32) |
| 112 | set(output_name_${libname} ${name}_dynamic-${arch}${COMPILER_RT_OS_SUFFIX}) |
| 113 | else() |
| 114 | set(output_name_${libname} ${name}-${arch}${COMPILER_RT_OS_SUFFIX}) |
| 115 | endif() |
| 116 | endif() |
Chris Bieneman | 97c4610 | 2015-08-26 18:33:51 +0000 | [diff] [blame] | 117 | set(sources_${libname} ${LIB_SOURCES}) |
| 118 | format_object_libs(sources_${libname} ${arch} ${LIB_OBJECT_LIBS}) |
Chris Bieneman | 0576c36 | 2015-08-25 19:53:09 +0000 | [diff] [blame] | 119 | set(libnames ${libnames} ${libname}) |
| 120 | set(extra_cflags_${libname} ${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS}) |
| 121 | endforeach() |
| 122 | endif() |
Alexey Samsonov | e16af95 | 2013-01-20 13:58:10 +0000 | [diff] [blame] | 123 | |
Chris Bieneman | 0576c36 | 2015-08-25 19:53:09 +0000 | [diff] [blame] | 124 | if(NOT libnames) |
| 125 | return() |
| 126 | endif() |
| 127 | |
| 128 | if(LIB_PARENT_TARGET) |
| 129 | set(COMPONENT_OPTION COMPONENT ${LIB_PARENT_TARGET}) |
| 130 | endif() |
| 131 | |
| 132 | foreach(libname ${libnames}) |
Chris Bieneman | 97c4610 | 2015-08-26 18:33:51 +0000 | [diff] [blame] | 133 | add_library(${libname} ${type} ${sources_${libname}}) |
Chris Bieneman | 0576c36 | 2015-08-25 19:53:09 +0000 | [diff] [blame] | 134 | set_target_compile_flags(${libname} ${extra_cflags_${libname}}) |
| 135 | set_target_link_flags(${libname} ${extra_linkflags_${libname}}) |
| 136 | set_property(TARGET ${libname} APPEND PROPERTY |
| 137 | COMPILE_DEFINITIONS ${LIB_DEFS}) |
| 138 | set_target_properties(${libname} PROPERTIES |
| 139 | ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR} |
| 140 | LIBRARY_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR} |
| 141 | RUNTIME_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}) |
| 142 | set_target_properties(${libname} PROPERTIES |
| 143 | OUTPUT_NAME ${output_name_${libname}}) |
| 144 | if(LIB_LINK_LIBS AND ${type} STREQUAL "SHARED") |
| 145 | target_link_libraries(${libname} ${LIB_LINK_LIBS}) |
Chris Bieneman | 607a4f7 | 2015-08-18 17:32:18 +0000 | [diff] [blame] | 146 | endif() |
Chris Bieneman | 0576c36 | 2015-08-25 19:53:09 +0000 | [diff] [blame] | 147 | install(TARGETS ${libname} |
| 148 | ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR} |
| 149 | ${COMPONENT_OPTION} |
| 150 | LIBRARY DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR} |
| 151 | ${COMPONENT_OPTION} |
| 152 | RUNTIME DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR} |
| 153 | ${COMPONENT_OPTION}) |
| 154 | if(APPLE) |
| 155 | set_target_properties(${libname} PROPERTIES |
| 156 | OSX_ARCHITECTURES "${LIB_ARCHS_${libname}}") |
| 157 | endif() |
Chris Bieneman | 1d908be | 2015-12-03 20:08:22 +0000 | [diff] [blame] | 158 | |
| 159 | if(type STREQUAL "SHARED") |
| 160 | rt_externalize_debuginfo(${libname}) |
| 161 | endif() |
Chris Bieneman | 0576c36 | 2015-08-25 19:53:09 +0000 | [diff] [blame] | 162 | endforeach() |
| 163 | if(LIB_PARENT_TARGET) |
| 164 | add_dependencies(${LIB_PARENT_TARGET} ${libnames}) |
Chris Bieneman | 607a4f7 | 2015-08-18 17:32:18 +0000 | [diff] [blame] | 165 | endif() |
| 166 | endfunction() |
Alexey Samsonov | 2aad7c1 | 2013-01-21 08:12:20 +0000 | [diff] [blame] | 167 | |
Sumanth Gundapaneni | d52305f | 2016-01-14 18:18:49 +0000 | [diff] [blame] | 168 | # when cross compiling, COMPILER_RT_TEST_COMPILER_CFLAGS help |
| 169 | # in compilation and linking of unittests. |
| 170 | string(REPLACE " " ";" COMPILER_RT_UNITTEST_CFLAGS "${COMPILER_RT_TEST_COMPILER_CFLAGS}") |
| 171 | set(COMPILER_RT_UNITTEST_LINKFLAGS ${COMPILER_RT_UNITTEST_CFLAGS}) |
Timur Iskhodzhanov | a73e9db | 2014-05-30 12:42:57 +0000 | [diff] [blame] | 172 | |
Alexey Samsonov | 392c50d | 2013-01-18 16:05:21 +0000 | [diff] [blame] | 173 | # Unittests support. |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 174 | set(COMPILER_RT_GTEST_PATH ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest) |
Chandler Carruth | ace5350 | 2013-11-15 10:21:15 +0000 | [diff] [blame] | 175 | 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] | 176 | set(COMPILER_RT_GTEST_CFLAGS |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 177 | -DGTEST_NO_LLVM_RAW_OSTREAM=1 |
Timur Iskhodzhanov | 402bcb5 | 2014-05-28 08:38:13 +0000 | [diff] [blame] | 178 | -DGTEST_HAS_RTTI=0 |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 179 | -I${COMPILER_RT_GTEST_PATH}/include |
Chandler Carruth | ace5350 | 2013-11-15 10:21:15 +0000 | [diff] [blame] | 180 | -I${COMPILER_RT_GTEST_PATH} |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 181 | ) |
| 182 | |
Sumanth Gundapaneni | d52305f | 2016-01-14 18:18:49 +0000 | [diff] [blame] | 183 | append_list_if(COMPILER_RT_DEBUG -DSANITIZER_DEBUG=1 COMPILER_RT_UNITTEST_CFLAGS) |
Alexey Samsonov | 001d038 | 2015-01-06 20:58:40 +0000 | [diff] [blame] | 184 | |
Timur Iskhodzhanov | 402bcb5 | 2014-05-28 08:38:13 +0000 | [diff] [blame] | 185 | if(MSVC) |
Timur Iskhodzhanov | a73e9db | 2014-05-30 12:42:57 +0000 | [diff] [blame] | 186 | # clang doesn't support exceptions on Windows yet. |
Sumanth Gundapaneni | d52305f | 2016-01-14 18:18:49 +0000 | [diff] [blame] | 187 | list(APPEND COMPILER_RT_UNITTEST_CFLAGS -D_HAS_EXCEPTIONS=0) |
Timur Iskhodzhanov | a73e9db | 2014-05-30 12:42:57 +0000 | [diff] [blame] | 188 | |
| 189 | # We should teach clang to understand "#pragma intrinsic", see PR19898. |
Sumanth Gundapaneni | d52305f | 2016-01-14 18:18:49 +0000 | [diff] [blame] | 190 | list(APPEND COMPILER_RT_UNITTEST_CFLAGS -Wno-undefined-inline) |
Timur Iskhodzhanov | a73e9db | 2014-05-30 12:42:57 +0000 | [diff] [blame] | 191 | |
Timur Iskhodzhanov | 402bcb5 | 2014-05-28 08:38:13 +0000 | [diff] [blame] | 192 | # Clang doesn't support SEH on Windows yet. |
| 193 | list(APPEND COMPILER_RT_GTEST_CFLAGS -DGTEST_HAS_SEH=0) |
Timur Iskhodzhanov | a73e9db | 2014-05-30 12:42:57 +0000 | [diff] [blame] | 194 | |
| 195 | # gtest use a lot of stuff marked as deprecated on Windows. |
| 196 | list(APPEND COMPILER_RT_GTEST_CFLAGS -Wno-deprecated-declarations) |
Ehsan Akhgari | 1c4db80 | 2014-09-15 11:33:50 +0000 | [diff] [blame] | 197 | |
| 198 | # Visual Studio 2012 only supports up to 8 template parameters in |
| 199 | # std::tr1::tuple by default, but gtest requires 10 |
| 200 | if(MSVC_VERSION EQUAL 1700) |
Ehsan Akhgari | 494410f | 2014-09-25 20:42:49 +0000 | [diff] [blame] | 201 | list(APPEND COMPILER_RT_GTEST_CFLAGS -D_VARIADIC_MAX=10) |
Ehsan Akhgari | 1c4db80 | 2014-09-15 11:33:50 +0000 | [diff] [blame] | 202 | endif() |
Timur Iskhodzhanov | 402bcb5 | 2014-05-28 08:38:13 +0000 | [diff] [blame] | 203 | endif() |
| 204 | |
Alexey Samsonov | 17cf7c5 | 2014-02-19 13:01:03 +0000 | [diff] [blame] | 205 | # Link objects into a single executable with COMPILER_RT_TEST_COMPILER, |
| 206 | # using specified link flags. Make executable a part of provided |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 207 | # test_suite. |
| 208 | # add_compiler_rt_test(<test_suite> <test_name> |
Alexey Samsonov | 431f94d | 2014-12-17 23:14:01 +0000 | [diff] [blame] | 209 | # SUBDIR <subdirectory for binary> |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 210 | # OBJECTS <object files> |
| 211 | # DEPS <deps (e.g. runtime libs)> |
| 212 | # LINK_FLAGS <link flags>) |
| 213 | macro(add_compiler_rt_test test_suite test_name) |
Filipe Cabecinhas | c309de7 | 2015-06-19 03:39:24 +0000 | [diff] [blame] | 214 | cmake_parse_arguments(TEST "" "SUBDIR" "OBJECTS;DEPS;LINK_FLAGS" "" ${ARGN}) |
Alexey Samsonov | 431f94d | 2014-12-17 23:14:01 +0000 | [diff] [blame] | 215 | if(TEST_SUBDIR) |
| 216 | set(output_bin "${CMAKE_CURRENT_BINARY_DIR}/${TEST_SUBDIR}/${test_name}") |
| 217 | else() |
| 218 | set(output_bin "${CMAKE_CURRENT_BINARY_DIR}/${test_name}") |
| 219 | endif() |
Timur Iskhodzhanov | 00b915c | 2015-01-22 14:54:22 +0000 | [diff] [blame] | 220 | if(MSVC) |
| 221 | set(output_bin "${output_bin}.exe") |
| 222 | endif() |
Alexey Samsonov | 17cf7c5 | 2014-02-19 13:01:03 +0000 | [diff] [blame] | 223 | # Use host compiler in a standalone build, and just-built Clang otherwise. |
| 224 | if(NOT COMPILER_RT_STANDALONE_BUILD) |
| 225 | list(APPEND TEST_DEPS clang) |
| 226 | endif() |
Chandler Carruth | 272eef9 | 2014-05-15 16:33:58 +0000 | [diff] [blame] | 227 | # If we're not on MSVC, include the linker flags from CMAKE but override them |
| 228 | # with the provided link flags. This ensures that flags which are required to |
| 229 | # link programs at all are included, but the changes needed for the test |
| 230 | # trump. With MSVC we can't do that because CMake is set up to run link.exe |
| 231 | # when linking, not the compiler. Here, we hack it to use the compiler |
| 232 | # because we want to use -fsanitize flags. |
| 233 | if(NOT MSVC) |
| 234 | set(TEST_LINK_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${TEST_LINK_FLAGS}") |
| 235 | separate_arguments(TEST_LINK_FLAGS) |
| 236 | endif() |
Alexey Samsonov | a74424e | 2013-01-28 09:07:30 +0000 | [diff] [blame] | 237 | add_custom_target(${test_name} |
Timur Iskhodzhanov | 7c70734 | 2014-05-12 08:55:20 +0000 | [diff] [blame] | 238 | COMMAND ${COMPILER_RT_TEST_COMPILER} ${TEST_OBJECTS} |
Timur Iskhodzhanov | 402bcb5 | 2014-05-28 08:38:13 +0000 | [diff] [blame] | 239 | -o "${output_bin}" |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 240 | ${TEST_LINK_FLAGS} |
Alexey Samsonov | 17cf7c5 | 2014-02-19 13:01:03 +0000 | [diff] [blame] | 241 | DEPENDS ${TEST_DEPS}) |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 242 | # Make the test suite depend on the binary. |
| 243 | add_dependencies(${test_suite} ${test_name}) |
| 244 | endmacro() |
Alexey Samsonov | c1caace | 2013-05-21 13:48:27 +0000 | [diff] [blame] | 245 | |
| 246 | macro(add_compiler_rt_resource_file target_name file_name) |
| 247 | set(src_file "${CMAKE_CURRENT_SOURCE_DIR}/${file_name}") |
Alexey Samsonov | a52e2dc | 2014-02-18 14:28:53 +0000 | [diff] [blame] | 248 | set(dst_file "${COMPILER_RT_OUTPUT_DIR}/${file_name}") |
Alexey Samsonov | 41bf0bc | 2014-02-27 07:22:59 +0000 | [diff] [blame] | 249 | add_custom_command(OUTPUT ${dst_file} |
| 250 | DEPENDS ${src_file} |
Alexey Samsonov | c1caace | 2013-05-21 13:48:27 +0000 | [diff] [blame] | 251 | COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src_file} ${dst_file} |
Alexey Samsonov | 41bf0bc | 2014-02-27 07:22:59 +0000 | [diff] [blame] | 252 | COMMENT "Copying ${file_name}...") |
| 253 | add_custom_target(${target_name} DEPENDS ${dst_file}) |
Alexey Samsonov | c1caace | 2013-05-21 13:48:27 +0000 | [diff] [blame] | 254 | # Install in Clang resource directory. |
Alexey Samsonov | a52e2dc | 2014-02-18 14:28:53 +0000 | [diff] [blame] | 255 | install(FILES ${file_name} DESTINATION ${COMPILER_RT_INSTALL_PATH}) |
Alexey Samsonov | c1caace | 2013-05-21 13:48:27 +0000 | [diff] [blame] | 256 | endmacro() |
Evgeniy Stepanov | 9514ed1 | 2014-02-27 08:41:40 +0000 | [diff] [blame] | 257 | |
| 258 | macro(add_compiler_rt_script name) |
| 259 | set(dst ${COMPILER_RT_EXEC_OUTPUT_DIR}/${name}) |
| 260 | set(src ${CMAKE_CURRENT_SOURCE_DIR}/${name}) |
| 261 | add_custom_command(OUTPUT ${dst} |
| 262 | DEPENDS ${src} |
| 263 | COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst} |
| 264 | COMMENT "Copying ${name}...") |
| 265 | add_custom_target(${name} DEPENDS ${dst}) |
| 266 | install(FILES ${dst} |
| 267 | PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE |
| 268 | DESTINATION ${COMPILER_RT_INSTALL_PATH}/bin) |
| 269 | endmacro(add_compiler_rt_script src name) |
Alexey Samsonov | 2e8e441 | 2014-05-09 22:11:03 +0000 | [diff] [blame] | 270 | |
| 271 | # Builds custom version of libc++ and installs it in <prefix>. |
| 272 | # Can be used to build sanitized versions of libc++ for running unit tests. |
| 273 | # add_custom_libcxx(<name> <prefix> |
| 274 | # DEPS <list of build deps> |
| 275 | # CFLAGS <list of compile flags>) |
| 276 | macro(add_custom_libcxx name prefix) |
| 277 | if(NOT COMPILER_RT_HAS_LIBCXX_SOURCES) |
| 278 | message(FATAL_ERROR "libcxx not found!") |
| 279 | endif() |
| 280 | |
Filipe Cabecinhas | c309de7 | 2015-06-19 03:39:24 +0000 | [diff] [blame] | 281 | cmake_parse_arguments(LIBCXX "" "" "DEPS;CFLAGS" ${ARGN}) |
Alexey Samsonov | 2e8e441 | 2014-05-09 22:11:03 +0000 | [diff] [blame] | 282 | foreach(flag ${LIBCXX_CFLAGS}) |
| 283 | set(flagstr "${flagstr} ${flag}") |
| 284 | endforeach() |
| 285 | set(LIBCXX_CFLAGS ${flagstr}) |
| 286 | |
| 287 | if(NOT COMPILER_RT_STANDALONE_BUILD) |
| 288 | list(APPEND LIBCXX_DEPS clang) |
| 289 | endif() |
| 290 | |
| 291 | ExternalProject_Add(${name} |
| 292 | PREFIX ${prefix} |
| 293 | SOURCE_DIR ${COMPILER_RT_LIBCXX_PATH} |
Andy Gibbs | 61adea8 | 2015-12-02 13:46:56 +0000 | [diff] [blame] | 294 | CMAKE_ARGS -DCMAKE_MAKE_PROGRAM:STRING=${CMAKE_MAKE_PROGRAM} |
| 295 | -DCMAKE_C_COMPILER=${COMPILER_RT_TEST_COMPILER} |
Alexey Samsonov | 2e8e441 | 2014-05-09 22:11:03 +0000 | [diff] [blame] | 296 | -DCMAKE_CXX_COMPILER=${COMPILER_RT_TEST_COMPILER} |
| 297 | -DCMAKE_C_FLAGS=${LIBCXX_CFLAGS} |
| 298 | -DCMAKE_CXX_FLAGS=${LIBCXX_CFLAGS} |
| 299 | -DCMAKE_BUILD_TYPE=Release |
| 300 | -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR> |
Alexey Samsonov | 19de1ba | 2014-05-12 21:07:28 +0000 | [diff] [blame] | 301 | LOG_BUILD 1 |
| 302 | LOG_CONFIGURE 1 |
| 303 | LOG_INSTALL 1 |
Alexey Samsonov | 2e8e441 | 2014-05-09 22:11:03 +0000 | [diff] [blame] | 304 | ) |
Alexey Samsonov | dd6f844 | 2015-07-16 21:20:05 +0000 | [diff] [blame] | 305 | set_target_properties(${name} PROPERTIES EXCLUDE_FROM_ALL TRUE) |
Alexey Samsonov | 2e8e441 | 2014-05-09 22:11:03 +0000 | [diff] [blame] | 306 | |
| 307 | ExternalProject_Add_Step(${name} force-reconfigure |
| 308 | DEPENDERS configure |
| 309 | ALWAYS 1 |
| 310 | ) |
| 311 | |
| 312 | ExternalProject_Add_Step(${name} clobber |
| 313 | COMMAND ${CMAKE_COMMAND} -E remove_directory <BINARY_DIR> |
| 314 | COMMAND ${CMAKE_COMMAND} -E make_directory <BINARY_DIR> |
| 315 | COMMENT "Clobberring ${name} build directory..." |
| 316 | DEPENDERS configure |
| 317 | DEPENDS ${LIBCXX_DEPS} |
| 318 | ) |
| 319 | endmacro() |
Chris Bieneman | 1d908be | 2015-12-03 20:08:22 +0000 | [diff] [blame] | 320 | |
| 321 | function(rt_externalize_debuginfo name) |
| 322 | if(NOT COMPILER_RT_EXTERNALIZE_DEBUGINFO) |
| 323 | return() |
| 324 | endif() |
| 325 | |
| 326 | if(APPLE) |
| 327 | if(CMAKE_CXX_FLAGS MATCHES "-flto" |
| 328 | OR CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE} MATCHES "-flto") |
| 329 | |
| 330 | set(lto_object ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${name}-lto.o) |
Chris Bieneman | 5d5bc5b | 2015-12-03 22:52:22 +0000 | [diff] [blame] | 331 | set_property(TARGET ${name} APPEND_STRING PROPERTY |
Chris Bieneman | 960c490 | 2015-12-03 22:56:21 +0000 | [diff] [blame] | 332 | LINK_FLAGS " -Wl,-object_path_lto -Wl,${lto_object}") |
Chris Bieneman | 1d908be | 2015-12-03 20:08:22 +0000 | [diff] [blame] | 333 | endif() |
| 334 | add_custom_command(TARGET ${name} POST_BUILD |
| 335 | COMMAND xcrun dsymutil $<TARGET_FILE:${name}> |
| 336 | COMMAND xcrun strip -Sl $<TARGET_FILE:${name}>) |
| 337 | else() |
| 338 | message(FATAL_ERROR "COMPILER_RT_EXTERNALIZE_DEBUGINFO isn't implemented for non-darwin platforms!") |
| 339 | endif() |
| 340 | endfunction() |