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