Chris Bieneman | 1dd58a7 | 2016-04-28 18:22:01 +0000 | [diff] [blame] | 1 | include(CMakePushCheckState) |
| 2 | include(CheckSymbolExists) |
| 3 | |
Alexey Samsonov | 163ab9d | 2013-01-18 16:05:21 +0000 | [diff] [blame] | 4 | # Because compiler-rt spends a lot of time setting up custom compile flags, |
| 5 | # define a handy helper function for it. The compile flags setting in CMake |
| 6 | # has serious issues that make its syntax challenging at best. |
| 7 | function(set_target_compile_flags target) |
Aaron Ballman | e927a17 | 2014-10-23 22:13:52 +0000 | [diff] [blame] | 8 | set(argstring "") |
Alexey Samsonov | 163ab9d | 2013-01-18 16:05:21 +0000 | [diff] [blame] | 9 | foreach(arg ${ARGN}) |
| 10 | set(argstring "${argstring} ${arg}") |
| 11 | endforeach() |
| 12 | set_property(TARGET ${target} PROPERTY COMPILE_FLAGS "${argstring}") |
| 13 | endfunction() |
| 14 | |
| 15 | function(set_target_link_flags target) |
Aaron Ballman | e927a17 | 2014-10-23 22:13:52 +0000 | [diff] [blame] | 16 | set(argstring "") |
Alexey Samsonov | 163ab9d | 2013-01-18 16:05:21 +0000 | [diff] [blame] | 17 | foreach(arg ${ARGN}) |
| 18 | set(argstring "${argstring} ${arg}") |
| 19 | endforeach() |
| 20 | set_property(TARGET ${target} PROPERTY LINK_FLAGS "${argstring}") |
| 21 | endfunction() |
| 22 | |
Peter Collingbourne | cbdea32 | 2013-10-25 23:03:34 +0000 | [diff] [blame] | 23 | # Set the variable var_PYBOOL to True if var holds a true-ish string, |
| 24 | # otherwise set it to False. |
| 25 | macro(pythonize_bool var) |
| 26 | if (${var}) |
| 27 | set(${var}_PYBOOL True) |
| 28 | else() |
| 29 | set(${var}_PYBOOL False) |
| 30 | endif() |
| 31 | endmacro() |
Alexey Samsonov | b73db72 | 2014-02-18 07:52:40 +0000 | [diff] [blame] | 32 | |
Alexey Samsonov | 32956d6 | 2014-03-13 09:31:36 +0000 | [diff] [blame] | 33 | # Appends value to all lists in ARGN, if the condition is true. |
Kuba Brecka | 14c0c59 | 2014-10-15 22:47:54 +0000 | [diff] [blame] | 34 | macro(append_list_if condition value) |
Alexey Samsonov | 32956d6 | 2014-03-13 09:31:36 +0000 | [diff] [blame] | 35 | if(${condition}) |
| 36 | foreach(list ${ARGN}) |
| 37 | list(APPEND ${list} ${value}) |
| 38 | endforeach() |
Alexey Samsonov | b73db72 | 2014-02-18 07:52:40 +0000 | [diff] [blame] | 39 | endif() |
| 40 | endmacro() |
| 41 | |
Alexey Samsonov | fe7e28c | 2014-03-13 11:31:10 +0000 | [diff] [blame] | 42 | # Appends value to all strings in ARGN, if the condition is true. |
| 43 | macro(append_string_if condition value) |
| 44 | if(${condition}) |
| 45 | foreach(str ${ARGN}) |
| 46 | set(${str} "${${str}} ${value}") |
| 47 | endforeach() |
| 48 | endif() |
| 49 | endmacro() |
| 50 | |
Filipe Cabecinhas | b08c76f | 2016-03-05 10:01:04 +0000 | [diff] [blame] | 51 | macro(append_rtti_flag polarity list) |
Filipe Cabecinhas | e5914d82 | 2016-08-22 18:30:37 +0000 | [diff] [blame] | 52 | if(${polarity}) |
Filipe Cabecinhas | b08c76f | 2016-03-05 10:01:04 +0000 | [diff] [blame] | 53 | append_list_if(COMPILER_RT_HAS_FRTTI_FLAG -frtti ${list}) |
| 54 | append_list_if(COMPILER_RT_HAS_GR_FLAG /GR ${list}) |
| 55 | else() |
| 56 | append_list_if(COMPILER_RT_HAS_FNO_RTTI_FLAG -fno-rtti ${list}) |
| 57 | append_list_if(COMPILER_RT_HAS_GR_FLAG /GR- ${list}) |
| 58 | endif() |
Alexey Samsonov | b73db72 | 2014-02-18 07:52:40 +0000 | [diff] [blame] | 59 | endmacro() |
Yury Gribov | 8e49b47 | 2015-04-09 08:06:49 +0000 | [diff] [blame] | 60 | |
| 61 | macro(append_have_file_definition filename varname list) |
| 62 | check_include_file("${filename}" "${varname}") |
Reid Kleckner | aa90296 | 2015-05-20 16:56:17 +0000 | [diff] [blame] | 63 | if (NOT ${varname}) |
Yury Gribov | 8e49b47 | 2015-04-09 08:06:49 +0000 | [diff] [blame] | 64 | set("${varname}" 0) |
| 65 | endif() |
| 66 | list(APPEND ${list} "${varname}=${${varname}}") |
| 67 | endmacro() |
Chris Bieneman | 361231e | 2015-08-13 20:38:16 +0000 | [diff] [blame] | 68 | |
Daniel Sanders | de098c9 | 2016-01-27 09:28:01 +0000 | [diff] [blame] | 69 | macro(list_intersect output input1 input2) |
Chris Bieneman | 361231e | 2015-08-13 20:38:16 +0000 | [diff] [blame] | 70 | set(${output}) |
| 71 | foreach(it ${${input1}}) |
| 72 | list(FIND ${input2} ${it} index) |
| 73 | if( NOT (index EQUAL -1)) |
| 74 | list(APPEND ${output} ${it}) |
| 75 | endif() |
| 76 | endforeach() |
| 77 | endmacro() |
Chris Bieneman | 5a5b21d | 2016-02-17 16:57:38 +0000 | [diff] [blame] | 78 | |
Saleem Abdulrasool | b6ced62 | 2016-08-19 15:13:21 +0000 | [diff] [blame] | 79 | function(list_replace input_list old new) |
| 80 | set(replaced_list) |
| 81 | foreach(item ${${input_list}}) |
| 82 | if(${item} STREQUAL ${old}) |
| 83 | list(APPEND replaced_list ${new}) |
| 84 | else() |
| 85 | list(APPEND replaced_list ${item}) |
| 86 | endif() |
| 87 | endforeach() |
| 88 | set(${input_list} "${replaced_list}" PARENT_SCOPE) |
| 89 | endfunction() |
| 90 | |
Chris Bieneman | 5a5b21d | 2016-02-17 16:57:38 +0000 | [diff] [blame] | 91 | # Takes ${ARGN} and puts only supported architectures in @out_var list. |
| 92 | function(filter_available_targets out_var) |
| 93 | set(archs ${${out_var}}) |
| 94 | foreach(arch ${ARGN}) |
| 95 | list(FIND COMPILER_RT_SUPPORTED_ARCH ${arch} ARCH_INDEX) |
| 96 | if(NOT (ARCH_INDEX EQUAL -1) AND CAN_TARGET_${arch}) |
| 97 | list(APPEND archs ${arch}) |
| 98 | endif() |
| 99 | endforeach() |
| 100 | set(${out_var} ${archs} PARENT_SCOPE) |
| 101 | endfunction() |
| 102 | |
Petr Hosek | f332d19 | 2016-12-12 23:14:02 +0000 | [diff] [blame] | 103 | # Add $arch as supported with no additional flags. |
| 104 | macro(add_default_target_arch arch) |
| 105 | set(TARGET_${arch}_CFLAGS "") |
| 106 | set(CAN_TARGET_${arch} 1) |
| 107 | list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch}) |
| 108 | endmacro() |
| 109 | |
Chris Bieneman | 5a5b21d | 2016-02-17 16:57:38 +0000 | [diff] [blame] | 110 | function(check_compile_definition def argstring out_var) |
| 111 | if("${def}" STREQUAL "") |
| 112 | set(${out_var} TRUE PARENT_SCOPE) |
| 113 | return() |
| 114 | endif() |
| 115 | cmake_push_check_state() |
| 116 | set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${argstring}") |
| 117 | check_symbol_exists(${def} "" ${out_var}) |
| 118 | cmake_pop_check_state() |
| 119 | endfunction() |
| 120 | |
| 121 | # test_target_arch(<arch> <def> <target flags...>) |
| 122 | # Checks if architecture is supported: runs host compiler with provided |
| 123 | # flags to verify that: |
| 124 | # 1) <def> is defined (if non-empty) |
| 125 | # 2) simple file can be successfully built. |
| 126 | # If successful, saves target flags for this architecture. |
| 127 | macro(test_target_arch arch def) |
| 128 | set(TARGET_${arch}_CFLAGS ${ARGN}) |
Francis Ricci | 17781c7 | 2017-01-10 04:33:04 +0000 | [diff] [blame] | 129 | set(TARGET_${arch}_LINK_FLAGS ${ARGN}) |
Chris Bieneman | 5a5b21d | 2016-02-17 16:57:38 +0000 | [diff] [blame] | 130 | set(argstring "") |
| 131 | foreach(arg ${ARGN}) |
| 132 | set(argstring "${argstring} ${arg}") |
| 133 | endforeach() |
| 134 | check_compile_definition("${def}" "${argstring}" HAS_${arch}_DEF) |
Daniel Sanders | aea8b55 | 2016-07-22 10:15:09 +0000 | [diff] [blame] | 135 | if(NOT DEFINED CAN_TARGET_${arch}) |
| 136 | if(NOT HAS_${arch}_DEF) |
| 137 | set(CAN_TARGET_${arch} FALSE) |
| 138 | elseif(TEST_COMPILE_ONLY) |
| 139 | try_compile_only(CAN_TARGET_${arch} ${TARGET_${arch}_CFLAGS}) |
| 140 | else() |
Jonas Hahnfeld | b297841 | 2016-09-21 05:44:06 +0000 | [diff] [blame] | 141 | set(FLAG_NO_EXCEPTIONS "") |
| 142 | if(COMPILER_RT_HAS_FNO_EXCEPTIONS_FLAG) |
| 143 | set(FLAG_NO_EXCEPTIONS " -fno-exceptions ") |
| 144 | endif() |
Bob Haarman | ccd6ae2 | 2017-03-21 18:25:35 +0000 | [diff] [blame] | 145 | set(SAVED_CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS}) |
| 146 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${argstring}") |
Jonas Hahnfeld | 71befac | 2018-06-17 09:51:33 +0000 | [diff] [blame] | 147 | try_compile(CAN_TARGET_${arch} ${CMAKE_BINARY_DIR} ${SIMPLE_SOURCE} |
Jonas Hahnfeld | b297841 | 2016-09-21 05:44:06 +0000 | [diff] [blame] | 148 | COMPILE_DEFINITIONS "${TARGET_${arch}_CFLAGS} ${FLAG_NO_EXCEPTIONS}" |
Bob Haarman | ccd6ae2 | 2017-03-21 18:25:35 +0000 | [diff] [blame] | 149 | OUTPUT_VARIABLE TARGET_${arch}_OUTPUT) |
| 150 | set(CMAKE_EXE_LINKER_FLAGS ${SAVED_CMAKE_EXE_LINKER_FLAGS}) |
Daniel Sanders | aea8b55 | 2016-07-22 10:15:09 +0000 | [diff] [blame] | 151 | endif() |
Chris Bieneman | 5a5b21d | 2016-02-17 16:57:38 +0000 | [diff] [blame] | 152 | endif() |
| 153 | if(${CAN_TARGET_${arch}}) |
| 154 | list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch}) |
Francis Ricci | b04a721 | 2016-07-20 18:06:31 +0000 | [diff] [blame] | 155 | elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" STREQUAL "${arch}" AND |
Chris Bieneman | 5a5b21d | 2016-02-17 16:57:38 +0000 | [diff] [blame] | 156 | COMPILER_RT_HAS_EXPLICIT_DEFAULT_TARGET_TRIPLE) |
| 157 | # Bail out if we cannot target the architecture we plan to test. |
| 158 | message(FATAL_ERROR "Cannot compile for ${arch}:\n${TARGET_${arch}_OUTPUT}") |
| 159 | endif() |
| 160 | endmacro() |
Chris Bieneman | 648d3bc | 2016-06-03 17:34:02 +0000 | [diff] [blame] | 161 | |
| 162 | macro(detect_target_arch) |
| 163 | check_symbol_exists(__arm__ "" __ARM) |
| 164 | check_symbol_exists(__aarch64__ "" __AARCH64) |
| 165 | check_symbol_exists(__x86_64__ "" __X86_64) |
Chris Bieneman | 648d3bc | 2016-06-03 17:34:02 +0000 | [diff] [blame] | 166 | check_symbol_exists(__i386__ "" __I386) |
| 167 | check_symbol_exists(__mips__ "" __MIPS) |
| 168 | check_symbol_exists(__mips64__ "" __MIPS64) |
Sterling Augustine | 9b6943f | 2017-11-30 21:04:11 +0000 | [diff] [blame] | 169 | check_symbol_exists(__powerpc64__ "" __PPC64) |
| 170 | check_symbol_exists(__powerpc64le__ "" __PPC64LE) |
Shiva Chen | 77f19a3 | 2018-03-01 07:47:27 +0000 | [diff] [blame] | 171 | check_symbol_exists(__riscv "" __RISCV) |
Chris Bieneman | 648d3bc | 2016-06-03 17:34:02 +0000 | [diff] [blame] | 172 | check_symbol_exists(__s390x__ "" __S390X) |
| 173 | check_symbol_exists(__wasm32__ "" __WEBASSEMBLY32) |
| 174 | check_symbol_exists(__wasm64__ "" __WEBASSEMBLY64) |
| 175 | if(__ARM) |
| 176 | add_default_target_arch(arm) |
| 177 | elseif(__AARCH64) |
| 178 | add_default_target_arch(aarch64) |
| 179 | elseif(__X86_64) |
| 180 | add_default_target_arch(x86_64) |
Chris Bieneman | 648d3bc | 2016-06-03 17:34:02 +0000 | [diff] [blame] | 181 | elseif(__I386) |
| 182 | add_default_target_arch(i386) |
| 183 | elseif(__MIPS64) # must be checked before __MIPS |
| 184 | add_default_target_arch(mips64) |
| 185 | elseif(__MIPS) |
| 186 | add_default_target_arch(mips) |
Sterling Augustine | 9b6943f | 2017-11-30 21:04:11 +0000 | [diff] [blame] | 187 | elseif(__PPC64) |
| 188 | add_default_target_arch(powerpc64) |
| 189 | elseif(__PPC64LE) |
| 190 | add_default_target_arch(powerpc64le) |
Shiva Chen | 77f19a3 | 2018-03-01 07:47:27 +0000 | [diff] [blame] | 191 | elseif(__RISCV) |
| 192 | if(CMAKE_SIZEOF_VOID_P EQUAL "4") |
| 193 | add_default_target_arch(riscv32) |
| 194 | elseif(CMAKE_SIZEOF_VOID_P EQUAL "8") |
| 195 | add_default_target_arch(riscv64) |
| 196 | else() |
| 197 | message(FATAL_ERROR "Unsupport XLEN for RISC-V") |
| 198 | endif() |
Chris Bieneman | 648d3bc | 2016-06-03 17:34:02 +0000 | [diff] [blame] | 199 | elseif(__S390X) |
| 200 | add_default_target_arch(s390x) |
| 201 | elseif(__WEBASSEMBLY32) |
| 202 | add_default_target_arch(wasm32) |
| 203 | elseif(__WEBASSEMBLY64) |
| 204 | add_default_target_arch(wasm64) |
| 205 | endif() |
| 206 | endmacro() |
Jonas Hahnfeld | 9b2c3ab | 2016-08-02 05:51:05 +0000 | [diff] [blame] | 207 | |
| 208 | macro(load_llvm_config) |
| 209 | if (NOT LLVM_CONFIG_PATH) |
| 210 | find_program(LLVM_CONFIG_PATH "llvm-config" |
| 211 | DOC "Path to llvm-config binary") |
| 212 | if (NOT LLVM_CONFIG_PATH) |
Martin Storsjo | d07bd75 | 2018-08-03 05:50:33 +0000 | [diff] [blame] | 213 | message(WARNING "UNSUPPORTED COMPILER-RT CONFIGURATION DETECTED: " |
| 214 | "llvm-config not found.\n" |
| 215 | "Reconfigure with -DLLVM_CONFIG_PATH=path/to/llvm-config.") |
Jonas Hahnfeld | 9b2c3ab | 2016-08-02 05:51:05 +0000 | [diff] [blame] | 216 | endif() |
| 217 | endif() |
Martin Storsjo | d07bd75 | 2018-08-03 05:50:33 +0000 | [diff] [blame] | 218 | if (LLVM_CONFIG_PATH) |
| 219 | execute_process( |
Dean Michael Berris | 1f60207 | 2018-09-20 05:22:37 +0000 | [diff] [blame] | 220 | COMMAND ${LLVM_CONFIG_PATH} "--obj-root" "--bindir" "--libdir" "--src-root" "--includedir" |
Martin Storsjo | d07bd75 | 2018-08-03 05:50:33 +0000 | [diff] [blame] | 221 | RESULT_VARIABLE HAD_ERROR |
| 222 | OUTPUT_VARIABLE CONFIG_OUTPUT) |
| 223 | if (HAD_ERROR) |
| 224 | message(FATAL_ERROR "llvm-config failed with status ${HAD_ERROR}") |
| 225 | endif() |
| 226 | string(REGEX REPLACE "[ \t]*[\r\n]+[ \t]*" ";" CONFIG_OUTPUT ${CONFIG_OUTPUT}) |
| 227 | list(GET CONFIG_OUTPUT 0 BINARY_DIR) |
| 228 | list(GET CONFIG_OUTPUT 1 TOOLS_BINARY_DIR) |
| 229 | list(GET CONFIG_OUTPUT 2 LIBRARY_DIR) |
| 230 | list(GET CONFIG_OUTPUT 3 MAIN_SRC_DIR) |
Dean Michael Berris | 1f60207 | 2018-09-20 05:22:37 +0000 | [diff] [blame] | 231 | list(GET CONFIG_OUTPUT 4 INCLUDE_DIR) |
Martin Storsjo | d07bd75 | 2018-08-03 05:50:33 +0000 | [diff] [blame] | 232 | |
| 233 | set(LLVM_BINARY_DIR ${BINARY_DIR} CACHE PATH "Path to LLVM build tree") |
Martin Storsjo | d07bd75 | 2018-08-03 05:50:33 +0000 | [diff] [blame] | 234 | set(LLVM_LIBRARY_DIR ${LIBRARY_DIR} CACHE PATH "Path to llvm/lib") |
| 235 | set(LLVM_MAIN_SRC_DIR ${MAIN_SRC_DIR} CACHE PATH "Path to LLVM source tree") |
Dean Michael Berris | 1f60207 | 2018-09-20 05:22:37 +0000 | [diff] [blame] | 236 | set(LLVM_TOOLS_BINARY_DIR ${TOOLS_BINARY_DIR} CACHE PATH "Path to llvm/bin") |
| 237 | set(LLVM_INCLUDE_DIR ${INCLUDE_DIR} CACHE PATH "Paths to LLVM headers") |
Martin Storsjo | d07bd75 | 2018-08-03 05:50:33 +0000 | [diff] [blame] | 238 | |
Dean Michael Berris | f578aaa | 2018-09-24 05:28:01 +0000 | [diff] [blame] | 239 | # Detect if we have the LLVMXRay and TestingSupport library installed and |
| 240 | # available from llvm-config. |
| 241 | execute_process( |
| 242 | COMMAND ${LLVM_CONFIG_PATH} "--ldflags" "--libs" "xray" "testingsupport" |
| 243 | RESULT_VARIABLE HAD_ERROR |
| 244 | OUTPUT_VARIABLE CONFIG_OUTPUT) |
| 245 | if (HAD_ERROR) |
| 246 | message(WARNING "llvm-config finding xray failed with status ${HAD_ERROR}") |
| 247 | set(COMPILER_RT_HAS_LLVMXRAY FALSE) |
| 248 | else() |
| 249 | string(REGEX REPLACE "[ \t]*[\r\n]+[ \t]*" ";" CONFIG_OUTPUT ${CONFIG_OUTPUT}) |
| 250 | list(GET CONFIG_OUTPUT 0 LDFLAGS) |
| 251 | list(GET CONFIG_OUTPUT 1 LIBLIST) |
| 252 | set(LLVM_XRAY_LDFLAGS ${LDFLAGS} CACHE STRING "Linker flags for LLVMXRay library") |
| 253 | set(LLVM_XRAY_LIBLIST ${LIBLIST} CACHE STRING "Library list for LLVMXRay") |
| 254 | set(COMPILER_RT_HAS_LLVMXRAY TRUE) |
| 255 | endif() |
| 256 | |
Martin Storsjo | d07bd75 | 2018-08-03 05:50:33 +0000 | [diff] [blame] | 257 | # Make use of LLVM CMake modules. |
| 258 | # --cmakedir is supported since llvm r291218 (4.0 release) |
| 259 | execute_process( |
| 260 | COMMAND ${LLVM_CONFIG_PATH} --cmakedir |
| 261 | RESULT_VARIABLE HAD_ERROR |
| 262 | OUTPUT_VARIABLE CONFIG_OUTPUT) |
| 263 | if(NOT HAD_ERROR) |
| 264 | string(STRIP "${CONFIG_OUTPUT}" LLVM_CMAKE_PATH_FROM_LLVM_CONFIG) |
| 265 | file(TO_CMAKE_PATH ${LLVM_CMAKE_PATH_FROM_LLVM_CONFIG} LLVM_CMAKE_PATH) |
| 266 | else() |
| 267 | file(TO_CMAKE_PATH ${LLVM_BINARY_DIR} LLVM_BINARY_DIR_CMAKE_STYLE) |
| 268 | set(LLVM_CMAKE_PATH "${LLVM_BINARY_DIR_CMAKE_STYLE}/lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm") |
| 269 | endif() |
| 270 | |
| 271 | list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_PATH}") |
| 272 | # Get some LLVM variables from LLVMConfig. |
| 273 | include("${LLVM_CMAKE_PATH}/LLVMConfig.cmake") |
| 274 | |
| 275 | set(LLVM_LIBRARY_OUTPUT_INTDIR |
| 276 | ${LLVM_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}) |
Jonas Hahnfeld | 9b2c3ab | 2016-08-02 05:51:05 +0000 | [diff] [blame] | 277 | endif() |
Jonas Hahnfeld | 9b2c3ab | 2016-08-02 05:51:05 +0000 | [diff] [blame] | 278 | endmacro() |
| 279 | |
| 280 | macro(construct_compiler_rt_default_triple) |
Petr Hosek | f332d19 | 2016-12-12 23:14:02 +0000 | [diff] [blame] | 281 | if(COMPILER_RT_DEFAULT_TARGET_ONLY) |
| 282 | if(DEFINED COMPILER_RT_DEFAULT_TARGET_TRIPLE) |
| 283 | message(FATAL_ERROR "COMPILER_RT_DEFAULT_TARGET_TRIPLE isn't supported when building for default target only") |
| 284 | endif() |
| 285 | set(COMPILER_RT_DEFAULT_TARGET_TRIPLE ${CMAKE_C_COMPILER_TARGET}) |
| 286 | else() |
| 287 | set(COMPILER_RT_DEFAULT_TARGET_TRIPLE ${TARGET_TRIPLE} CACHE STRING |
| 288 | "Default triple for which compiler-rt runtimes will be built.") |
| 289 | endif() |
| 290 | |
Jonas Hahnfeld | 9b2c3ab | 2016-08-02 05:51:05 +0000 | [diff] [blame] | 291 | if(DEFINED COMPILER_RT_TEST_TARGET_TRIPLE) |
| 292 | # Backwards compatibility: this variable used to be called |
| 293 | # COMPILER_RT_TEST_TARGET_TRIPLE. |
| 294 | set(COMPILER_RT_DEFAULT_TARGET_TRIPLE ${COMPILER_RT_TEST_TARGET_TRIPLE}) |
| 295 | endif() |
| 296 | |
| 297 | string(REPLACE "-" ";" TARGET_TRIPLE_LIST ${COMPILER_RT_DEFAULT_TARGET_TRIPLE}) |
| 298 | list(GET TARGET_TRIPLE_LIST 0 COMPILER_RT_DEFAULT_TARGET_ARCH) |
Jonas Hahnfeld | 9b2c3ab | 2016-08-02 05:51:05 +0000 | [diff] [blame] | 299 | # Determine if test target triple is specified explicitly, and doesn't match the |
| 300 | # default. |
| 301 | if(NOT COMPILER_RT_DEFAULT_TARGET_TRIPLE STREQUAL TARGET_TRIPLE) |
| 302 | set(COMPILER_RT_HAS_EXPLICIT_DEFAULT_TARGET_TRIPLE TRUE) |
| 303 | else() |
| 304 | set(COMPILER_RT_HAS_EXPLICIT_DEFAULT_TARGET_TRIPLE FALSE) |
| 305 | endif() |
| 306 | endmacro() |
Francis Ricci | e3b018f | 2017-08-30 17:12:57 +0000 | [diff] [blame] | 307 | |
| 308 | # Filter out generic versions of routines that are re-implemented in |
| 309 | # architecture specific manner. This prevents multiple definitions of the |
| 310 | # same symbols, making the symbol selection non-deterministic. |
| 311 | function(filter_builtin_sources output_var exclude_or_include excluded_list) |
| 312 | if(exclude_or_include STREQUAL "EXCLUDE") |
| 313 | set(filter_action GREATER) |
| 314 | set(filter_value -1) |
| 315 | elseif(exclude_or_include STREQUAL "INCLUDE") |
| 316 | set(filter_action LESS) |
| 317 | set(filter_value 0) |
| 318 | else() |
| 319 | message(FATAL_ERROR "filter_builtin_sources called without EXCLUDE|INCLUDE") |
| 320 | endif() |
| 321 | |
| 322 | set(intermediate ${ARGN}) |
| 323 | foreach (_file ${intermediate}) |
| 324 | get_filename_component(_name_we ${_file} NAME_WE) |
| 325 | list(FIND ${excluded_list} ${_name_we} _found) |
| 326 | if(_found ${filter_action} ${filter_value}) |
| 327 | list(REMOVE_ITEM intermediate ${_file}) |
| 328 | elseif(${_file} MATCHES ".*/.*\\.S" OR ${_file} MATCHES ".*/.*\\.c") |
| 329 | get_filename_component(_name ${_file} NAME) |
| 330 | string(REPLACE ".S" ".c" _cname "${_name}") |
| 331 | list(REMOVE_ITEM intermediate ${_cname}) |
| 332 | endif () |
| 333 | endforeach () |
| 334 | set(${output_var} ${intermediate} PARENT_SCOPE) |
| 335 | endfunction() |
Petr Hosek | 887f26d | 2018-06-28 03:11:52 +0000 | [diff] [blame] | 336 | |
| 337 | function(get_compiler_rt_target arch variable) |
Petr Hosek | 39f0860 | 2018-08-14 18:01:19 +0000 | [diff] [blame] | 338 | string(FIND ${COMPILER_RT_DEFAULT_TARGET_TRIPLE} "-" dash_index) |
| 339 | string(SUBSTRING ${COMPILER_RT_DEFAULT_TARGET_TRIPLE} ${dash_index} -1 triple_suffix) |
Petr Hosek | 887f26d | 2018-06-28 03:11:52 +0000 | [diff] [blame] | 340 | if(ANDROID AND ${arch} STREQUAL "i386") |
Petr Hosek | 39f0860 | 2018-08-14 18:01:19 +0000 | [diff] [blame] | 341 | set(target "i686${COMPILER_RT_OS_SUFFIX}${triple_suffix}") |
Petr Hosek | 887f26d | 2018-06-28 03:11:52 +0000 | [diff] [blame] | 342 | else() |
Petr Hosek | 39f0860 | 2018-08-14 18:01:19 +0000 | [diff] [blame] | 343 | set(target "${arch}${triple_suffix}") |
Petr Hosek | 887f26d | 2018-06-28 03:11:52 +0000 | [diff] [blame] | 344 | endif() |
| 345 | set(${variable} ${target} PARENT_SCOPE) |
| 346 | endfunction() |
| 347 | |
| 348 | function(get_compiler_rt_install_dir arch install_dir) |
| 349 | if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) |
| 350 | get_compiler_rt_target(${arch} target) |
| 351 | set(${install_dir} ${COMPILER_RT_INSTALL_PATH}/${target}/lib PARENT_SCOPE) |
| 352 | else() |
| 353 | set(${install_dir} ${COMPILER_RT_LIBRARY_INSTALL_DIR} PARENT_SCOPE) |
| 354 | endif() |
| 355 | endfunction() |
| 356 | |
| 357 | function(get_compiler_rt_output_dir arch output_dir) |
| 358 | if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) |
| 359 | get_compiler_rt_target(${arch} target) |
| 360 | set(${output_dir} ${COMPILER_RT_OUTPUT_DIR}/${target}/lib PARENT_SCOPE) |
| 361 | else() |
| 362 | set(${output_dir} ${COMPILER_RT_LIBRARY_OUTPUT_DIR} PARENT_SCOPE) |
| 363 | endif() |
| 364 | endfunction() |
Dan Liew | b1f9569 | 2018-07-10 13:00:17 +0000 | [diff] [blame] | 365 | |
| 366 | # compiler_rt_process_sources( |
| 367 | # <OUTPUT_VAR> |
| 368 | # <SOURCE_FILE> ... |
| 369 | # [ADDITIONAL_HEADERS <header> ...] |
| 370 | # ) |
| 371 | # |
| 372 | # Process the provided sources and write the list of new sources |
| 373 | # into `<OUTPUT_VAR>`. |
| 374 | # |
| 375 | # ADDITIONAL_HEADERS - Adds the supplied header to list of sources for IDEs. |
| 376 | # |
| 377 | # This function is very similar to `llvm_process_sources()` but exists here |
| 378 | # because we need to support standalone builds of compiler-rt. |
| 379 | function(compiler_rt_process_sources OUTPUT_VAR) |
| 380 | cmake_parse_arguments( |
| 381 | ARG |
| 382 | "" |
| 383 | "" |
| 384 | "ADDITIONAL_HEADERS" |
| 385 | ${ARGN} |
| 386 | ) |
| 387 | set(sources ${ARG_UNPARSED_ARGUMENTS}) |
| 388 | set(headers "") |
| 389 | if (XCODE OR MSVC_IDE OR CMAKE_EXTRA_GENERATOR) |
| 390 | # For IDEs we need to tell CMake about header files. |
| 391 | # Otherwise they won't show up in UI. |
| 392 | set(headers ${ARG_ADDITIONAL_HEADERS}) |
| 393 | list(LENGTH headers headers_length) |
| 394 | if (${headers_length} GREATER 0) |
| 395 | set_source_files_properties(${headers} |
| 396 | PROPERTIES HEADER_FILE_ONLY ON) |
| 397 | endif() |
| 398 | endif() |
| 399 | set("${OUTPUT_VAR}" ${sources} ${headers} PARENT_SCOPE) |
| 400 | endfunction() |