Alexey Samsonov | 2e8e441 | 2014-05-09 22:11:03 +0000 | [diff] [blame] | 1 | include(ExternalProject) |
Alexey Samsonov | 392c50d | 2013-01-18 16:05:21 +0000 | [diff] [blame] | 2 | include(CompilerRTUtils) |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 3 | |
Etienne Bergeron | a088b36 | 2016-07-11 21:51:56 +0000 | [diff] [blame] | 4 | function(set_target_output_directories target output_dir) |
| 5 | # For RUNTIME_OUTPUT_DIRECTORY variable, Multi-configuration generators |
| 6 | # append a per-configuration subdirectory to the specified directory. |
| 7 | # To avoid the appended folder, the configuration specific variable must be |
| 8 | # set 'RUNTIME_OUTPUT_DIRECTORY_${CONF}': |
| 9 | # RUNTIME_OUTPUT_DIRECTORY_DEBUG, RUNTIME_OUTPUT_DIRECTORY_RELEASE, ... |
| 10 | if(CMAKE_CONFIGURATION_TYPES) |
| 11 | foreach(build_mode ${CMAKE_CONFIGURATION_TYPES}) |
| 12 | string(TOUPPER "${build_mode}" CONFIG_SUFFIX) |
| 13 | set_target_properties("${target}" PROPERTIES |
| 14 | "ARCHIVE_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${output_dir} |
| 15 | "LIBRARY_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${output_dir} |
| 16 | "RUNTIME_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${output_dir}) |
| 17 | endforeach() |
| 18 | else() |
| 19 | set_target_properties("${target}" PROPERTIES |
| 20 | ARCHIVE_OUTPUT_DIRECTORY ${output_dir} |
| 21 | LIBRARY_OUTPUT_DIRECTORY ${output_dir} |
| 22 | RUNTIME_OUTPUT_DIRECTORY ${output_dir}) |
| 23 | endif() |
| 24 | endfunction() |
| 25 | |
Chris Bieneman | 5c2fd24 | 2015-06-10 23:55:07 +0000 | [diff] [blame] | 26 | # Tries to add an "object library" target for a given list of OSs and/or |
| 27 | # architectures with name "<name>.<arch>" for non-Darwin platforms if |
| 28 | # architecture can be targeted, and "<name>.<os>" for Darwin platforms. |
| 29 | # add_compiler_rt_object_libraries(<name> |
Filipe Cabecinhas | c309de7 | 2015-06-19 03:39:24 +0000 | [diff] [blame] | 30 | # OS <os names> |
| 31 | # ARCHS <architectures> |
Chris Bieneman | 5c2fd24 | 2015-06-10 23:55:07 +0000 | [diff] [blame] | 32 | # SOURCES <source files> |
| 33 | # CFLAGS <compile flags> |
| 34 | # DEFS <compile definitions>) |
| 35 | function(add_compiler_rt_object_libraries name) |
Filipe Cabecinhas | c309de7 | 2015-06-19 03:39:24 +0000 | [diff] [blame] | 36 | cmake_parse_arguments(LIB "" "" "OS;ARCHS;SOURCES;CFLAGS;DEFS" ${ARGN}) |
Chris Bieneman | 5c2fd24 | 2015-06-10 23:55:07 +0000 | [diff] [blame] | 37 | set(libnames) |
| 38 | if(APPLE) |
| 39 | foreach(os ${LIB_OS}) |
| 40 | set(libname "${name}.${os}") |
| 41 | set(libnames ${libnames} ${libname}) |
| 42 | set(extra_cflags_${libname} ${DARWIN_${os}_CFLAGS}) |
Daniel Sanders | bfcbe76 | 2016-01-27 09:28:01 +0000 | [diff] [blame] | 43 | list_intersect(LIB_ARCHS_${libname} DARWIN_${os}_ARCHS LIB_ARCHS) |
Chris Bieneman | 5c2fd24 | 2015-06-10 23:55:07 +0000 | [diff] [blame] | 44 | endforeach() |
Alexey Samsonov | 392c50d | 2013-01-18 16:05:21 +0000 | [diff] [blame] | 45 | else() |
Filipe Cabecinhas | c309de7 | 2015-06-19 03:39:24 +0000 | [diff] [blame] | 46 | foreach(arch ${LIB_ARCHS}) |
Chris Bieneman | 5c2fd24 | 2015-06-10 23:55:07 +0000 | [diff] [blame] | 47 | set(libname "${name}.${arch}") |
| 48 | set(libnames ${libnames} ${libname}) |
| 49 | set(extra_cflags_${libname} ${TARGET_${arch}_CFLAGS}) |
| 50 | if(NOT CAN_TARGET_${arch}) |
Filipe Cabecinhas | 030b590 | 2015-08-10 18:26:29 +0000 | [diff] [blame] | 51 | message(FATAL_ERROR "Architecture ${arch} can't be targeted") |
Chris Bieneman | 5c2fd24 | 2015-06-10 23:55:07 +0000 | [diff] [blame] | 52 | return() |
| 53 | endif() |
| 54 | endforeach() |
Alexey Samsonov | 392c50d | 2013-01-18 16:05:21 +0000 | [diff] [blame] | 55 | endif() |
Etienne Bergeron | a088b36 | 2016-07-11 21:51:56 +0000 | [diff] [blame] | 56 | |
Chris Bieneman | 5c2fd24 | 2015-06-10 23:55:07 +0000 | [diff] [blame] | 57 | foreach(libname ${libnames}) |
| 58 | add_library(${libname} OBJECT ${LIB_SOURCES}) |
Vedant Kumar | 9c41849 | 2017-09-07 01:36:47 +0000 | [diff] [blame] | 59 | |
| 60 | # Strip out -msse3 if this isn't macOS. |
| 61 | set(target_flags ${LIB_CFLAGS}) |
| 62 | if(APPLE AND NOT "${libname}" MATCHES ".*\.osx.*") |
| 63 | list(REMOVE_ITEM target_flags "-msse3") |
| 64 | endif() |
| 65 | |
Aaron Smith | 9d41aea | 2018-04-11 17:31:18 +0000 | [diff] [blame] | 66 | set_target_compile_flags(${libname} |
| 67 | ${CMAKE_CXX_FLAGS} ${extra_cflags_${libname}} ${target_flags}) |
Chris Bieneman | 5c2fd24 | 2015-06-10 23:55:07 +0000 | [diff] [blame] | 68 | set_property(TARGET ${libname} APPEND PROPERTY |
| 69 | COMPILE_DEFINITIONS ${LIB_DEFS}) |
Etienne Bergeron | a088b36 | 2016-07-11 21:51:56 +0000 | [diff] [blame] | 70 | set_target_properties(${libname} PROPERTIES FOLDER "Compiler-RT Libraries") |
Chris Bieneman | 5c2fd24 | 2015-06-10 23:55:07 +0000 | [diff] [blame] | 71 | if(APPLE) |
Chris Bieneman | 19c8451 | 2015-08-13 20:38:16 +0000 | [diff] [blame] | 72 | set_target_properties(${libname} PROPERTIES |
| 73 | OSX_ARCHITECTURES "${LIB_ARCHS_${libname}}") |
Chris Bieneman | 5c2fd24 | 2015-06-10 23:55:07 +0000 | [diff] [blame] | 74 | endif() |
| 75 | endforeach() |
| 76 | endfunction() |
Alexey Samsonov | 5162314 | 2013-01-20 14:36:12 +0000 | [diff] [blame] | 77 | |
Chris Bieneman | 97c4610 | 2015-08-26 18:33:51 +0000 | [diff] [blame] | 78 | # Takes a list of object library targets, and a suffix and appends the proper |
| 79 | # TARGET_OBJECTS string to the output variable. |
| 80 | # format_object_libs(<output> <suffix> ...) |
| 81 | macro(format_object_libs output suffix) |
| 82 | foreach(lib ${ARGN}) |
| 83 | list(APPEND ${output} $<TARGET_OBJECTS:${lib}.${suffix}>) |
| 84 | endforeach() |
| 85 | endmacro() |
| 86 | |
Chris Bieneman | 3bb5562 | 2016-08-26 20:52:22 +0000 | [diff] [blame] | 87 | function(add_compiler_rt_component name) |
| 88 | add_custom_target(${name}) |
| 89 | set_target_properties(${name} PROPERTIES FOLDER "Compiler-RT Misc") |
| 90 | if(COMMAND runtime_register_component) |
| 91 | runtime_register_component(${name}) |
| 92 | endif() |
| 93 | add_dependencies(compiler-rt ${name}) |
| 94 | endfunction() |
| 95 | |
Kuba Mracek | 0a72880 | 2017-11-29 19:27:25 +0000 | [diff] [blame] | 96 | function(add_asm_sources output) |
| 97 | set(${output} ${ARGN} PARENT_SCOPE) |
| 98 | # Xcode will try to compile asm files as C ('clang -x c'), and that will fail. |
| 99 | if (${CMAKE_GENERATOR} STREQUAL "Xcode") |
| 100 | enable_language(ASM) |
| 101 | else() |
| 102 | # Pass ASM file directly to the C++ compiler. |
| 103 | set_source_files_properties(${ARGN} PROPERTIES LANGUAGE C) |
| 104 | endif() |
| 105 | endfunction() |
| 106 | |
Evgeniy Stepanov | 20bf9b4 | 2017-08-29 22:12:31 +0000 | [diff] [blame] | 107 | macro(set_output_name output name arch) |
| 108 | if(ANDROID AND ${arch} STREQUAL "i386") |
| 109 | set(${output} "${name}-i686${COMPILER_RT_OS_SUFFIX}") |
| 110 | else() |
| 111 | set(${output} "${name}-${arch}${COMPILER_RT_OS_SUFFIX}") |
| 112 | endif() |
| 113 | endmacro() |
| 114 | |
Chris Bieneman | 0576c36 | 2015-08-25 19:53:09 +0000 | [diff] [blame] | 115 | # Adds static or shared runtime for a list of architectures and operating |
| 116 | # systems and puts it in the proper directory in the build and install trees. |
| 117 | # add_compiler_rt_runtime(<name> |
| 118 | # {STATIC|SHARED} |
| 119 | # ARCHS <architectures> |
| 120 | # OS <os list> |
Alexey Samsonov | e18b785 | 2014-03-31 13:45:36 +0000 | [diff] [blame] | 121 | # SOURCES <source files> |
| 122 | # CFLAGS <compile flags> |
Francis Ricci | 9f93113 | 2017-01-10 04:33:04 +0000 | [diff] [blame] | 123 | # LINK_FLAGS <linker flags> |
Evgeniy Stepanov | 4401473 | 2014-09-29 13:18:55 +0000 | [diff] [blame] | 124 | # DEFS <compile definitions> |
Chris Bieneman | 0576c36 | 2015-08-25 19:53:09 +0000 | [diff] [blame] | 125 | # LINK_LIBS <linked libraries> (only for shared library) |
Chris Bieneman | 97c4610 | 2015-08-26 18:33:51 +0000 | [diff] [blame] | 126 | # OBJECT_LIBS <object libraries to use as sources> |
Chris Bieneman | 0576c36 | 2015-08-25 19:53:09 +0000 | [diff] [blame] | 127 | # PARENT_TARGET <convenience parent target>) |
| 128 | function(add_compiler_rt_runtime name type) |
| 129 | if(NOT type MATCHES "^(STATIC|SHARED)$") |
| 130 | message(FATAL_ERROR "type argument must be STATIC or SHARED") |
| 131 | return() |
Alexey Samsonov | e16af95 | 2013-01-20 13:58:10 +0000 | [diff] [blame] | 132 | endif() |
Chris Bieneman | 0576c36 | 2015-08-25 19:53:09 +0000 | [diff] [blame] | 133 | cmake_parse_arguments(LIB |
| 134 | "" |
| 135 | "PARENT_TARGET" |
Francis Ricci | 9f93113 | 2017-01-10 04:33:04 +0000 | [diff] [blame] | 136 | "OS;ARCHS;SOURCES;CFLAGS;LINK_FLAGS;DEFS;LINK_LIBS;OBJECT_LIBS" |
Chris Bieneman | 0576c36 | 2015-08-25 19:53:09 +0000 | [diff] [blame] | 137 | ${ARGN}) |
| 138 | set(libnames) |
Bob Haarman | 955475a | 2017-03-22 17:25:49 +0000 | [diff] [blame] | 139 | # Until we support this some other way, build compiler-rt runtime without LTO |
| 140 | # to allow non-LTO projects to link with it. |
| 141 | if(COMPILER_RT_HAS_FNO_LTO_FLAG) |
| 142 | set(NO_LTO_FLAGS "-fno-lto") |
| 143 | else() |
| 144 | set(NO_LTO_FLAGS "") |
| 145 | endif() |
Vedant Kumar | 160179b | 2017-09-01 23:23:59 +0000 | [diff] [blame] | 146 | |
Chris Bieneman | 0576c36 | 2015-08-25 19:53:09 +0000 | [diff] [blame] | 147 | if(APPLE) |
| 148 | foreach(os ${LIB_OS}) |
Vedant Kumar | 160179b | 2017-09-01 23:23:59 +0000 | [diff] [blame] | 149 | # Strip out -msse3 if this isn't macOS. |
Vedant Kumar | 160179b | 2017-09-01 23:23:59 +0000 | [diff] [blame] | 150 | list(LENGTH LIB_CFLAGS HAS_EXTRA_CFLAGS) |
| 151 | if(HAS_EXTRA_CFLAGS AND NOT "${os}" MATCHES "^(osx)$") |
| 152 | list(REMOVE_ITEM LIB_CFLAGS "-msse3") |
| 153 | endif() |
Chris Bieneman | 0576c36 | 2015-08-25 19:53:09 +0000 | [diff] [blame] | 154 | if(type STREQUAL "STATIC") |
| 155 | set(libname "${name}_${os}") |
| 156 | else() |
| 157 | set(libname "${name}_${os}_dynamic") |
Francis Ricci | 9f93113 | 2017-01-10 04:33:04 +0000 | [diff] [blame] | 158 | set(extra_link_flags_${libname} ${DARWIN_${os}_LINK_FLAGS} ${LIB_LINK_FLAGS}) |
Chris Bieneman | 0576c36 | 2015-08-25 19:53:09 +0000 | [diff] [blame] | 159 | endif() |
Daniel Sanders | bfcbe76 | 2016-01-27 09:28:01 +0000 | [diff] [blame] | 160 | list_intersect(LIB_ARCHS_${libname} DARWIN_${os}_ARCHS LIB_ARCHS) |
Chris Bieneman | 0576c36 | 2015-08-25 19:53:09 +0000 | [diff] [blame] | 161 | if(LIB_ARCHS_${libname}) |
| 162 | list(APPEND libnames ${libname}) |
Bob Haarman | 955475a | 2017-03-22 17:25:49 +0000 | [diff] [blame] | 163 | set(extra_cflags_${libname} ${DARWIN_${os}_CFLAGS} ${NO_LTO_FLAGS} ${LIB_CFLAGS}) |
Chris Bieneman | 0576c36 | 2015-08-25 19:53:09 +0000 | [diff] [blame] | 164 | set(output_name_${libname} ${libname}${COMPILER_RT_OS_SUFFIX}) |
Chris Bieneman | 97c4610 | 2015-08-26 18:33:51 +0000 | [diff] [blame] | 165 | set(sources_${libname} ${LIB_SOURCES}) |
| 166 | format_object_libs(sources_${libname} ${os} ${LIB_OBJECT_LIBS}) |
Chris Bieneman | 0576c36 | 2015-08-25 19:53:09 +0000 | [diff] [blame] | 167 | endif() |
| 168 | endforeach() |
| 169 | else() |
| 170 | foreach(arch ${LIB_ARCHS}) |
| 171 | if(NOT CAN_TARGET_${arch}) |
| 172 | message(FATAL_ERROR "Architecture ${arch} can't be targeted") |
| 173 | return() |
| 174 | endif() |
| 175 | if(type STREQUAL "STATIC") |
| 176 | set(libname "${name}-${arch}") |
Evgeniy Stepanov | 20bf9b4 | 2017-08-29 22:12:31 +0000 | [diff] [blame] | 177 | set_output_name(output_name_${libname} ${name} ${arch}) |
Chris Bieneman | 0576c36 | 2015-08-25 19:53:09 +0000 | [diff] [blame] | 178 | else() |
| 179 | set(libname "${name}-dynamic-${arch}") |
Etienne Bergeron | a6c33c4 | 2016-06-21 14:46:32 +0000 | [diff] [blame] | 180 | set(extra_cflags_${libname} ${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS}) |
Francis Ricci | 9f93113 | 2017-01-10 04:33:04 +0000 | [diff] [blame] | 181 | set(extra_link_flags_${libname} ${TARGET_${arch}_LINK_FLAGS} ${LIB_LINK_FLAGS}) |
Chris Bieneman | 0576c36 | 2015-08-25 19:53:09 +0000 | [diff] [blame] | 182 | if(WIN32) |
Evgeniy Stepanov | 20bf9b4 | 2017-08-29 22:12:31 +0000 | [diff] [blame] | 183 | set_output_name(output_name_${libname} ${name}_dynamic ${arch}) |
Chris Bieneman | 0576c36 | 2015-08-25 19:53:09 +0000 | [diff] [blame] | 184 | else() |
Evgeniy Stepanov | 20bf9b4 | 2017-08-29 22:12:31 +0000 | [diff] [blame] | 185 | set_output_name(output_name_${libname} ${name} ${arch}) |
Chris Bieneman | 0576c36 | 2015-08-25 19:53:09 +0000 | [diff] [blame] | 186 | endif() |
| 187 | endif() |
Chris Bieneman | 97c4610 | 2015-08-26 18:33:51 +0000 | [diff] [blame] | 188 | set(sources_${libname} ${LIB_SOURCES}) |
| 189 | format_object_libs(sources_${libname} ${arch} ${LIB_OBJECT_LIBS}) |
Chris Bieneman | 0576c36 | 2015-08-25 19:53:09 +0000 | [diff] [blame] | 190 | set(libnames ${libnames} ${libname}) |
Bob Haarman | 955475a | 2017-03-22 17:25:49 +0000 | [diff] [blame] | 191 | set(extra_cflags_${libname} ${TARGET_${arch}_CFLAGS} ${NO_LTO_FLAGS} ${LIB_CFLAGS}) |
Chris Bieneman | 0576c36 | 2015-08-25 19:53:09 +0000 | [diff] [blame] | 192 | endforeach() |
| 193 | endif() |
Alexey Samsonov | e16af95 | 2013-01-20 13:58:10 +0000 | [diff] [blame] | 194 | |
Chris Bieneman | 0576c36 | 2015-08-25 19:53:09 +0000 | [diff] [blame] | 195 | if(NOT libnames) |
| 196 | return() |
| 197 | endif() |
| 198 | |
| 199 | if(LIB_PARENT_TARGET) |
Chris Bieneman | f0dfa19 | 2016-02-23 21:55:38 +0000 | [diff] [blame] | 200 | # If the parent targets aren't created we should create them |
| 201 | if(NOT TARGET ${LIB_PARENT_TARGET}) |
| 202 | add_custom_target(${LIB_PARENT_TARGET}) |
| 203 | endif() |
| 204 | if(NOT TARGET install-${LIB_PARENT_TARGET}) |
| 205 | # The parent install target specifies the parent component to scrape up |
| 206 | # anything not installed by the individual install targets, and to handle |
| 207 | # installation when running the multi-configuration generators. |
| 208 | add_custom_target(install-${LIB_PARENT_TARGET} |
| 209 | DEPENDS ${LIB_PARENT_TARGET} |
| 210 | COMMAND "${CMAKE_COMMAND}" |
| 211 | -DCMAKE_INSTALL_COMPONENT=${LIB_PARENT_TARGET} |
| 212 | -P "${CMAKE_BINARY_DIR}/cmake_install.cmake") |
Shoaib Meenai | db05652 | 2017-12-01 19:06:29 +0000 | [diff] [blame] | 213 | add_custom_target(install-${LIB_PARENT_TARGET}-stripped |
| 214 | DEPENDS ${LIB_PARENT_TARGET} |
| 215 | COMMAND "${CMAKE_COMMAND}" |
| 216 | -DCMAKE_INSTALL_COMPONENT=${LIB_PARENT_TARGET} |
| 217 | -DCMAKE_INSTALL_DO_STRIP=1 |
| 218 | -P "${CMAKE_BINARY_DIR}/cmake_install.cmake") |
Etienne Bergeron | a088b36 | 2016-07-11 21:51:56 +0000 | [diff] [blame] | 219 | set_target_properties(install-${LIB_PARENT_TARGET} PROPERTIES |
| 220 | FOLDER "Compiler-RT Misc") |
Shoaib Meenai | db05652 | 2017-12-01 19:06:29 +0000 | [diff] [blame] | 221 | set_target_properties(install-${LIB_PARENT_TARGET}-stripped PROPERTIES |
| 222 | FOLDER "Compiler-RT Misc") |
Chris Bieneman | a213e3e | 2016-08-19 22:17:46 +0000 | [diff] [blame] | 223 | add_dependencies(install-compiler-rt install-${LIB_PARENT_TARGET}) |
Shoaib Meenai | db05652 | 2017-12-01 19:06:29 +0000 | [diff] [blame] | 224 | add_dependencies(install-compiler-rt-stripped install-${LIB_PARENT_TARGET}-stripped) |
Chris Bieneman | f0dfa19 | 2016-02-23 21:55:38 +0000 | [diff] [blame] | 225 | endif() |
Chris Bieneman | 0576c36 | 2015-08-25 19:53:09 +0000 | [diff] [blame] | 226 | endif() |
| 227 | |
| 228 | foreach(libname ${libnames}) |
Etienne Bergeron | a088b36 | 2016-07-11 21:51:56 +0000 | [diff] [blame] | 229 | # If you are using a multi-configuration generator we don't generate |
Chris Bieneman | f0dfa19 | 2016-02-23 21:55:38 +0000 | [diff] [blame] | 230 | # per-library install rules, so we fall back to the parent target COMPONENT |
| 231 | if(CMAKE_CONFIGURATION_TYPES AND LIB_PARENT_TARGET) |
| 232 | set(COMPONENT_OPTION COMPONENT ${LIB_PARENT_TARGET}) |
| 233 | else() |
| 234 | set(COMPONENT_OPTION COMPONENT ${libname}) |
| 235 | endif() |
| 236 | |
Chris Bieneman | 97c4610 | 2015-08-26 18:33:51 +0000 | [diff] [blame] | 237 | add_library(${libname} ${type} ${sources_${libname}}) |
Chris Bieneman | 0576c36 | 2015-08-25 19:53:09 +0000 | [diff] [blame] | 238 | set_target_compile_flags(${libname} ${extra_cflags_${libname}}) |
Francis Ricci | 9f93113 | 2017-01-10 04:33:04 +0000 | [diff] [blame] | 239 | set_target_link_flags(${libname} ${extra_link_flags_${libname}}) |
Etienne Bergeron | a088b36 | 2016-07-11 21:51:56 +0000 | [diff] [blame] | 240 | set_property(TARGET ${libname} APPEND PROPERTY |
Chris Bieneman | 0576c36 | 2015-08-25 19:53:09 +0000 | [diff] [blame] | 241 | COMPILE_DEFINITIONS ${LIB_DEFS}) |
Etienne Bergeron | a088b36 | 2016-07-11 21:51:56 +0000 | [diff] [blame] | 242 | set_target_output_directories(${libname} ${COMPILER_RT_LIBRARY_OUTPUT_DIR}) |
Chris Bieneman | 0576c36 | 2015-08-25 19:53:09 +0000 | [diff] [blame] | 243 | set_target_properties(${libname} PROPERTIES |
| 244 | OUTPUT_NAME ${output_name_${libname}}) |
Etienne Bergeron | a088b36 | 2016-07-11 21:51:56 +0000 | [diff] [blame] | 245 | set_target_properties(${libname} PROPERTIES FOLDER "Compiler-RT Runtime") |
George Karpenkov | 0c8339c | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 246 | if(LIB_LINK_LIBS) |
| 247 | target_link_libraries(${libname} ${LIB_LINK_LIBS}) |
| 248 | endif() |
Francis Ricci | 4a0c5cd | 2016-09-07 20:32:48 +0000 | [diff] [blame] | 249 | if(${type} STREQUAL "SHARED") |
Don Hinton | 87a6c64 | 2018-01-27 21:14:17 +0000 | [diff] [blame] | 250 | if(COMMAND llvm_setup_rpath) |
| 251 | llvm_setup_rpath(${libname}) |
| 252 | endif() |
Francis Ricci | 4a0c5cd | 2016-09-07 20:32:48 +0000 | [diff] [blame] | 253 | if(WIN32 AND NOT CYGWIN AND NOT MINGW) |
| 254 | set_target_properties(${libname} PROPERTIES IMPORT_PREFIX "") |
| 255 | set_target_properties(${libname} PROPERTIES IMPORT_SUFFIX ".lib") |
| 256 | endif() |
Kuba Mracek | fcf0ff1 | 2017-04-26 18:59:22 +0000 | [diff] [blame] | 257 | if(APPLE) |
| 258 | # Ad-hoc sign the dylibs |
| 259 | add_custom_command(TARGET ${libname} |
| 260 | POST_BUILD |
| 261 | COMMAND codesign --sign - $<TARGET_FILE:${libname}> |
| 262 | WORKING_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR} |
| 263 | ) |
| 264 | endif() |
Chris Bieneman | 607a4f7 | 2015-08-18 17:32:18 +0000 | [diff] [blame] | 265 | endif() |
Chris Bieneman | 0576c36 | 2015-08-25 19:53:09 +0000 | [diff] [blame] | 266 | install(TARGETS ${libname} |
| 267 | ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR} |
| 268 | ${COMPONENT_OPTION} |
| 269 | LIBRARY DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR} |
| 270 | ${COMPONENT_OPTION} |
| 271 | RUNTIME DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR} |
| 272 | ${COMPONENT_OPTION}) |
Chris Bieneman | f0dfa19 | 2016-02-23 21:55:38 +0000 | [diff] [blame] | 273 | |
| 274 | # We only want to generate per-library install targets if you aren't using |
| 275 | # an IDE because the extra targets get cluttered in IDEs. |
| 276 | if(NOT CMAKE_CONFIGURATION_TYPES) |
| 277 | add_custom_target(install-${libname} |
| 278 | DEPENDS ${libname} |
| 279 | COMMAND "${CMAKE_COMMAND}" |
| 280 | -DCMAKE_INSTALL_COMPONENT=${libname} |
| 281 | -P "${CMAKE_BINARY_DIR}/cmake_install.cmake") |
Shoaib Meenai | db05652 | 2017-12-01 19:06:29 +0000 | [diff] [blame] | 282 | add_custom_target(install-${libname}-stripped |
| 283 | DEPENDS ${libname} |
| 284 | COMMAND "${CMAKE_COMMAND}" |
| 285 | -DCMAKE_INSTALL_COMPONENT=${libname} |
| 286 | -DCMAKE_INSTALL_DO_STRIP=1 |
| 287 | -P "${CMAKE_BINARY_DIR}/cmake_install.cmake") |
Chris Bieneman | f0dfa19 | 2016-02-23 21:55:38 +0000 | [diff] [blame] | 288 | # If you have a parent target specified, we bind the new install target |
| 289 | # to the parent install target. |
| 290 | if(LIB_PARENT_TARGET) |
| 291 | add_dependencies(install-${LIB_PARENT_TARGET} install-${libname}) |
Shoaib Meenai | db05652 | 2017-12-01 19:06:29 +0000 | [diff] [blame] | 292 | add_dependencies(install-${LIB_PARENT_TARGET}-stripped install-${libname}-stripped) |
Chris Bieneman | f0dfa19 | 2016-02-23 21:55:38 +0000 | [diff] [blame] | 293 | endif() |
| 294 | endif() |
Chris Bieneman | 0576c36 | 2015-08-25 19:53:09 +0000 | [diff] [blame] | 295 | if(APPLE) |
| 296 | set_target_properties(${libname} PROPERTIES |
| 297 | OSX_ARCHITECTURES "${LIB_ARCHS_${libname}}") |
| 298 | endif() |
Chris Bieneman | 1d908be | 2015-12-03 20:08:22 +0000 | [diff] [blame] | 299 | |
| 300 | if(type STREQUAL "SHARED") |
| 301 | rt_externalize_debuginfo(${libname}) |
| 302 | endif() |
Chris Bieneman | 0576c36 | 2015-08-25 19:53:09 +0000 | [diff] [blame] | 303 | endforeach() |
| 304 | if(LIB_PARENT_TARGET) |
Alexey Samsonov | 124a8a5 | 2016-02-26 20:59:40 +0000 | [diff] [blame] | 305 | add_dependencies(${LIB_PARENT_TARGET} ${libnames}) |
Chris Bieneman | 607a4f7 | 2015-08-18 17:32:18 +0000 | [diff] [blame] | 306 | endif() |
| 307 | endfunction() |
Alexey Samsonov | 2aad7c1 | 2013-01-21 08:12:20 +0000 | [diff] [blame] | 308 | |
Sumanth Gundapaneni | d52305f | 2016-01-14 18:18:49 +0000 | [diff] [blame] | 309 | # when cross compiling, COMPILER_RT_TEST_COMPILER_CFLAGS help |
| 310 | # in compilation and linking of unittests. |
| 311 | string(REPLACE " " ";" COMPILER_RT_UNITTEST_CFLAGS "${COMPILER_RT_TEST_COMPILER_CFLAGS}") |
Francis Ricci | 9f93113 | 2017-01-10 04:33:04 +0000 | [diff] [blame] | 312 | set(COMPILER_RT_UNITTEST_LINK_FLAGS ${COMPILER_RT_UNITTEST_CFLAGS}) |
Timur Iskhodzhanov | a73e9db | 2014-05-30 12:42:57 +0000 | [diff] [blame] | 313 | |
Alexey Samsonov | 392c50d | 2013-01-18 16:05:21 +0000 | [diff] [blame] | 314 | # Unittests support. |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 315 | set(COMPILER_RT_GTEST_PATH ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest) |
Chandler Carruth | ace5350 | 2013-11-15 10:21:15 +0000 | [diff] [blame] | 316 | 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] | 317 | set(COMPILER_RT_GTEST_CFLAGS |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 318 | -DGTEST_NO_LLVM_RAW_OSTREAM=1 |
Timur Iskhodzhanov | 402bcb5 | 2014-05-28 08:38:13 +0000 | [diff] [blame] | 319 | -DGTEST_HAS_RTTI=0 |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 320 | -I${COMPILER_RT_GTEST_PATH}/include |
Chandler Carruth | ace5350 | 2013-11-15 10:21:15 +0000 | [diff] [blame] | 321 | -I${COMPILER_RT_GTEST_PATH} |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 322 | ) |
| 323 | |
Sumanth Gundapaneni | d52305f | 2016-01-14 18:18:49 +0000 | [diff] [blame] | 324 | append_list_if(COMPILER_RT_DEBUG -DSANITIZER_DEBUG=1 COMPILER_RT_UNITTEST_CFLAGS) |
Chandler Carruth | e78a0bf | 2017-01-05 03:41:41 +0000 | [diff] [blame] | 325 | append_list_if(COMPILER_RT_HAS_WCOVERED_SWITCH_DEFAULT_FLAG -Wno-covered-switch-default COMPILER_RT_UNITTEST_CFLAGS) |
Alexey Samsonov | 001d038 | 2015-01-06 20:58:40 +0000 | [diff] [blame] | 326 | |
Timur Iskhodzhanov | 402bcb5 | 2014-05-28 08:38:13 +0000 | [diff] [blame] | 327 | if(MSVC) |
Timur Iskhodzhanov | a73e9db | 2014-05-30 12:42:57 +0000 | [diff] [blame] | 328 | # clang doesn't support exceptions on Windows yet. |
Sumanth Gundapaneni | d52305f | 2016-01-14 18:18:49 +0000 | [diff] [blame] | 329 | list(APPEND COMPILER_RT_UNITTEST_CFLAGS -D_HAS_EXCEPTIONS=0) |
Timur Iskhodzhanov | a73e9db | 2014-05-30 12:42:57 +0000 | [diff] [blame] | 330 | |
| 331 | # We should teach clang to understand "#pragma intrinsic", see PR19898. |
Sumanth Gundapaneni | d52305f | 2016-01-14 18:18:49 +0000 | [diff] [blame] | 332 | list(APPEND COMPILER_RT_UNITTEST_CFLAGS -Wno-undefined-inline) |
Timur Iskhodzhanov | a73e9db | 2014-05-30 12:42:57 +0000 | [diff] [blame] | 333 | |
Timur Iskhodzhanov | 402bcb5 | 2014-05-28 08:38:13 +0000 | [diff] [blame] | 334 | # Clang doesn't support SEH on Windows yet. |
| 335 | list(APPEND COMPILER_RT_GTEST_CFLAGS -DGTEST_HAS_SEH=0) |
Timur Iskhodzhanov | a73e9db | 2014-05-30 12:42:57 +0000 | [diff] [blame] | 336 | |
| 337 | # gtest use a lot of stuff marked as deprecated on Windows. |
| 338 | list(APPEND COMPILER_RT_GTEST_CFLAGS -Wno-deprecated-declarations) |
Timur Iskhodzhanov | 402bcb5 | 2014-05-28 08:38:13 +0000 | [diff] [blame] | 339 | endif() |
| 340 | |
George Karpenkov | 38e269e | 2017-08-15 22:56:10 +0000 | [diff] [blame] | 341 | # Compile and register compiler-rt tests. |
| 342 | # generate_compiler_rt_tests(<output object files> <test_suite> <test_name> |
| 343 | # <test architecture> |
| 344 | # KIND <custom prefix> |
| 345 | # SUBDIR <subdirectory for testing binary> |
| 346 | # SOURCES <sources to compile> |
| 347 | # RUNTIME <tests runtime to link in> |
| 348 | # CFLAGS <compile-time flags> |
| 349 | # COMPILE_DEPS <compile-time dependencies> |
| 350 | # DEPS <dependencies> |
| 351 | # LINK_FLAGS <flags to use during linking> |
| 352 | # ) |
| 353 | function(generate_compiler_rt_tests test_objects test_suite testname arch) |
| 354 | cmake_parse_arguments(TEST "" "KIND;RUNTIME;SUBDIR" |
| 355 | "SOURCES;COMPILE_DEPS;DEPS;CFLAGS;LINK_FLAGS" ${ARGN}) |
| 356 | |
| 357 | foreach(source ${TEST_SOURCES}) |
| 358 | sanitizer_test_compile( |
| 359 | "${test_objects}" "${source}" "${arch}" |
| 360 | KIND ${TEST_KIND} |
| 361 | COMPILE_DEPS ${TEST_COMPILE_DEPS} |
| 362 | DEPS ${TEST_DEPS} |
| 363 | CFLAGS ${TEST_CFLAGS} |
| 364 | ) |
| 365 | endforeach() |
| 366 | |
| 367 | set(TEST_DEPS ${${test_objects}}) |
| 368 | |
| 369 | if(NOT "${TEST_RUNTIME}" STREQUAL "") |
| 370 | list(APPEND TEST_DEPS ${TEST_RUNTIME}) |
| 371 | list(APPEND "${test_objects}" $<TARGET_FILE:${TEST_RUNTIME}>) |
| 372 | endif() |
| 373 | |
| 374 | add_compiler_rt_test(${test_suite} "${testname}" "${arch}" |
| 375 | SUBDIR ${TEST_SUBDIR} |
| 376 | OBJECTS ${${test_objects}} |
| 377 | DEPS ${TEST_DEPS} |
George Karpenkov | bcb584b | 2017-08-15 23:22:52 +0000 | [diff] [blame] | 378 | LINK_FLAGS ${TEST_LINK_FLAGS} |
George Karpenkov | 38e269e | 2017-08-15 22:56:10 +0000 | [diff] [blame] | 379 | ) |
| 380 | set("${test_objects}" "${${test_objects}}" PARENT_SCOPE) |
| 381 | endfunction() |
| 382 | |
Alexey Samsonov | 17cf7c5 | 2014-02-19 13:01:03 +0000 | [diff] [blame] | 383 | # Link objects into a single executable with COMPILER_RT_TEST_COMPILER, |
| 384 | # using specified link flags. Make executable a part of provided |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 385 | # test_suite. |
George Karpenkov | 38e269e | 2017-08-15 22:56:10 +0000 | [diff] [blame] | 386 | # add_compiler_rt_test(<test_suite> <test_name> <arch> |
Alexey Samsonov | 431f94d | 2014-12-17 23:14:01 +0000 | [diff] [blame] | 387 | # SUBDIR <subdirectory for binary> |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 388 | # OBJECTS <object files> |
| 389 | # DEPS <deps (e.g. runtime libs)> |
| 390 | # LINK_FLAGS <link flags>) |
George Karpenkov | 38e269e | 2017-08-15 22:56:10 +0000 | [diff] [blame] | 391 | function(add_compiler_rt_test test_suite test_name arch) |
Filipe Cabecinhas | c309de7 | 2015-06-19 03:39:24 +0000 | [diff] [blame] | 392 | cmake_parse_arguments(TEST "" "SUBDIR" "OBJECTS;DEPS;LINK_FLAGS" "" ${ARGN}) |
George Karpenkov | 8ffc41a | 2017-08-15 18:32:28 +0000 | [diff] [blame] | 393 | set(output_dir ${CMAKE_CURRENT_BINARY_DIR}) |
Alexey Samsonov | 431f94d | 2014-12-17 23:14:01 +0000 | [diff] [blame] | 394 | if(TEST_SUBDIR) |
George Karpenkov | 8ffc41a | 2017-08-15 18:32:28 +0000 | [diff] [blame] | 395 | set(output_dir "${output_dir}/${TEST_SUBDIR}") |
Alexey Samsonov | 431f94d | 2014-12-17 23:14:01 +0000 | [diff] [blame] | 396 | endif() |
George Karpenkov | 8ffc41a | 2017-08-15 18:32:28 +0000 | [diff] [blame] | 397 | set(output_dir "${output_dir}/${CMAKE_CFG_INTDIR}") |
| 398 | file(MAKE_DIRECTORY "${output_dir}") |
| 399 | set(output_bin "${output_dir}/${test_name}") |
Timur Iskhodzhanov | 00b915c | 2015-01-22 14:54:22 +0000 | [diff] [blame] | 400 | if(MSVC) |
| 401 | set(output_bin "${output_bin}.exe") |
| 402 | endif() |
Etienne Bergeron | 4659e36 | 2016-05-16 14:58:07 +0000 | [diff] [blame] | 403 | |
Alexey Samsonov | 17cf7c5 | 2014-02-19 13:01:03 +0000 | [diff] [blame] | 404 | # Use host compiler in a standalone build, and just-built Clang otherwise. |
| 405 | if(NOT COMPILER_RT_STANDALONE_BUILD) |
| 406 | list(APPEND TEST_DEPS clang) |
| 407 | endif() |
George Karpenkov | 38e269e | 2017-08-15 22:56:10 +0000 | [diff] [blame] | 408 | |
| 409 | get_target_flags_for_arch(${arch} TARGET_LINK_FLAGS) |
| 410 | list(APPEND TEST_LINK_FLAGS ${TARGET_LINK_FLAGS}) |
| 411 | |
Chandler Carruth | 272eef9 | 2014-05-15 16:33:58 +0000 | [diff] [blame] | 412 | # If we're not on MSVC, include the linker flags from CMAKE but override them |
| 413 | # with the provided link flags. This ensures that flags which are required to |
| 414 | # link programs at all are included, but the changes needed for the test |
| 415 | # trump. With MSVC we can't do that because CMake is set up to run link.exe |
| 416 | # when linking, not the compiler. Here, we hack it to use the compiler |
| 417 | # because we want to use -fsanitize flags. |
| 418 | if(NOT MSVC) |
| 419 | set(TEST_LINK_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${TEST_LINK_FLAGS}") |
| 420 | separate_arguments(TEST_LINK_FLAGS) |
| 421 | endif() |
George Karpenkov | 916b56d | 2017-08-21 21:19:13 +0000 | [diff] [blame] | 422 | add_custom_command( |
| 423 | OUTPUT "${output_bin}" |
| 424 | COMMAND ${COMPILER_RT_TEST_COMPILER} ${TEST_OBJECTS} -o "${output_bin}" |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 425 | ${TEST_LINK_FLAGS} |
George Karpenkov | 916b56d | 2017-08-21 21:19:13 +0000 | [diff] [blame] | 426 | DEPENDS ${TEST_DEPS} |
| 427 | ) |
| 428 | add_custom_target(T${test_name} DEPENDS "${output_bin}") |
| 429 | set_target_properties(T${test_name} PROPERTIES FOLDER "Compiler-RT Tests") |
Etienne Bergeron | a088b36 | 2016-07-11 21:51:56 +0000 | [diff] [blame] | 430 | |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 431 | # Make the test suite depend on the binary. |
George Karpenkov | 916b56d | 2017-08-21 21:19:13 +0000 | [diff] [blame] | 432 | add_dependencies(${test_suite} T${test_name}) |
George Karpenkov | 8ffc41a | 2017-08-15 18:32:28 +0000 | [diff] [blame] | 433 | endfunction() |
Alexey Samsonov | c1caace | 2013-05-21 13:48:27 +0000 | [diff] [blame] | 434 | |
Chris Bieneman | 772a58d | 2016-02-23 21:50:39 +0000 | [diff] [blame] | 435 | macro(add_compiler_rt_resource_file target_name file_name component) |
Alexey Samsonov | c1caace | 2013-05-21 13:48:27 +0000 | [diff] [blame] | 436 | set(src_file "${CMAKE_CURRENT_SOURCE_DIR}/${file_name}") |
Petr Hosek | b6c53ea | 2018-01-14 03:43:14 +0000 | [diff] [blame] | 437 | set(dst_file "${COMPILER_RT_OUTPUT_DIR}/share/${file_name}") |
Alexey Samsonov | 41bf0bc | 2014-02-27 07:22:59 +0000 | [diff] [blame] | 438 | add_custom_command(OUTPUT ${dst_file} |
| 439 | DEPENDS ${src_file} |
Alexey Samsonov | c1caace | 2013-05-21 13:48:27 +0000 | [diff] [blame] | 440 | COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src_file} ${dst_file} |
Alexey Samsonov | 41bf0bc | 2014-02-27 07:22:59 +0000 | [diff] [blame] | 441 | COMMENT "Copying ${file_name}...") |
| 442 | add_custom_target(${target_name} DEPENDS ${dst_file}) |
Alexey Samsonov | c1caace | 2013-05-21 13:48:27 +0000 | [diff] [blame] | 443 | # Install in Clang resource directory. |
Chris Bieneman | 772a58d | 2016-02-23 21:50:39 +0000 | [diff] [blame] | 444 | install(FILES ${file_name} |
Petr Hosek | b6c53ea | 2018-01-14 03:43:14 +0000 | [diff] [blame] | 445 | DESTINATION ${COMPILER_RT_INSTALL_PATH}/share |
Chris Bieneman | 772a58d | 2016-02-23 21:50:39 +0000 | [diff] [blame] | 446 | COMPONENT ${component}) |
| 447 | add_dependencies(${component} ${target_name}) |
Etienne Bergeron | a088b36 | 2016-07-11 21:51:56 +0000 | [diff] [blame] | 448 | |
| 449 | set_target_properties(${target_name} PROPERTIES FOLDER "Compiler-RT Misc") |
Alexey Samsonov | c1caace | 2013-05-21 13:48:27 +0000 | [diff] [blame] | 450 | endmacro() |
Evgeniy Stepanov | 9514ed1 | 2014-02-27 08:41:40 +0000 | [diff] [blame] | 451 | |
| 452 | macro(add_compiler_rt_script name) |
| 453 | set(dst ${COMPILER_RT_EXEC_OUTPUT_DIR}/${name}) |
| 454 | set(src ${CMAKE_CURRENT_SOURCE_DIR}/${name}) |
| 455 | add_custom_command(OUTPUT ${dst} |
| 456 | DEPENDS ${src} |
| 457 | COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst} |
| 458 | COMMENT "Copying ${name}...") |
| 459 | add_custom_target(${name} DEPENDS ${dst}) |
| 460 | install(FILES ${dst} |
| 461 | PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE |
| 462 | DESTINATION ${COMPILER_RT_INSTALL_PATH}/bin) |
| 463 | endmacro(add_compiler_rt_script src name) |
Alexey Samsonov | 2e8e441 | 2014-05-09 22:11:03 +0000 | [diff] [blame] | 464 | |
| 465 | # Builds custom version of libc++ and installs it in <prefix>. |
| 466 | # Can be used to build sanitized versions of libc++ for running unit tests. |
| 467 | # add_custom_libcxx(<name> <prefix> |
| 468 | # DEPS <list of build deps> |
Petr Hosek | 7ccfd60 | 2018-01-21 01:01:53 +0000 | [diff] [blame] | 469 | # CFLAGS <list of compile flags> |
| 470 | # USE_TOOLCHAIN) |
Alexey Samsonov | 2e8e441 | 2014-05-09 22:11:03 +0000 | [diff] [blame] | 471 | macro(add_custom_libcxx name prefix) |
Petr Hosek | eff0155 | 2017-12-12 01:20:52 +0000 | [diff] [blame] | 472 | if(NOT COMPILER_RT_LIBCXX_PATH) |
Alexey Samsonov | 2e8e441 | 2014-05-09 22:11:03 +0000 | [diff] [blame] | 473 | message(FATAL_ERROR "libcxx not found!") |
| 474 | endif() |
| 475 | |
Petr Hosek | 7ccfd60 | 2018-01-21 01:01:53 +0000 | [diff] [blame] | 476 | cmake_parse_arguments(LIBCXX "USE_TOOLCHAIN" "" "DEPS;CFLAGS;CMAKE_ARGS" ${ARGN}) |
Alexey Samsonov | 2e8e441 | 2014-05-09 22:11:03 +0000 | [diff] [blame] | 477 | foreach(flag ${LIBCXX_CFLAGS}) |
| 478 | set(flagstr "${flagstr} ${flag}") |
| 479 | endforeach() |
Petr Hosek | 7bcd41f | 2018-03-07 18:14:09 +0000 | [diff] [blame] | 480 | set(LIBCXX_C_FLAGS ${flagstr}) |
| 481 | set(LIBCXX_CXX_FLAGS ${flagstr}) |
Alexey Samsonov | 2e8e441 | 2014-05-09 22:11:03 +0000 | [diff] [blame] | 482 | |
Petr Hosek | 7ccfd60 | 2018-01-21 01:01:53 +0000 | [diff] [blame] | 483 | if(LIBCXX_USE_TOOLCHAIN) |
| 484 | set(compiler_args -DCMAKE_C_COMPILER=${COMPILER_RT_TEST_COMPILER} |
| 485 | -DCMAKE_CXX_COMPILER=${COMPILER_RT_TEST_CXX_COMPILER}) |
| 486 | if(NOT COMPILER_RT_STANDALONE_BUILD) |
Petr Hosek | 7bcd41f | 2018-03-07 18:14:09 +0000 | [diff] [blame] | 487 | set(toolchain_deps $<TARGET_FILE:clang>) |
| 488 | set(force_deps DEPENDS $<TARGET_FILE:clang>) |
Petr Hosek | 7ccfd60 | 2018-01-21 01:01:53 +0000 | [diff] [blame] | 489 | endif() |
Petr Hosek | 0654588 | 2018-01-21 03:22:22 +0000 | [diff] [blame] | 490 | else() |
| 491 | set(compiler_args -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} |
| 492 | -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}) |
Petr Hosek | 7ccfd60 | 2018-01-21 01:01:53 +0000 | [diff] [blame] | 493 | endif() |
| 494 | |
Petr Hosek | 7bcd41f | 2018-03-07 18:14:09 +0000 | [diff] [blame] | 495 | set(STAMP_DIR ${prefix}-stamps/) |
| 496 | set(BINARY_DIR ${prefix}-bins/) |
| 497 | |
| 498 | add_custom_target(${name}-clear |
| 499 | COMMAND ${CMAKE_COMMAND} -E remove_directory ${BINARY_DIR} |
| 500 | COMMAND ${CMAKE_COMMAND} -E remove_directory ${STAMP_DIR} |
| 501 | COMMENT "Clobbering ${name} build and stamp directories" |
| 502 | USES_TERMINAL |
| 503 | ) |
| 504 | |
| 505 | add_custom_command( |
| 506 | OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${name}-clobber-stamp |
| 507 | DEPENDS ${LIBCXX_DEPS} ${toolchain_deps} |
| 508 | COMMAND ${CMAKE_COMMAND} -E touch ${BINARY_DIR}/CMakeCache.txt |
| 509 | COMMAND ${CMAKE_COMMAND} -E touch ${STAMP_DIR}/${name}-mkdir |
| 510 | COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/${name}-clobber-stamp |
| 511 | COMMENT "Clobbering bootstrap build and stamp directories" |
| 512 | ) |
| 513 | |
| 514 | add_custom_target(${name}-clobber |
| 515 | DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${name}-clobber-stamp) |
| 516 | |
Petr Hosek | 7ccfd60 | 2018-01-21 01:01:53 +0000 | [diff] [blame] | 517 | if(CMAKE_SYSROOT) |
| 518 | set(sysroot_arg -DCMAKE_SYSROOT=${CMAKE_SYSROOT}) |
Alexey Samsonov | 2e8e441 | 2014-05-09 22:11:03 +0000 | [diff] [blame] | 519 | endif() |
| 520 | |
| 521 | ExternalProject_Add(${name} |
Petr Hosek | 7bcd41f | 2018-03-07 18:14:09 +0000 | [diff] [blame] | 522 | DEPENDS ${name}-clobber ${LIBCXX_DEPS} |
Alexey Samsonov | 2e8e441 | 2014-05-09 22:11:03 +0000 | [diff] [blame] | 523 | PREFIX ${prefix} |
| 524 | SOURCE_DIR ${COMPILER_RT_LIBCXX_PATH} |
Petr Hosek | 7bcd41f | 2018-03-07 18:14:09 +0000 | [diff] [blame] | 525 | STAMP_DIR ${STAMP_DIR} |
| 526 | BINARY_DIR ${BINARY_DIR} |
Petr Hosek | 7ccfd60 | 2018-01-21 01:01:53 +0000 | [diff] [blame] | 527 | CMAKE_ARGS -DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM} |
| 528 | ${compiler_args} |
| 529 | ${sysroot_arg} |
Petr Hosek | 7bcd41f | 2018-03-07 18:14:09 +0000 | [diff] [blame] | 530 | -DCMAKE_C_FLAGS=${LIBCXX_C_FLAGS} |
| 531 | -DCMAKE_CXX_FLAGS=${LIBCXX_CXX_FLAGS} |
Alexey Samsonov | 2e8e441 | 2014-05-09 22:11:03 +0000 | [diff] [blame] | 532 | -DCMAKE_BUILD_TYPE=Release |
Petr Hosek | 7bcd41f | 2018-03-07 18:14:09 +0000 | [diff] [blame] | 533 | -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} |
Daniel Sanders | a268a2f | 2016-02-02 12:55:28 +0000 | [diff] [blame] | 534 | -DLLVM_PATH=${LLVM_MAIN_SRC_DIR} |
Petr Hosek | 7bcd41f | 2018-03-07 18:14:09 +0000 | [diff] [blame] | 535 | -DLLVM_BINARY_DIR=${prefix} |
| 536 | -DLLVM_LIBRARY_OUTPUT_INTDIR=${prefix}/lib |
| 537 | -DLIBCXX_STANDALONE_BUILD=ON |
Petr Hosek | 9090db4 | 2017-12-21 20:04:10 +0000 | [diff] [blame] | 538 | ${LIBCXX_CMAKE_ARGS} |
Petr Hosek | 7bcd41f | 2018-03-07 18:14:09 +0000 | [diff] [blame] | 539 | INSTALL_COMMAND "" |
| 540 | STEP_TARGETS configure build |
| 541 | BUILD_ALWAYS 1 |
| 542 | USES_TERMINAL_CONFIGURE 1 |
| 543 | USES_TERMINAL_BUILD 1 |
| 544 | USES_TERMINAL_INSTALL 1 |
Petr Hosek | 7ccfd60 | 2018-01-21 01:01:53 +0000 | [diff] [blame] | 545 | EXCLUDE_FROM_ALL TRUE |
Alexey Samsonov | 2e8e441 | 2014-05-09 22:11:03 +0000 | [diff] [blame] | 546 | ) |
| 547 | |
Petr Hosek | 7bcd41f | 2018-03-07 18:14:09 +0000 | [diff] [blame] | 548 | if (CMAKE_GENERATOR MATCHES "Make") |
| 549 | set(run_clean "$(MAKE)" "-C" "${BINARY_DIR}" "clean") |
| 550 | else() |
| 551 | set(run_clean ${CMAKE_COMMAND} --build ${BINARY_DIR} --target clean |
| 552 | --config "$<CONFIGURATION>") |
| 553 | endif() |
Alexey Samsonov | 2e8e441 | 2014-05-09 22:11:03 +0000 | [diff] [blame] | 554 | |
Petr Hosek | 7bcd41f | 2018-03-07 18:14:09 +0000 | [diff] [blame] | 555 | ExternalProject_Add_Step(${name} clean |
| 556 | COMMAND ${run_clean} |
| 557 | COMMENT "Cleaning ${name}..." |
| 558 | DEPENDEES configure |
Petr Hosek | 7ccfd60 | 2018-01-21 01:01:53 +0000 | [diff] [blame] | 559 | ${force_deps} |
Petr Hosek | 7bcd41f | 2018-03-07 18:14:09 +0000 | [diff] [blame] | 560 | WORKING_DIRECTORY ${BINARY_DIR} |
| 561 | EXCLUDE_FROM_MAIN 1 |
| 562 | USES_TERMINAL 1 |
Alexey Samsonov | 2e8e441 | 2014-05-09 22:11:03 +0000 | [diff] [blame] | 563 | ) |
Petr Hosek | 7bcd41f | 2018-03-07 18:14:09 +0000 | [diff] [blame] | 564 | ExternalProject_Add_StepTargets(${name} clean) |
| 565 | |
| 566 | if(LIBCXX_USE_TOOLCHAIN) |
| 567 | add_dependencies(${name}-clean ${name}-clobber) |
| 568 | set_target_properties(${name}-clean PROPERTIES |
| 569 | SOURCES ${CMAKE_CURRENT_BINARY_DIR}/${name}-clobber-stamp) |
| 570 | endif() |
Alexey Samsonov | 2e8e441 | 2014-05-09 22:11:03 +0000 | [diff] [blame] | 571 | endmacro() |
Chris Bieneman | 1d908be | 2015-12-03 20:08:22 +0000 | [diff] [blame] | 572 | |
| 573 | function(rt_externalize_debuginfo name) |
| 574 | if(NOT COMPILER_RT_EXTERNALIZE_DEBUGINFO) |
| 575 | return() |
| 576 | endif() |
| 577 | |
Chris Bieneman | 8a78256 | 2016-03-31 21:17:19 +0000 | [diff] [blame] | 578 | if(NOT COMPILER_RT_EXTERNALIZE_DEBUGINFO_SKIP_STRIP) |
| 579 | set(strip_command COMMAND xcrun strip -Sl $<TARGET_FILE:${name}>) |
| 580 | endif() |
| 581 | |
Chris Bieneman | 1d908be | 2015-12-03 20:08:22 +0000 | [diff] [blame] | 582 | if(APPLE) |
| 583 | if(CMAKE_CXX_FLAGS MATCHES "-flto" |
| 584 | OR CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE} MATCHES "-flto") |
| 585 | |
| 586 | 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] | 587 | set_property(TARGET ${name} APPEND_STRING PROPERTY |
Chris Bieneman | 960c490 | 2015-12-03 22:56:21 +0000 | [diff] [blame] | 588 | LINK_FLAGS " -Wl,-object_path_lto -Wl,${lto_object}") |
Chris Bieneman | 1d908be | 2015-12-03 20:08:22 +0000 | [diff] [blame] | 589 | endif() |
| 590 | add_custom_command(TARGET ${name} POST_BUILD |
| 591 | COMMAND xcrun dsymutil $<TARGET_FILE:${name}> |
Chris Bieneman | 8a78256 | 2016-03-31 21:17:19 +0000 | [diff] [blame] | 592 | ${strip_command}) |
Chris Bieneman | 1d908be | 2015-12-03 20:08:22 +0000 | [diff] [blame] | 593 | else() |
| 594 | message(FATAL_ERROR "COMPILER_RT_EXTERNALIZE_DEBUGINFO isn't implemented for non-darwin platforms!") |
| 595 | endif() |
| 596 | endfunction() |
Greg Bedwell | 1ad28c7 | 2017-11-13 12:57:54 +0000 | [diff] [blame] | 597 | |
| 598 | |
| 599 | # Configure lit configuration files, including compiler-rt specific variables. |
| 600 | function(configure_compiler_rt_lit_site_cfg input output) |
| 601 | set_llvm_build_mode() |
| 602 | |
| 603 | string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} COMPILER_RT_RESOLVED_TEST_COMPILER ${COMPILER_RT_TEST_COMPILER}) |
| 604 | string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} COMPILER_RT_RESOLVED_LIBRARY_OUTPUT_DIR ${COMPILER_RT_LIBRARY_OUTPUT_DIR}) |
| 605 | |
| 606 | configure_lit_site_cfg(${input} ${output}) |
| 607 | endfunction() |