Eric Fiselier | 78fdf2d | 2015-03-31 04:15:45 | [diff] [blame] | 1 | set(LIBCXX_LIB_CMAKEFILES_DIR "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}" PARENT_SCOPE) |
| 2 | |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 3 | # Get sources |
Petr Hosek | f80c4b6 | 2019-05-01 06:40:36 | [diff] [blame] | 4 | set(LIBCXX_SOURCES |
| 5 | algorithm.cpp |
| 6 | any.cpp |
| 7 | bind.cpp |
| 8 | charconv.cpp |
| 9 | chrono.cpp |
| 10 | condition_variable.cpp |
| 11 | debug.cpp |
| 12 | exception.cpp |
| 13 | functional.cpp |
| 14 | future.cpp |
| 15 | hash.cpp |
| 16 | include/apple_availability.h |
| 17 | include/atomic_support.h |
| 18 | include/config_elast.h |
| 19 | include/refstring.h |
| 20 | ios.cpp |
| 21 | iostream.cpp |
| 22 | locale.cpp |
| 23 | memory.cpp |
| 24 | mutex.cpp |
| 25 | new.cpp |
| 26 | optional.cpp |
| 27 | random.cpp |
| 28 | regex.cpp |
| 29 | shared_mutex.cpp |
| 30 | stdexcept.cpp |
| 31 | string.cpp |
| 32 | strstream.cpp |
| 33 | support/runtime/exception_fallback.ipp |
| 34 | support/runtime/exception_glibcxx.ipp |
| 35 | support/runtime/exception_libcxxabi.ipp |
| 36 | support/runtime/exception_libcxxrt.ipp |
| 37 | support/runtime/exception_msvc.ipp |
| 38 | support/runtime/exception_pointer_cxxabi.ipp |
| 39 | support/runtime/exception_pointer_glibcxx.ipp |
| 40 | support/runtime/exception_pointer_msvc.ipp |
| 41 | support/runtime/exception_pointer_unimplemented.ipp |
| 42 | support/runtime/new_handler_fallback.ipp |
| 43 | support/runtime/stdexcept_default.ipp |
| 44 | support/runtime/stdexcept_vcruntime.ipp |
| 45 | system_error.cpp |
| 46 | thread.cpp |
| 47 | typeinfo.cpp |
| 48 | utility.cpp |
| 49 | valarray.cpp |
| 50 | variant.cpp |
| 51 | vector.cpp |
| 52 | ) |
| 53 | |
Howard Hinnant | 3c78ca0 | 2011-09-22 19:10:18 | [diff] [blame] | 54 | if(WIN32) |
Petr Hosek | f80c4b6 | 2019-05-01 06:40:36 | [diff] [blame] | 55 | list(APPEND LIBCXX_SOURCES |
| 56 | support/win32/locale_win32.cpp |
| 57 | support/win32/support.cpp |
| 58 | support/win32/thread_win32.cpp |
| 59 | ) |
Eric Fiselier | 53deb60 | 2014-11-25 21:57:41 | [diff] [blame] | 60 | elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "SunOS") |
Petr Hosek | f80c4b6 | 2019-05-01 06:40:36 | [diff] [blame] | 61 | list(APPEND LIBCXX_SOURCES |
| 62 | support/solaris/mbsnrtowcs.inc |
| 63 | support/solaris/wcsnrtombs.inc |
| 64 | support/solaris/xlocale.cpp |
| 65 | ) |
Howard Hinnant | 3c78ca0 | 2011-09-22 19:10:18 | [diff] [blame] | 66 | endif() |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 67 | |
Eric Fiselier | f1d87f8 | 2019-03-21 00:04:31 | [diff] [blame] | 68 | if (LIBCXX_ENABLE_FILESYSTEM) |
Petr Hosek | f80c4b6 | 2019-05-01 06:40:36 | [diff] [blame] | 69 | list(APPEND LIBCXX_SOURCES |
| 70 | filesystem/filesystem_common.h |
| 71 | filesystem/operations.cpp |
| 72 | filesystem/directory_iterator.cpp |
| 73 | ) |
Eric Fiselier | f1d87f8 | 2019-03-21 00:04:31 | [diff] [blame] | 74 | # Filesystem uses __int128_t, which requires a definition of __muloi4 when |
| 75 | # compiled with UBSAN. This definition is not provided by libgcc_s, but is |
| 76 | # provided by compiler-rt. So we need to disable it to avoid having multiple |
| 77 | # definitions. See filesystem/int128_builtins.cpp. |
| 78 | if (NOT LIBCXX_USE_COMPILER_RT) |
Petr Hosek | f80c4b6 | 2019-05-01 06:40:36 | [diff] [blame] | 79 | list(APPEND LIBCXX_SOURCES |
| 80 | filesystem/int128_builtins.cpp |
| 81 | ) |
Eric Fiselier | f1d87f8 | 2019-03-21 00:04:31 | [diff] [blame] | 82 | endif() |
Louis Dionne | cc37af7 | 2019-03-19 20:56:13 | [diff] [blame] | 83 | endif() |
| 84 | |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 85 | # Add all the headers to the project for IDEs. |
Eric Fiselier | 6627c70 | 2015-12-16 23:41:05 | [diff] [blame] | 86 | if (LIBCXX_CONFIGURE_IDE) |
Howard Hinnant | b2f52bb | 2012-03-19 15:40:23 | [diff] [blame] | 87 | file(GLOB_RECURSE LIBCXX_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../include/*) |
Howard Hinnant | 3c78ca0 | 2011-09-22 19:10:18 | [diff] [blame] | 88 | if(WIN32) |
Howard Hinnant | b2f52bb | 2012-03-19 15:40:23 | [diff] [blame] | 89 | file( GLOB LIBCXX_WIN32_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../include/support/win32/*.h) |
| 90 | list(APPEND LIBCXX_HEADERS ${LIBCXX_WIN32_HEADERS}) |
Howard Hinnant | 3c78ca0 | 2011-09-22 19:10:18 | [diff] [blame] | 91 | endif() |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 92 | # Force them all into the headers dir on MSVC, otherwise they end up at |
| 93 | # project scope because they don't have extensions. |
| 94 | if (MSVC_IDE) |
Howard Hinnant | b2f52bb | 2012-03-19 15:40:23 | [diff] [blame] | 95 | source_group("Header Files" FILES ${LIBCXX_HEADERS}) |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 96 | endif() |
| 97 | endif() |
| 98 | |
Chris Bieneman | a1b79ae | 2015-12-03 18:52:54 | [diff] [blame] | 99 | if(NOT LIBCXX_INSTALL_LIBRARY) |
| 100 | set(exclude_from_all EXCLUDE_FROM_ALL) |
| 101 | endif() |
| 102 | |
Saleem Abdulrasool | 99c19ad | 2017-01-04 05:49:55 | [diff] [blame] | 103 | # If LIBCXX_CXX_ABI_LIBRARY_PATH is defined we want to add it to the search path. |
| 104 | add_link_flags_if(LIBCXX_CXX_ABI_LIBRARY_PATH |
| 105 | "${CMAKE_LIBRARY_PATH_FLAG}${LIBCXX_CXX_ABI_LIBRARY_PATH}") |
Eric Fiselier | 0357171 | 2015-03-03 15:59:51 | [diff] [blame] | 106 | |
Eric Fiselier | 2aeac46 | 2017-03-11 03:24:18 | [diff] [blame] | 107 | |
| 108 | if (LIBCXX_GENERATE_COVERAGE AND NOT LIBCXX_COVERAGE_LIBRARY) |
| 109 | find_compiler_rt_library(profile LIBCXX_COVERAGE_LIBRARY) |
| 110 | endif() |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 111 | add_library_flags_if(LIBCXX_COVERAGE_LIBRARY "${LIBCXX_COVERAGE_LIBRARY}") |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 112 | |
Eric Fiselier | d1bac4c | 2015-07-22 00:33:36 | [diff] [blame] | 113 | if (APPLE AND LLVM_USE_SANITIZER) |
Kuba Brecka | 50bc34ca31 | 2016-09-15 11:04:53 | [diff] [blame] | 114 | if (("${LLVM_USE_SANITIZER}" STREQUAL "Address") OR |
| 115 | ("${LLVM_USE_SANITIZER}" STREQUAL "Address;Undefined") OR |
| 116 | ("${LLVM_USE_SANITIZER}" STREQUAL "Undefined;Address")) |
Eric Fiselier | d1bac4c | 2015-07-22 00:33:36 | [diff] [blame] | 117 | set(LIBFILE "libclang_rt.asan_osx_dynamic.dylib") |
| 118 | elseif("${LLVM_USE_SANITIZER}" STREQUAL "Undefined") |
| 119 | set(LIBFILE "libclang_rt.ubsan_osx_dynamic.dylib") |
Kuba Brecka | d634df5 | 2016-09-14 14:12:50 | [diff] [blame] | 120 | elseif("${LLVM_USE_SANITIZER}" STREQUAL "Thread") |
| 121 | set(LIBFILE "libclang_rt.tsan_osx_dynamic.dylib") |
Eric Fiselier | d1bac4c | 2015-07-22 00:33:36 | [diff] [blame] | 122 | else() |
| 123 | message(WARNING "LLVM_USE_SANITIZER=${LLVM_USE_SANITIZER} is not supported on OS X") |
| 124 | endif() |
| 125 | if (LIBFILE) |
Eric Fiselier | 2aeac46 | 2017-03-11 03:24:18 | [diff] [blame] | 126 | find_compiler_rt_dir(LIBDIR) |
Eric Fiselier | d1bac4c | 2015-07-22 00:33:36 | [diff] [blame] | 127 | if (NOT IS_DIRECTORY "${LIBDIR}") |
| 128 | message(FATAL_ERROR "Cannot find compiler-rt directory on OS X required for LLVM_USE_SANITIZER") |
| 129 | endif() |
| 130 | set(LIBCXX_SANITIZER_LIBRARY "${LIBDIR}/${LIBFILE}") |
| 131 | set(LIBCXX_SANITIZER_LIBRARY "${LIBCXX_SANITIZER_LIBRARY}" PARENT_SCOPE) |
| 132 | message(STATUS "Manually linking compiler-rt library: ${LIBCXX_SANITIZER_LIBRARY}") |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 133 | add_library_flags("${LIBCXX_SANITIZER_LIBRARY}") |
| 134 | add_link_flags("-Wl,-rpath,${LIBDIR}") |
Eric Fiselier | d1bac4c | 2015-07-22 00:33:36 | [diff] [blame] | 135 | endif() |
| 136 | endif() |
| 137 | |
Louis Dionne | 68924e6 | 2019-04-30 15:44:19 | [diff] [blame] | 138 | function(cxx_link_system_libraries target) |
| 139 | target_add_link_flags_if_supported(${target} PRIVATE "-nodefaultlibs") |
| 140 | target_add_compile_flags_if_supported(${target} PRIVATE "/Zl") |
| 141 | target_add_link_flags_if_supported(${target} PRIVATE "/nodefaultlib") |
Eric Fiselier | 78fdf2d | 2015-03-31 04:15:45 | [diff] [blame] | 142 | |
Louis Dionne | 223ed70 | 2019-05-02 17:43:48 | [diff] [blame] | 143 | if (LIBCXX_HAS_SYSTEM_LIB) |
| 144 | target_link_libraries(${target} PUBLIC System) |
| 145 | endif() |
| 146 | |
Louis Dionne | 68924e6 | 2019-04-30 15:44:19 | [diff] [blame] | 147 | if (LIBCXX_HAS_PTHREAD_LIB) |
| 148 | target_link_libraries(${target} PUBLIC pthread) |
Eric Fiselier | 7e3ee09 | 2017-01-14 07:54:39 | [diff] [blame] | 149 | endif() |
Eric Fiselier | 7e3ee09 | 2017-01-14 07:54:39 | [diff] [blame] | 150 | |
Louis Dionne | 68924e6 | 2019-04-30 15:44:19 | [diff] [blame] | 151 | if (LIBCXX_HAS_C_LIB) |
| 152 | target_link_libraries(${target} PUBLIC c) |
| 153 | endif() |
| 154 | |
| 155 | if (LIBCXX_HAS_M_LIB) |
| 156 | target_link_libraries(${target} PUBLIC m) |
| 157 | endif() |
| 158 | |
| 159 | if (LIBCXX_HAS_RT_LIB) |
| 160 | target_link_libraries(${target} PUBLIC rt) |
| 161 | endif() |
| 162 | |
| 163 | if (LIBCXX_USE_COMPILER_RT) |
| 164 | find_compiler_rt_library(builtins LIBCXX_BUILTINS_LIBRARY) |
| 165 | if (LIBCXX_BUILTINS_LIBRARY) |
| 166 | target_link_libraries(${target} PUBLIC "${LIBCXX_BUILTINS_LIBRARY}") |
| 167 | endif() |
| 168 | elseif (LIBCXX_HAS_GCC_S_LIB) |
| 169 | target_link_libraries(${target} PUBLIC gcc_s) |
| 170 | endif() |
| 171 | |
| 172 | if (LIBCXX_HAVE_CXX_ATOMICS_WITH_LIB) |
| 173 | target_link_libraries(${target} PUBLIC atomic) |
| 174 | endif() |
| 175 | |
| 176 | if (MINGW) |
| 177 | target_link_libraries(${target} PUBLIC "${MINGW_LIBRARIES}") |
| 178 | endif() |
| 179 | |
| 180 | if (LIBCXX_TARGETING_MSVC) |
| 181 | if (LIBCXX_DEBUG_BUILD) |
| 182 | set(LIB_SUFFIX "d") |
| 183 | else() |
| 184 | set(LIB_SUFFIX "") |
| 185 | endif() |
| 186 | |
| 187 | target_link_libraries(${target} PUBLIC ucrt${LIB_SUFFIX}) # Universal C runtime |
| 188 | target_link_libraries(${target} PUBLIC vcruntime${LIB_SUFFIX}) # C++ runtime |
| 189 | target_link_libraries(${target} PUBLIC msvcrt${LIB_SUFFIX}) # C runtime startup files |
| 190 | target_link_libraries(${target} PUBLIC msvcprt${LIB_SUFFIX}) # C++ standard library. Required for exception_ptr internals. |
| 191 | # Required for standards-complaint wide character formatting functions |
| 192 | # (e.g. `printfw`/`scanfw`) |
| 193 | target_link_libraries(${target} PUBLIC iso_stdio_wide_specifiers) |
| 194 | endif() |
| 195 | endfunction() |
Eric Fiselier | cc1f65c | 2017-01-14 06:06:47 | [diff] [blame] | 196 | |
Louis Dionne | 989eca6 | 2019-03-14 14:19:08 | [diff] [blame] | 197 | function(cxx_set_common_defines name) |
Petr Hosek | a2685cd | 2019-01-06 06:14:31 | [diff] [blame] | 198 | if(LIBCXX_CXX_ABI_HEADER_TARGET) |
| 199 | add_dependencies(${name} ${LIBCXX_CXX_ABI_HEADER_TARGET}) |
| 200 | endif() |
| 201 | if(WIN32 AND NOT MINGW) |
| 202 | target_compile_definitions(${name} |
| 203 | PRIVATE |
| 204 | # Ignore the -MSC_VER mismatch, as we may build |
| 205 | # with a different compatibility version. |
| 206 | _ALLOW_MSC_VER_MISMATCH |
| 207 | # Don't check the msvcprt iterator debug levels |
| 208 | # as we will define the iterator types; libc++ |
| 209 | # uses a different macro to identify the debug |
| 210 | # level. |
| 211 | _ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH |
| 212 | # We are building the c++ runtime, don't pull in |
| 213 | # msvcprt. |
| 214 | _CRTBLD |
| 215 | # Don't warn on the use of "deprecated" |
| 216 | # "insecure" functions which are standards |
| 217 | # specified. |
| 218 | _CRT_SECURE_NO_WARNINGS |
| 219 | # Use the ISO conforming behaviour for conversion |
| 220 | # in printf, scanf. |
| 221 | _CRT_STDIO_ISO_WIDE_SPECIFIERS) |
| 222 | endif() |
Louis Dionne | 989eca6 | 2019-03-14 14:19:08 | [diff] [blame] | 223 | endfunction() |
Petr Hosek | a2685cd | 2019-01-06 06:14:31 | [diff] [blame] | 224 | |
Louis Dionne | 989eca6 | 2019-03-14 14:19:08 | [diff] [blame] | 225 | split_list(LIBCXX_COMPILE_FLAGS) |
| 226 | split_list(LIBCXX_LINK_FLAGS) |
Petr Hosek | 9e49a33 | 2016-08-08 22:57:25 | [diff] [blame] | 227 | |
Petr Hosek | 9e49a33 | 2016-08-08 22:57:25 | [diff] [blame] | 228 | # Build the shared library. |
| 229 | if (LIBCXX_ENABLE_SHARED) |
Louis Dionne | 989eca6 | 2019-03-14 14:19:08 | [diff] [blame] | 230 | add_library(cxx_shared SHARED ${exclude_from_all} ${LIBCXX_SOURCES} ${LIBCXX_HEADERS}) |
Don Hinton | 88434fe | 2018-01-27 18:55:30 | [diff] [blame] | 231 | if(COMMAND llvm_setup_rpath) |
Don Hinton | d21aeff | 2018-01-26 01:34:51 | [diff] [blame] | 232 | llvm_setup_rpath(cxx_shared) |
| 233 | endif() |
Louis Dionne | 68924e6 | 2019-04-30 15:44:19 | [diff] [blame] | 234 | cxx_link_system_libraries(cxx_shared) |
Petr Hosek | 8e78915 | 2019-01-30 23:18:05 | [diff] [blame] | 235 | target_link_libraries(cxx_shared PRIVATE ${LIBCXX_LIBRARIES}) |
Petr Hosek | 9e49a33 | 2016-08-08 22:57:25 | [diff] [blame] | 236 | set_target_properties(cxx_shared |
| 237 | PROPERTIES |
Louis Dionne | 989eca6 | 2019-03-14 14:19:08 | [diff] [blame] | 238 | COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}" |
Petr Hosek | 9e49a33 | 2016-08-08 22:57:25 | [diff] [blame] | 239 | LINK_FLAGS "${LIBCXX_LINK_FLAGS}" |
| 240 | OUTPUT_NAME "c++" |
| 241 | VERSION "${LIBCXX_ABI_VERSION}.0" |
| 242 | SOVERSION "${LIBCXX_ABI_VERSION}" |
Louis Dionne | 702411f | 2019-03-14 17:15:47 | [diff] [blame] | 243 | DEFINE_SYMBOL "" |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 244 | ) |
Louis Dionne | 989eca6 | 2019-03-14 14:19:08 | [diff] [blame] | 245 | cxx_set_common_defines(cxx_shared) |
| 246 | |
Petr Hosek | 1788b89 | 2019-04-17 21:41:09 | [diff] [blame] | 247 | # Link against LLVM libunwind |
| 248 | if (LIBCXXABI_USE_LLVM_UNWINDER) |
| 249 | if (NOT LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY AND (TARGET unwind_shared OR HAVE_LIBUNWIND)) |
Louis Dionne | 68924e6 | 2019-04-30 15:44:19 | [diff] [blame] | 250 | target_link_libraries(cxx_shared PUBLIC unwind_shared) |
Petr Hosek | 1788b89 | 2019-04-17 21:41:09 | [diff] [blame] | 251 | list(APPEND LIBCXX_INTERFACE_LIBRARIES unwind_shared) # For the linker script |
| 252 | elseif (LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY AND (TARGET unwind_static OR HAVE_LIBUNWIND)) |
| 253 | # libunwind is already included in libc++abi |
| 254 | else() |
| 255 | target_link_libraries(cxx_shared PRIVATE unwind) |
| 256 | list(APPEND LIBCXX_INTERFACE_LIBRARIES unwind) # For the linker script |
| 257 | endif() |
| 258 | endif() |
| 259 | |
Louis Dionne | 6e68a79 | 2019-04-05 20:29:54 | [diff] [blame] | 260 | # Link against libc++abi |
| 261 | if (LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY) |
| 262 | if (APPLE) |
Martin Storsjo | c90045b | 2019-04-09 14:31:09 | [diff] [blame] | 263 | target_link_libraries(cxx_shared PRIVATE "-Wl,-force_load" "${LIBCXX_CXX_STATIC_ABI_LIBRARY}") |
Louis Dionne | 6e68a79 | 2019-04-05 20:29:54 | [diff] [blame] | 264 | else() |
Martin Storsjo | c90045b | 2019-04-09 14:31:09 | [diff] [blame] | 265 | target_link_libraries(cxx_shared PRIVATE "-Wl,--whole-archive,-Bstatic" "${LIBCXX_CXX_STATIC_ABI_LIBRARY}" "-Wl,-Bdynamic,--no-whole-archive") |
Louis Dionne | 6e68a79 | 2019-04-05 20:29:54 | [diff] [blame] | 266 | endif() |
| 267 | else() |
Louis Dionne | 68924e6 | 2019-04-30 15:44:19 | [diff] [blame] | 268 | target_link_libraries(cxx_shared PUBLIC "${LIBCXX_CXX_SHARED_ABI_LIBRARY}") |
Louis Dionne | cd9a528 | 2019-04-05 21:05:32 | [diff] [blame] | 269 | list(APPEND LIBCXX_INTERFACE_LIBRARIES "${LIBCXX_CXX_SHARED_ABI_LIBRARY}") # For the linker script |
Louis Dionne | 6e68a79 | 2019-04-05 20:29:54 | [diff] [blame] | 270 | endif() |
| 271 | |
| 272 | # Maybe re-export symbols from libc++abi |
| 273 | if (APPLE AND (LIBCXX_CXX_ABI_LIBNAME STREQUAL "libcxxabi" OR |
| 274 | LIBCXX_CXX_ABI_LIBNAME STREQUAL "default") |
| 275 | AND NOT DEFINED LIBCXX_OSX_REEXPORT_LIBCXXABI_SYMBOLS) |
| 276 | set(LIBCXX_OSX_REEXPORT_LIBCXXABI_SYMBOLS ON) |
| 277 | endif() |
| 278 | |
| 279 | if (LIBCXX_OSX_REEXPORT_LIBCXXABI_SYMBOLS) |
| 280 | if ("${CMAKE_OSX_ARCHITECTURES}" MATCHES "^(armv6|armv7|armv7s)$") |
Petr Hosek | f80c4b6 | 2019-05-01 06:40:36 | [diff] [blame] | 281 | set(RE_EXPORT_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../lib/libc++sjlj-abi.v${LIBCXX_LIBCPPABI_VERSION}.exp") |
Louis Dionne | 6e68a79 | 2019-04-05 20:29:54 | [diff] [blame] | 282 | else() |
Petr Hosek | f80c4b6 | 2019-05-01 06:40:36 | [diff] [blame] | 283 | set(RE_EXPORT_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../lib/libc++abi.v${LIBCXX_LIBCPPABI_VERSION}.exp") |
Louis Dionne | 6e68a79 | 2019-04-05 20:29:54 | [diff] [blame] | 284 | endif() |
| 285 | target_link_libraries(cxx_shared PRIVATE |
Petr Hosek | f80c4b6 | 2019-05-01 06:40:36 | [diff] [blame] | 286 | "-Wl,-unexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/libc++unexp.exp" |
Louis Dionne | 6e68a79 | 2019-04-05 20:29:54 | [diff] [blame] | 287 | "-Wl,-reexported_symbols_list,${RE_EXPORT_LIST}" |
Petr Hosek | f80c4b6 | 2019-05-01 06:40:36 | [diff] [blame] | 288 | "-Wl,-force_symbols_not_weak_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/notweak.exp" |
| 289 | "-Wl,-force_symbols_weak_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/weak.exp") |
Louis Dionne | 6e68a79 | 2019-04-05 20:29:54 | [diff] [blame] | 290 | |
| 291 | if (NOT LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS) |
Petr Hosek | f80c4b6 | 2019-05-01 06:40:36 | [diff] [blame] | 292 | target_link_libraries(cxx_shared PRIVATE "-Wl,-reexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/libc++abi-new-delete.exp") |
Louis Dionne | 6e68a79 | 2019-04-05 20:29:54 | [diff] [blame] | 293 | endif() |
| 294 | endif() |
| 295 | |
| 296 | # Generate a linker script in place of a libc++.so symlink. Rerun this command |
| 297 | # after cxx builds. |
| 298 | if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT) |
| 299 | # Get the name of the ABI library and handle the case where CXXABI_LIBNAME |
| 300 | # is a target name and not a library. Ex cxxabi_shared. |
| 301 | set(LIBCXX_INTERFACE_LIBRARY_NAMES) |
| 302 | foreach(lib ${LIBCXX_INTERFACE_LIBRARIES}) |
| 303 | # FIXME: Handle cxxabi_static and unwind_static. |
| 304 | if (TARGET ${lib} OR |
| 305 | (${lib} MATCHES "cxxabi(_static|_shared)?" AND HAVE_LIBCXXABI) OR |
| 306 | (${lib} MATCHES "unwind(_static|_shared)?" AND HAVE_LIBUNWIND)) |
| 307 | list(APPEND LIBCXX_INTERFACE_LIBRARY_NAMES "$<TARGET_PROPERTY:${lib},OUTPUT_NAME>") |
| 308 | else() |
| 309 | list(APPEND LIBCXX_INTERFACE_LIBRARY_NAMES "${lib}") |
| 310 | endif() |
| 311 | endforeach() |
| 312 | add_custom_command(TARGET cxx_shared POST_BUILD |
| 313 | COMMAND |
| 314 | ${PYTHON_EXECUTABLE} ${LIBCXX_SOURCE_DIR}/utils/gen_link_script.py |
| 315 | ARGS |
Petr Hosek | e9a2d1c | 2019-04-22 19:51:33 | [diff] [blame] | 316 | --input "$<TARGET_SONAME_FILE:cxx_shared>" |
| 317 | --output "$<TARGET_LINKER_FILE:cxx_shared>" |
Louis Dionne | 6e68a79 | 2019-04-05 20:29:54 | [diff] [blame] | 318 | ${LIBCXX_INTERFACE_LIBRARY_NAMES} |
| 319 | WORKING_DIRECTORY ${LIBCXX_BUILD_DIR} |
| 320 | ) |
| 321 | endif() |
| 322 | |
Petr Hosek | 4a1e14e | 2018-07-24 23:27:51 | [diff] [blame] | 323 | list(APPEND LIBCXX_BUILD_TARGETS "cxx_shared") |
| 324 | if (LIBCXX_INSTALL_SHARED_LIBRARY) |
| 325 | list(APPEND LIBCXX_INSTALL_TARGETS "cxx_shared") |
| 326 | endif() |
Saleem Abdulrasool | 2d2ed1c | 2017-01-02 21:09:19 | [diff] [blame] | 327 | if(WIN32 AND NOT MINGW AND NOT "${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows") |
| 328 | # Since we most likely do not have a mt.exe replacement, disable the |
| 329 | # manifest bundling. This allows a normal cmake invocation to pass which |
| 330 | # will attempt to use the manifest tool to generate the bundled manifest |
| 331 | set_target_properties(cxx_shared PROPERTIES |
| 332 | APPEND_STRING PROPERTY LINK_FLAGS " /MANIFEST:NO") |
| 333 | endif() |
Petr Hosek | 9e49a33 | 2016-08-08 22:57:25 | [diff] [blame] | 334 | endif() |
| 335 | |
| 336 | # Build the static library. |
| 337 | if (LIBCXX_ENABLE_STATIC) |
Louis Dionne | 989eca6 | 2019-03-14 14:19:08 | [diff] [blame] | 338 | add_library(cxx_static STATIC ${exclude_from_all} ${LIBCXX_SOURCES} ${LIBCXX_HEADERS}) |
Louis Dionne | 68924e6 | 2019-04-30 15:44:19 | [diff] [blame] | 339 | cxx_link_system_libraries(cxx_static) |
Petr Hosek | 8e78915 | 2019-01-30 23:18:05 | [diff] [blame] | 340 | target_link_libraries(cxx_static PRIVATE ${LIBCXX_LIBRARIES}) |
Martell Malone | 8fd2d37 | 2017-05-25 22:37:15 | [diff] [blame] | 341 | set(CMAKE_STATIC_LIBRARY_PREFIX "lib") |
Petr Hosek | 9e49a33 | 2016-08-08 22:57:25 | [diff] [blame] | 342 | set_target_properties(cxx_static |
| 343 | PROPERTIES |
Louis Dionne | 989eca6 | 2019-03-14 14:19:08 | [diff] [blame] | 344 | COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}" |
Petr Hosek | 9e49a33 | 2016-08-08 22:57:25 | [diff] [blame] | 345 | LINK_FLAGS "${LIBCXX_LINK_FLAGS}" |
Martell Malone | 8fd2d37 | 2017-05-25 22:37:15 | [diff] [blame] | 346 | OUTPUT_NAME "c++" |
Petr Hosek | 9e49a33 | 2016-08-08 22:57:25 | [diff] [blame] | 347 | ) |
Louis Dionne | 850a3d3 | 2019-03-14 14:52:26 | [diff] [blame] | 348 | cxx_set_common_defines(cxx_static) |
Louis Dionne | 989eca6 | 2019-03-14 14:19:08 | [diff] [blame] | 349 | |
| 350 | if (LIBCXX_HERMETIC_STATIC_LIBRARY) |
| 351 | append_flags_if_supported(CXX_STATIC_LIBRARY_FLAGS -fvisibility=hidden) |
Petr Hosek | 741f52c | 2019-05-06 01:22:28 | [diff] [blame] | 352 | # If the hermetic library doesn't define the operator new/delete functions |
| 353 | # then its code shouldn't declare them with hidden visibility. They might |
| 354 | # actually be provided by a shared library at link time. |
| 355 | if (LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS) |
| 356 | append_flags_if_supported(CXX_STATIC_LIBRARY_FLAGS -fvisibility-global-new-delete-hidden) |
| 357 | endif() |
Louis Dionne | 989eca6 | 2019-03-14 14:19:08 | [diff] [blame] | 358 | target_compile_options(cxx_static PRIVATE ${CXX_STATIC_LIBRARY_FLAGS}) |
| 359 | target_compile_definitions(cxx_static PRIVATE _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) |
| 360 | endif() |
| 361 | |
Petr Hosek | 4a1e14e | 2018-07-24 23:27:51 | [diff] [blame] | 362 | list(APPEND LIBCXX_BUILD_TARGETS "cxx_static") |
| 363 | if (LIBCXX_INSTALL_STATIC_LIBRARY) |
| 364 | list(APPEND LIBCXX_INSTALL_TARGETS "cxx_static") |
| 365 | endif() |
Eric Fiselier | bf58c8e | 2016-11-18 19:53:45 | [diff] [blame] | 366 | # Attempt to merge the libc++.a archive and the ABI library archive into one. |
Petr Hosek | 058c04c | 2018-07-24 07:06:17 | [diff] [blame] | 367 | if (LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY) |
Eric Fiselier | bf58c8e | 2016-11-18 19:53:45 | [diff] [blame] | 368 | set(MERGE_ARCHIVES_SEARCH_PATHS "") |
| 369 | if (LIBCXX_CXX_ABI_LIBRARY_PATH) |
| 370 | set(MERGE_ARCHIVES_SEARCH_PATHS "-L${LIBCXX_CXX_ABI_LIBRARY_PATH}") |
| 371 | endif() |
Petr Hosek | 30d9af1 | 2019-04-03 01:33:14 | [diff] [blame] | 372 | if (TARGET "${LIBCXX_CXX_STATIC_ABI_LIBRARY}" OR HAVE_LIBCXXABI) |
| 373 | set(MERGE_ARCHIVES_ABI_TARGET "$<TARGET_LINKER_FILE:${LIBCXX_CXX_STATIC_ABI_LIBRARY}>") |
Eric Fiselier | bf58c8e | 2016-11-18 19:53:45 | [diff] [blame] | 374 | else() |
Saleem Abdulrasool | f1ae11a | 2017-01-04 05:49:57 | [diff] [blame] | 375 | set(MERGE_ARCHIVES_ABI_TARGET |
Petr Hosek | 30d9af1 | 2019-04-03 01:33:14 | [diff] [blame] | 376 | "${CMAKE_STATIC_LIBRARY_PREFIX}${LIBCXX_CXX_STATIC_ABI_LIBRARY}${CMAKE_STATIC_LIBRARY_SUFFIX}") |
Eric Fiselier | bf58c8e | 2016-11-18 19:53:45 | [diff] [blame] | 377 | endif() |
| 378 | add_custom_command(TARGET cxx_static POST_BUILD |
| 379 | COMMAND |
| 380 | ${PYTHON_EXECUTABLE} ${LIBCXX_SOURCE_DIR}/utils/merge_archives.py |
| 381 | ARGS |
| 382 | -o $<TARGET_LINKER_FILE:cxx_static> |
Martin Storsjo | fb8eb6f | 2017-09-13 06:55:44 | [diff] [blame] | 383 | --ar "${CMAKE_AR}" |
Eric Fiselier | bf58c8e | 2016-11-18 19:53:45 | [diff] [blame] | 384 | "$<TARGET_LINKER_FILE:cxx_static>" |
| 385 | "${MERGE_ARCHIVES_ABI_TARGET}" |
| 386 | "${MERGE_ARCHIVES_SEARCH_PATHS}" |
| 387 | WORKING_DIRECTORY ${LIBCXX_BUILD_DIR} |
| 388 | ) |
| 389 | endif() |
Petr Hosek | 9e49a33 | 2016-08-08 22:57:25 | [diff] [blame] | 390 | endif() |
| 391 | |
Eric Fiselier | 67ea02b | 2018-07-27 03:47:46 | [diff] [blame] | 392 | # Add a meta-target for both libraries. |
| 393 | add_custom_target(cxx DEPENDS cxx-headers ${LIBCXX_BUILD_TARGETS}) |
| 394 | |
Eric Fiselier | 27cb2f1 | 2016-05-03 21:30:18 | [diff] [blame] | 395 | if (LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY) |
Petr Hosek | f80c4b6 | 2019-05-01 06:40:36 | [diff] [blame] | 396 | set(LIBCXX_EXPERIMENTAL_SOURCES |
| 397 | experimental/memory_resource.cpp |
| 398 | ) |
Eric Fiselier | 998a5c8 | 2018-07-27 03:07:09 | [diff] [blame] | 399 | add_library(cxx_experimental STATIC ${LIBCXX_EXPERIMENTAL_SOURCES}) |
Petr Hosek | 9e49a33 | 2016-08-08 22:57:25 | [diff] [blame] | 400 | if (LIBCXX_ENABLE_SHARED) |
| 401 | target_link_libraries(cxx_experimental cxx_shared) |
| 402 | else() |
| 403 | target_link_libraries(cxx_experimental cxx_static) |
| 404 | endif() |
Eric Fiselier | a5e201f | 2016-05-10 16:17:43 | [diff] [blame] | 405 | |
| 406 | set(experimental_flags "${LIBCXX_COMPILE_FLAGS}") |
| 407 | check_flag_supported(-std=c++14) |
| 408 | if (NOT MSVC AND LIBCXX_SUPPORTS_STD_EQ_CXX14_FLAG) |
| 409 | string(REPLACE "-std=c++11" "-std=c++14" experimental_flags "${LIBCXX_COMPILE_FLAGS}") |
| 410 | endif() |
Eric Fiselier | 27cb2f1 | 2016-05-03 21:30:18 | [diff] [blame] | 411 | set_target_properties(cxx_experimental |
| 412 | PROPERTIES |
Eric Fiselier | a5e201f | 2016-05-10 16:17:43 | [diff] [blame] | 413 | COMPILE_FLAGS "${experimental_flags}" |
Eric Fiselier | 27cb2f1 | 2016-05-03 21:30:18 | [diff] [blame] | 414 | OUTPUT_NAME "c++experimental" |
| 415 | ) |
| 416 | endif() |
| 417 | |
Eric Fiselier | 00f6bea | 2017-01-06 20:05:40 | [diff] [blame] | 418 | if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY) |
Asiri Rathnayake | 8c2bf45 | 2016-09-11 21:46:40 | [diff] [blame] | 419 | file(GLOB LIBCXX_EXTERNAL_THREADING_SUPPORT_SOURCES ../test/support/external_threads.cpp) |
| 420 | |
| 421 | if (LIBCXX_ENABLE_SHARED) |
| 422 | add_library(cxx_external_threads SHARED ${LIBCXX_EXTERNAL_THREADING_SUPPORT_SOURCES}) |
| 423 | else() |
| 424 | add_library(cxx_external_threads STATIC ${LIBCXX_EXTERNAL_THREADING_SUPPORT_SOURCES}) |
| 425 | endif() |
| 426 | |
| 427 | set_target_properties(cxx_external_threads |
| 428 | PROPERTIES |
| 429 | LINK_FLAGS "${LIBCXX_LINK_FLAGS}" |
| 430 | COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}" |
| 431 | OUTPUT_NAME "c++external_threads" |
| 432 | ) |
| 433 | endif() |
| 434 | |
Eric Fiselier | d77135f | 2015-08-26 20:18:21 | [diff] [blame] | 435 | if (LIBCXX_INSTALL_LIBRARY) |
Eric Fiselier | 27cb2f1 | 2016-05-03 21:30:18 | [diff] [blame] | 436 | if (LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY) |
| 437 | set(experimental_lib cxx_experimental) |
| 438 | endif() |
Louis Dionne | cc37af7 | 2019-03-19 20:56:13 | [diff] [blame] | 439 | install(TARGETS ${LIBCXX_INSTALL_TARGETS} ${experimental_lib} |
Petr Hosek | 81f433b | 2019-05-22 21:08:33 | [diff] [blame^] | 440 | LIBRARY DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx |
| 441 | ARCHIVE DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx |
Eric Fiselier | d77135f | 2015-08-26 20:18:21 | [diff] [blame] | 442 | ) |
Eric Fiselier | 8241405 | 2015-10-14 19:54:03 | [diff] [blame] | 443 | # NOTE: This install command must go after the cxx install command otherwise |
| 444 | # it will not be executed after the library symlinks are installed. |
Petr Hosek | 9e49a33 | 2016-08-08 22:57:25 | [diff] [blame] | 445 | if (LIBCXX_ENABLE_SHARED AND LIBCXX_ENABLE_ABI_LINKER_SCRIPT) |
Eric Fiselier | e2dd2fd | 2015-10-22 21:24:01 | [diff] [blame] | 446 | # Replace the libc++ filename with $<TARGET_LINKER_FILE:cxx> |
| 447 | # after we required CMake 3.0. |
Eric Fiselier | cae21e4 | 2015-10-23 07:04:24 | [diff] [blame] | 448 | install(FILES "${LIBCXX_LIBRARY_DIR}/libc++${CMAKE_SHARED_LIBRARY_SUFFIX}" |
Petr Hosek | 81f433b | 2019-05-22 21:08:33 | [diff] [blame^] | 449 | DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} |
Eric Fiselier | 8241405 | 2015-10-14 19:54:03 | [diff] [blame] | 450 | COMPONENT libcxx) |
| 451 | endif() |
Eric Fiselier | d77135f | 2015-08-26 20:18:21 | [diff] [blame] | 452 | endif() |
Eric Fiselier | 7cb813f | 2015-08-19 17:41:53 | [diff] [blame] | 453 | |
Eric Fiselier | d77135f | 2015-08-26 20:18:21 | [diff] [blame] | 454 | if (NOT CMAKE_CONFIGURATION_TYPES AND (LIBCXX_INSTALL_LIBRARY OR |
| 455 | LIBCXX_INSTALL_HEADERS)) |
Chris Bieneman | a1b79ae | 2015-12-03 18:52:54 | [diff] [blame] | 456 | if(LIBCXX_INSTALL_LIBRARY) |
Eric Fiselier | 59e9748 | 2016-05-03 05:34:38 | [diff] [blame] | 457 | set(lib_install_target cxx) |
Chris Bieneman | a1b79ae | 2015-12-03 18:52:54 | [diff] [blame] | 458 | endif() |
Eric Fiselier | 27cb2f1 | 2016-05-03 21:30:18 | [diff] [blame] | 459 | if (LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY) |
| 460 | set(experimental_lib_install_target cxx_experimental) |
| 461 | endif() |
Chris Bieneman | 4497e3a | 2016-04-29 22:17:15 | [diff] [blame] | 462 | if(LIBCXX_INSTALL_HEADERS) |
Chris Bieneman | f17227a | 2016-08-24 22:17:06 | [diff] [blame] | 463 | set(header_install_target install-cxx-headers) |
Chris Bieneman | 4497e3a | 2016-04-29 22:17:15 | [diff] [blame] | 464 | endif() |
Chris Bieneman | f17227a | 2016-08-24 22:17:06 | [diff] [blame] | 465 | add_custom_target(install-cxx |
Eric Fiselier | 27cb2f1 | 2016-05-03 21:30:18 | [diff] [blame] | 466 | DEPENDS ${lib_install_target} |
| 467 | ${experimental_lib_install_target} |
| 468 | ${header_install_target} |
Eric Fiselier | d77135f | 2015-08-26 20:18:21 | [diff] [blame] | 469 | COMMAND "${CMAKE_COMMAND}" |
Chris Bieneman | f17227a | 2016-08-24 22:17:06 | [diff] [blame] | 470 | -DCMAKE_INSTALL_COMPONENT=cxx |
Eric Fiselier | d77135f | 2015-08-26 20:18:21 | [diff] [blame] | 471 | -P "${LIBCXX_BINARY_DIR}/cmake_install.cmake") |
Shoaib Meenai | f7c7944 | 2017-12-06 21:03:42 | [diff] [blame] | 472 | add_custom_target(install-cxx-stripped |
| 473 | DEPENDS ${lib_install_target} |
| 474 | ${experimental_lib_install_target} |
| 475 | ${header_install_target} |
| 476 | COMMAND "${CMAKE_COMMAND}" |
| 477 | -DCMAKE_INSTALL_COMPONENT=cxx |
| 478 | -DCMAKE_INSTALL_DO_STRIP=1 |
| 479 | -P "${LIBCXX_BINARY_DIR}/cmake_install.cmake") |
Chris Bieneman | f17227a | 2016-08-24 22:17:06 | [diff] [blame] | 480 | add_custom_target(install-libcxx DEPENDS install-cxx) |
Eric Fiselier | 7cb813f | 2015-08-19 17:41:53 | [diff] [blame] | 481 | endif() |