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 |
Olivier Giroux | 54fa9ec | 2020-02-18 14:58:34 | [diff] [blame] | 7 | atomic.cpp |
| 8 | barrier.cpp |
Petr Hosek | f80c4b6 | 2019-05-01 06:40:36 | [diff] [blame] | 9 | bind.cpp |
| 10 | charconv.cpp |
| 11 | chrono.cpp |
| 12 | condition_variable.cpp |
Eric Fiselier | 8cedf04 | 2019-07-07 17:24:03 | [diff] [blame] | 13 | condition_variable_destructor.cpp |
Petr Hosek | f80c4b6 | 2019-05-01 06:40:36 | [diff] [blame] | 14 | debug.cpp |
| 15 | exception.cpp |
| 16 | functional.cpp |
| 17 | future.cpp |
| 18 | hash.cpp |
| 19 | include/apple_availability.h |
| 20 | include/atomic_support.h |
| 21 | include/config_elast.h |
| 22 | include/refstring.h |
| 23 | ios.cpp |
| 24 | iostream.cpp |
| 25 | locale.cpp |
| 26 | memory.cpp |
| 27 | mutex.cpp |
Eric Fiselier | 8baf838 | 2019-07-07 01:20:54 | [diff] [blame] | 28 | mutex_destructor.cpp |
Petr Hosek | f80c4b6 | 2019-05-01 06:40:36 | [diff] [blame] | 29 | new.cpp |
| 30 | optional.cpp |
| 31 | random.cpp |
Louis Dionne | ce6153a | 2020-06-30 16:42:44 | [diff] [blame] | 32 | random_shuffle.cpp |
Petr Hosek | f80c4b6 | 2019-05-01 06:40:36 | [diff] [blame] | 33 | regex.cpp |
| 34 | shared_mutex.cpp |
| 35 | stdexcept.cpp |
| 36 | string.cpp |
| 37 | strstream.cpp |
| 38 | support/runtime/exception_fallback.ipp |
| 39 | support/runtime/exception_glibcxx.ipp |
| 40 | support/runtime/exception_libcxxabi.ipp |
| 41 | support/runtime/exception_libcxxrt.ipp |
| 42 | support/runtime/exception_msvc.ipp |
| 43 | support/runtime/exception_pointer_cxxabi.ipp |
| 44 | support/runtime/exception_pointer_glibcxx.ipp |
| 45 | support/runtime/exception_pointer_msvc.ipp |
| 46 | support/runtime/exception_pointer_unimplemented.ipp |
| 47 | support/runtime/new_handler_fallback.ipp |
| 48 | support/runtime/stdexcept_default.ipp |
| 49 | support/runtime/stdexcept_vcruntime.ipp |
| 50 | system_error.cpp |
| 51 | thread.cpp |
| 52 | typeinfo.cpp |
| 53 | utility.cpp |
| 54 | valarray.cpp |
| 55 | variant.cpp |
| 56 | vector.cpp |
| 57 | ) |
| 58 | |
Howard Hinnant | 3c78ca0 | 2011-09-22 19:10:18 | [diff] [blame] | 59 | if(WIN32) |
Petr Hosek | f80c4b6 | 2019-05-01 06:40:36 | [diff] [blame] | 60 | list(APPEND LIBCXX_SOURCES |
| 61 | support/win32/locale_win32.cpp |
| 62 | support/win32/support.cpp |
| 63 | support/win32/thread_win32.cpp |
| 64 | ) |
Eric Fiselier | 53deb60 | 2014-11-25 21:57:41 | [diff] [blame] | 65 | elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "SunOS") |
Petr Hosek | f80c4b6 | 2019-05-01 06:40:36 | [diff] [blame] | 66 | list(APPEND LIBCXX_SOURCES |
| 67 | support/solaris/mbsnrtowcs.inc |
| 68 | support/solaris/wcsnrtombs.inc |
| 69 | support/solaris/xlocale.cpp |
| 70 | ) |
Howard Hinnant | 3c78ca0 | 2011-09-22 19:10:18 | [diff] [blame] | 71 | endif() |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 72 | |
Eric Fiselier | f1d87f8 | 2019-03-21 00:04:31 | [diff] [blame] | 73 | if (LIBCXX_ENABLE_FILESYSTEM) |
Petr Hosek | f80c4b6 | 2019-05-01 06:40:36 | [diff] [blame] | 74 | list(APPEND LIBCXX_SOURCES |
| 75 | filesystem/filesystem_common.h |
| 76 | filesystem/operations.cpp |
| 77 | filesystem/directory_iterator.cpp |
| 78 | ) |
Eric Fiselier | f1d87f8 | 2019-03-21 00:04:31 | [diff] [blame] | 79 | # Filesystem uses __int128_t, which requires a definition of __muloi4 when |
| 80 | # compiled with UBSAN. This definition is not provided by libgcc_s, but is |
| 81 | # provided by compiler-rt. So we need to disable it to avoid having multiple |
| 82 | # definitions. See filesystem/int128_builtins.cpp. |
| 83 | if (NOT LIBCXX_USE_COMPILER_RT) |
Petr Hosek | f80c4b6 | 2019-05-01 06:40:36 | [diff] [blame] | 84 | list(APPEND LIBCXX_SOURCES |
| 85 | filesystem/int128_builtins.cpp |
| 86 | ) |
Eric Fiselier | f1d87f8 | 2019-03-21 00:04:31 | [diff] [blame] | 87 | endif() |
Louis Dionne | cc37af7 | 2019-03-19 20:56:13 | [diff] [blame] | 88 | endif() |
| 89 | |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 90 | # Add all the headers to the project for IDEs. |
Eric Fiselier | 6627c70 | 2015-12-16 23:41:05 | [diff] [blame] | 91 | if (LIBCXX_CONFIGURE_IDE) |
Howard Hinnant | b2f52bb | 2012-03-19 15:40:23 | [diff] [blame] | 92 | file(GLOB_RECURSE LIBCXX_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../include/*) |
Howard Hinnant | 3c78ca0 | 2011-09-22 19:10:18 | [diff] [blame] | 93 | if(WIN32) |
Howard Hinnant | b2f52bb | 2012-03-19 15:40:23 | [diff] [blame] | 94 | file( GLOB LIBCXX_WIN32_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../include/support/win32/*.h) |
| 95 | list(APPEND LIBCXX_HEADERS ${LIBCXX_WIN32_HEADERS}) |
Howard Hinnant | 3c78ca0 | 2011-09-22 19:10:18 | [diff] [blame] | 96 | endif() |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 97 | # Force them all into the headers dir on MSVC, otherwise they end up at |
| 98 | # project scope because they don't have extensions. |
| 99 | if (MSVC_IDE) |
Howard Hinnant | b2f52bb | 2012-03-19 15:40:23 | [diff] [blame] | 100 | source_group("Header Files" FILES ${LIBCXX_HEADERS}) |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 101 | endif() |
| 102 | endif() |
| 103 | |
Chris Bieneman | a1b79ae | 2015-12-03 18:52:54 | [diff] [blame] | 104 | if(NOT LIBCXX_INSTALL_LIBRARY) |
| 105 | set(exclude_from_all EXCLUDE_FROM_ALL) |
| 106 | endif() |
| 107 | |
Saleem Abdulrasool | 99c19ad | 2017-01-04 05:49:55 | [diff] [blame] | 108 | # If LIBCXX_CXX_ABI_LIBRARY_PATH is defined we want to add it to the search path. |
| 109 | add_link_flags_if(LIBCXX_CXX_ABI_LIBRARY_PATH |
| 110 | "${CMAKE_LIBRARY_PATH_FLAG}${LIBCXX_CXX_ABI_LIBRARY_PATH}") |
Eric Fiselier | 0357171 | 2015-03-03 15:59:51 | [diff] [blame] | 111 | |
Eric Fiselier | 2aeac46 | 2017-03-11 03:24:18 | [diff] [blame] | 112 | |
| 113 | if (LIBCXX_GENERATE_COVERAGE AND NOT LIBCXX_COVERAGE_LIBRARY) |
| 114 | find_compiler_rt_library(profile LIBCXX_COVERAGE_LIBRARY) |
| 115 | endif() |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 116 | add_library_flags_if(LIBCXX_COVERAGE_LIBRARY "${LIBCXX_COVERAGE_LIBRARY}") |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 117 | |
Eric Fiselier | d1bac4c | 2015-07-22 00:33:36 | [diff] [blame] | 118 | if (APPLE AND LLVM_USE_SANITIZER) |
Kuba Brecka | 50bc34ca31 | 2016-09-15 11:04:53 | [diff] [blame] | 119 | if (("${LLVM_USE_SANITIZER}" STREQUAL "Address") OR |
| 120 | ("${LLVM_USE_SANITIZER}" STREQUAL "Address;Undefined") OR |
| 121 | ("${LLVM_USE_SANITIZER}" STREQUAL "Undefined;Address")) |
Eric Fiselier | d1bac4c | 2015-07-22 00:33:36 | [diff] [blame] | 122 | set(LIBFILE "libclang_rt.asan_osx_dynamic.dylib") |
| 123 | elseif("${LLVM_USE_SANITIZER}" STREQUAL "Undefined") |
| 124 | set(LIBFILE "libclang_rt.ubsan_osx_dynamic.dylib") |
Kuba Brecka | d634df5 | 2016-09-14 14:12:50 | [diff] [blame] | 125 | elseif("${LLVM_USE_SANITIZER}" STREQUAL "Thread") |
| 126 | set(LIBFILE "libclang_rt.tsan_osx_dynamic.dylib") |
Eric Fiselier | d1bac4c | 2015-07-22 00:33:36 | [diff] [blame] | 127 | else() |
| 128 | message(WARNING "LLVM_USE_SANITIZER=${LLVM_USE_SANITIZER} is not supported on OS X") |
| 129 | endif() |
| 130 | if (LIBFILE) |
Eric Fiselier | 2aeac46 | 2017-03-11 03:24:18 | [diff] [blame] | 131 | find_compiler_rt_dir(LIBDIR) |
Eric Fiselier | d1bac4c | 2015-07-22 00:33:36 | [diff] [blame] | 132 | if (NOT IS_DIRECTORY "${LIBDIR}") |
| 133 | message(FATAL_ERROR "Cannot find compiler-rt directory on OS X required for LLVM_USE_SANITIZER") |
| 134 | endif() |
| 135 | set(LIBCXX_SANITIZER_LIBRARY "${LIBDIR}/${LIBFILE}") |
| 136 | set(LIBCXX_SANITIZER_LIBRARY "${LIBCXX_SANITIZER_LIBRARY}" PARENT_SCOPE) |
| 137 | message(STATUS "Manually linking compiler-rt library: ${LIBCXX_SANITIZER_LIBRARY}") |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 138 | add_library_flags("${LIBCXX_SANITIZER_LIBRARY}") |
| 139 | add_link_flags("-Wl,-rpath,${LIBDIR}") |
Eric Fiselier | d1bac4c | 2015-07-22 00:33:36 | [diff] [blame] | 140 | endif() |
| 141 | endif() |
| 142 | |
Louis Dionne | 0a06eb9 | 2019-08-05 18:29:14 | [diff] [blame] | 143 | if (LIBCXX_ENABLE_PARALLEL_ALGORITHMS AND NOT TARGET pstl::ParallelSTL) |
| 144 | message(FATAL_ERROR "Could not find ParallelSTL") |
| 145 | endif() |
| 146 | |
Louis Dionne | 989eca6 | 2019-03-14 14:19:08 | [diff] [blame] | 147 | function(cxx_set_common_defines name) |
Petr Hosek | a2685cd | 2019-01-06 06:14:31 | [diff] [blame] | 148 | if(LIBCXX_CXX_ABI_HEADER_TARGET) |
| 149 | add_dependencies(${name} ${LIBCXX_CXX_ABI_HEADER_TARGET}) |
| 150 | endif() |
Louis Dionne | 0a06eb9 | 2019-08-05 18:29:14 | [diff] [blame] | 151 | |
| 152 | if (LIBCXX_ENABLE_PARALLEL_ALGORITHMS) |
| 153 | target_link_libraries(${name} PUBLIC pstl::ParallelSTL) |
| 154 | endif() |
Louis Dionne | 989eca6 | 2019-03-14 14:19:08 | [diff] [blame] | 155 | endfunction() |
Petr Hosek | a2685cd | 2019-01-06 06:14:31 | [diff] [blame] | 156 | |
Louis Dionne | 989eca6 | 2019-03-14 14:19:08 | [diff] [blame] | 157 | split_list(LIBCXX_COMPILE_FLAGS) |
| 158 | split_list(LIBCXX_LINK_FLAGS) |
Petr Hosek | 9e49a33 | 2016-08-08 22:57:25 | [diff] [blame] | 159 | |
Petr Hosek | 9e49a33 | 2016-08-08 22:57:25 | [diff] [blame] | 160 | # Build the shared library. |
| 161 | if (LIBCXX_ENABLE_SHARED) |
Louis Dionne | 989eca6 | 2019-03-14 14:19:08 | [diff] [blame] | 162 | add_library(cxx_shared SHARED ${exclude_from_all} ${LIBCXX_SOURCES} ${LIBCXX_HEADERS}) |
Don Hinton | 88434fe | 2018-01-27 18:55:30 | [diff] [blame] | 163 | if(COMMAND llvm_setup_rpath) |
Don Hinton | d21aeff | 2018-01-26 01:34:51 | [diff] [blame] | 164 | llvm_setup_rpath(cxx_shared) |
| 165 | endif() |
Petr Hosek | 8e78915 | 2019-01-30 23:18:05 | [diff] [blame] | 166 | target_link_libraries(cxx_shared PRIVATE ${LIBCXX_LIBRARIES}) |
Petr Hosek | 9e49a33 | 2016-08-08 22:57:25 | [diff] [blame] | 167 | set_target_properties(cxx_shared |
| 168 | PROPERTIES |
Louis Dionne | 989eca6 | 2019-03-14 14:19:08 | [diff] [blame] | 169 | COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}" |
Petr Hosek | 9e49a33 | 2016-08-08 22:57:25 | [diff] [blame] | 170 | LINK_FLAGS "${LIBCXX_LINK_FLAGS}" |
| 171 | OUTPUT_NAME "c++" |
| 172 | VERSION "${LIBCXX_ABI_VERSION}.0" |
| 173 | SOVERSION "${LIBCXX_ABI_VERSION}" |
Louis Dionne | 702411f | 2019-03-14 17:15:47 | [diff] [blame] | 174 | DEFINE_SYMBOL "" |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 175 | ) |
Louis Dionne | fadc84a | 2019-10-04 22:50:23 | [diff] [blame] | 176 | cxx_add_common_build_flags(cxx_shared) |
Louis Dionne | 989eca6 | 2019-03-14 14:19:08 | [diff] [blame] | 177 | cxx_set_common_defines(cxx_shared) |
| 178 | |
Petr Hosek | 1788b89 | 2019-04-17 21:41:09 | [diff] [blame] | 179 | # Link against LLVM libunwind |
| 180 | if (LIBCXXABI_USE_LLVM_UNWINDER) |
| 181 | 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] | 182 | target_link_libraries(cxx_shared PUBLIC unwind_shared) |
Petr Hosek | 1788b89 | 2019-04-17 21:41:09 | [diff] [blame] | 183 | elseif (LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY AND (TARGET unwind_static OR HAVE_LIBUNWIND)) |
| 184 | # libunwind is already included in libc++abi |
| 185 | else() |
Louis Dionne | 1ea8bb3 | 2019-10-08 21:10:20 | [diff] [blame] | 186 | target_link_libraries(cxx_shared PUBLIC unwind) |
Petr Hosek | 1788b89 | 2019-04-17 21:41:09 | [diff] [blame] | 187 | endif() |
| 188 | endif() |
| 189 | |
Louis Dionne | 6e68a79 | 2019-04-05 20:29:54 | [diff] [blame] | 190 | # Link against libc++abi |
| 191 | if (LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY) |
| 192 | if (APPLE) |
Martin Storsjo | c90045b | 2019-04-09 14:31:09 | [diff] [blame] | 193 | 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] | 194 | else() |
Martin Storsjo | c90045b | 2019-04-09 14:31:09 | [diff] [blame] | 195 | 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] | 196 | endif() |
| 197 | else() |
Louis Dionne | 68924e6 | 2019-04-30 15:44:19 | [diff] [blame] | 198 | target_link_libraries(cxx_shared PUBLIC "${LIBCXX_CXX_SHARED_ABI_LIBRARY}") |
Louis Dionne | 6e68a79 | 2019-04-05 20:29:54 | [diff] [blame] | 199 | endif() |
| 200 | |
| 201 | # Maybe re-export symbols from libc++abi |
| 202 | if (APPLE AND (LIBCXX_CXX_ABI_LIBNAME STREQUAL "libcxxabi" OR |
| 203 | LIBCXX_CXX_ABI_LIBNAME STREQUAL "default") |
| 204 | AND NOT DEFINED LIBCXX_OSX_REEXPORT_LIBCXXABI_SYMBOLS) |
| 205 | set(LIBCXX_OSX_REEXPORT_LIBCXXABI_SYMBOLS ON) |
| 206 | endif() |
| 207 | |
| 208 | if (LIBCXX_OSX_REEXPORT_LIBCXXABI_SYMBOLS) |
Louis Dionne | 6e68a79 | 2019-04-05 20:29:54 | [diff] [blame] | 209 | target_link_libraries(cxx_shared PRIVATE |
Petr Hosek | f80c4b6 | 2019-05-01 06:40:36 | [diff] [blame] | 210 | "-Wl,-unexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/libc++unexp.exp" |
Louis Dionne | ecf313c | 2020-04-20 09:22:20 | [diff] [blame] | 211 | "-Wl,-reexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/libc++abi.v${LIBCXX_LIBCPPABI_VERSION}.exp" |
Petr Hosek | f80c4b6 | 2019-05-01 06:40:36 | [diff] [blame] | 212 | "-Wl,-force_symbols_not_weak_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/notweak.exp" |
| 213 | "-Wl,-force_symbols_weak_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/weak.exp") |
Louis Dionne | 6e68a79 | 2019-04-05 20:29:54 | [diff] [blame] | 214 | |
Louis Dionne | ecf313c | 2020-04-20 09:22:20 | [diff] [blame] | 215 | if (LIBCXX_ENABLE_EXCEPTIONS) |
| 216 | if ("${CMAKE_OSX_ARCHITECTURES}" MATCHES "^(armv6|armv7|armv7s)$") |
| 217 | target_link_libraries(cxx_shared PRIVATE "-Wl,-reexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/libc++abi-exceptions.sjlj.exp") |
| 218 | else() |
| 219 | target_link_libraries(cxx_shared PRIVATE "-Wl,-reexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/libc++abi-exceptions.exp") |
| 220 | endif() |
| 221 | endif() |
| 222 | |
Louis Dionne | 6e68a79 | 2019-04-05 20:29:54 | [diff] [blame] | 223 | if (NOT LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS) |
Petr Hosek | f80c4b6 | 2019-05-01 06:40:36 | [diff] [blame] | 224 | 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] | 225 | endif() |
| 226 | endif() |
| 227 | |
Louis Dionne | 1ea8bb3 | 2019-10-08 21:10:20 | [diff] [blame] | 228 | # Generate a linker script in place of a libc++.so symlink. |
Louis Dionne | 6e68a79 | 2019-04-05 20:29:54 | [diff] [blame] | 229 | if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT) |
Louis Dionne | 1ea8bb3 | 2019-10-08 21:10:20 | [diff] [blame] | 230 | include(DefineLinkerScript) |
| 231 | define_linker_script(cxx_shared) |
Louis Dionne | 6e68a79 | 2019-04-05 20:29:54 | [diff] [blame] | 232 | endif() |
| 233 | |
Petr Hosek | 4a1e14e | 2018-07-24 23:27:51 | [diff] [blame] | 234 | list(APPEND LIBCXX_BUILD_TARGETS "cxx_shared") |
Saleem Abdulrasool | 2d2ed1c | 2017-01-02 21:09:19 | [diff] [blame] | 235 | if(WIN32 AND NOT MINGW AND NOT "${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows") |
| 236 | # Since we most likely do not have a mt.exe replacement, disable the |
| 237 | # manifest bundling. This allows a normal cmake invocation to pass which |
| 238 | # will attempt to use the manifest tool to generate the bundled manifest |
| 239 | set_target_properties(cxx_shared PROPERTIES |
| 240 | APPEND_STRING PROPERTY LINK_FLAGS " /MANIFEST:NO") |
| 241 | endif() |
Petr Hosek | 9e49a33 | 2016-08-08 22:57:25 | [diff] [blame] | 242 | endif() |
| 243 | |
| 244 | # Build the static library. |
| 245 | if (LIBCXX_ENABLE_STATIC) |
Louis Dionne | 989eca6 | 2019-03-14 14:19:08 | [diff] [blame] | 246 | add_library(cxx_static STATIC ${exclude_from_all} ${LIBCXX_SOURCES} ${LIBCXX_HEADERS}) |
Petr Hosek | 8e78915 | 2019-01-30 23:18:05 | [diff] [blame] | 247 | target_link_libraries(cxx_static PRIVATE ${LIBCXX_LIBRARIES}) |
Martell Malone | 8fd2d37 | 2017-05-25 22:37:15 | [diff] [blame] | 248 | set(CMAKE_STATIC_LIBRARY_PREFIX "lib") |
Petr Hosek | 9e49a33 | 2016-08-08 22:57:25 | [diff] [blame] | 249 | set_target_properties(cxx_static |
| 250 | PROPERTIES |
Louis Dionne | 989eca6 | 2019-03-14 14:19:08 | [diff] [blame] | 251 | COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}" |
Petr Hosek | 9e49a33 | 2016-08-08 22:57:25 | [diff] [blame] | 252 | LINK_FLAGS "${LIBCXX_LINK_FLAGS}" |
Martell Malone | 8fd2d37 | 2017-05-25 22:37:15 | [diff] [blame] | 253 | OUTPUT_NAME "c++" |
Petr Hosek | 9e49a33 | 2016-08-08 22:57:25 | [diff] [blame] | 254 | ) |
Louis Dionne | fadc84a | 2019-10-04 22:50:23 | [diff] [blame] | 255 | cxx_add_common_build_flags(cxx_static) |
Louis Dionne | 850a3d3 | 2019-03-14 14:52:26 | [diff] [blame] | 256 | cxx_set_common_defines(cxx_static) |
Louis Dionne | 989eca6 | 2019-03-14 14:19:08 | [diff] [blame] | 257 | |
| 258 | if (LIBCXX_HERMETIC_STATIC_LIBRARY) |
Petr Hosek | 741f52c | 2019-05-06 01:22:28 | [diff] [blame] | 259 | # If the hermetic library doesn't define the operator new/delete functions |
| 260 | # then its code shouldn't declare them with hidden visibility. They might |
| 261 | # actually be provided by a shared library at link time. |
| 262 | if (LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS) |
| 263 | append_flags_if_supported(CXX_STATIC_LIBRARY_FLAGS -fvisibility-global-new-delete-hidden) |
| 264 | endif() |
Louis Dionne | 989eca6 | 2019-03-14 14:19:08 | [diff] [blame] | 265 | target_compile_options(cxx_static PRIVATE ${CXX_STATIC_LIBRARY_FLAGS}) |
| 266 | target_compile_definitions(cxx_static PRIVATE _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) |
| 267 | endif() |
| 268 | |
Petr Hosek | 4a1e14e | 2018-07-24 23:27:51 | [diff] [blame] | 269 | list(APPEND LIBCXX_BUILD_TARGETS "cxx_static") |
Eric Fiselier | bf58c8e | 2016-11-18 19:53:45 | [diff] [blame] | 270 | # 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] | 271 | if (LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY) |
Eric Fiselier | bf58c8e | 2016-11-18 19:53:45 | [diff] [blame] | 272 | set(MERGE_ARCHIVES_SEARCH_PATHS "") |
| 273 | if (LIBCXX_CXX_ABI_LIBRARY_PATH) |
| 274 | set(MERGE_ARCHIVES_SEARCH_PATHS "-L${LIBCXX_CXX_ABI_LIBRARY_PATH}") |
| 275 | endif() |
Petr Hosek | 30d9af1 | 2019-04-03 01:33:14 | [diff] [blame] | 276 | if (TARGET "${LIBCXX_CXX_STATIC_ABI_LIBRARY}" OR HAVE_LIBCXXABI) |
| 277 | set(MERGE_ARCHIVES_ABI_TARGET "$<TARGET_LINKER_FILE:${LIBCXX_CXX_STATIC_ABI_LIBRARY}>") |
Eric Fiselier | bf58c8e | 2016-11-18 19:53:45 | [diff] [blame] | 278 | else() |
Saleem Abdulrasool | f1ae11a | 2017-01-04 05:49:57 | [diff] [blame] | 279 | set(MERGE_ARCHIVES_ABI_TARGET |
Petr Hosek | 30d9af1 | 2019-04-03 01:33:14 | [diff] [blame] | 280 | "${CMAKE_STATIC_LIBRARY_PREFIX}${LIBCXX_CXX_STATIC_ABI_LIBRARY}${CMAKE_STATIC_LIBRARY_SUFFIX}") |
Eric Fiselier | bf58c8e | 2016-11-18 19:53:45 | [diff] [blame] | 281 | endif() |
Petr Hosek | 737de4d | 2019-06-02 01:14:31 | [diff] [blame] | 282 | if (APPLE) |
| 283 | set(MERGE_ARCHIVES_LIBTOOL "--use-libtool" "--libtool" "${CMAKE_LIBTOOL}") |
| 284 | endif() |
Eric Fiselier | bf58c8e | 2016-11-18 19:53:45 | [diff] [blame] | 285 | add_custom_command(TARGET cxx_static POST_BUILD |
| 286 | COMMAND |
Saleem Abdulrasool | 88af3dd | 2020-04-28 19:50:12 | [diff] [blame] | 287 | ${Python3_EXECUTABLE} ${LIBCXX_SOURCE_DIR}/utils/merge_archives.py |
Eric Fiselier | bf58c8e | 2016-11-18 19:53:45 | [diff] [blame] | 288 | ARGS |
| 289 | -o $<TARGET_LINKER_FILE:cxx_static> |
Martin Storsjo | fb8eb6f | 2017-09-13 06:55:44 | [diff] [blame] | 290 | --ar "${CMAKE_AR}" |
Petr Hosek | 737de4d | 2019-06-02 01:14:31 | [diff] [blame] | 291 | ${MERGE_ARCHIVES_LIBTOOL} |
Eric Fiselier | bf58c8e | 2016-11-18 19:53:45 | [diff] [blame] | 292 | "$<TARGET_LINKER_FILE:cxx_static>" |
| 293 | "${MERGE_ARCHIVES_ABI_TARGET}" |
| 294 | "${MERGE_ARCHIVES_SEARCH_PATHS}" |
| 295 | WORKING_DIRECTORY ${LIBCXX_BUILD_DIR} |
| 296 | ) |
| 297 | endif() |
Petr Hosek | 9e49a33 | 2016-08-08 22:57:25 | [diff] [blame] | 298 | endif() |
| 299 | |
Eric Fiselier | 67ea02b | 2018-07-27 03:47:46 | [diff] [blame] | 300 | # Add a meta-target for both libraries. |
| 301 | add_custom_target(cxx DEPENDS cxx-headers ${LIBCXX_BUILD_TARGETS}) |
| 302 | |
Eric Fiselier | 27cb2f1 | 2016-05-03 21:30:18 | [diff] [blame] | 303 | if (LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY) |
Petr Hosek | f80c4b6 | 2019-05-01 06:40:36 | [diff] [blame] | 304 | set(LIBCXX_EXPERIMENTAL_SOURCES |
| 305 | experimental/memory_resource.cpp |
| 306 | ) |
Eric Fiselier | 998a5c8 | 2018-07-27 03:07:09 | [diff] [blame] | 307 | add_library(cxx_experimental STATIC ${LIBCXX_EXPERIMENTAL_SOURCES}) |
Petr Hosek | 9e49a33 | 2016-08-08 22:57:25 | [diff] [blame] | 308 | if (LIBCXX_ENABLE_SHARED) |
Louis Dionne | 3230087 | 2019-10-08 16:26:24 | [diff] [blame] | 309 | target_link_libraries(cxx_experimental PRIVATE cxx_shared) |
Petr Hosek | 9e49a33 | 2016-08-08 22:57:25 | [diff] [blame] | 310 | else() |
Louis Dionne | 3230087 | 2019-10-08 16:26:24 | [diff] [blame] | 311 | target_link_libraries(cxx_experimental PRIVATE cxx_static) |
Petr Hosek | 9e49a33 | 2016-08-08 22:57:25 | [diff] [blame] | 312 | endif() |
Eric Fiselier | a5e201f | 2016-05-10 16:17:43 | [diff] [blame] | 313 | |
Eric Fiselier | 27cb2f1 | 2016-05-03 21:30:18 | [diff] [blame] | 314 | set_target_properties(cxx_experimental |
| 315 | PROPERTIES |
Louis Dionne | fadc84a | 2019-10-04 22:50:23 | [diff] [blame] | 316 | COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}" |
Eric Fiselier | 27cb2f1 | 2016-05-03 21:30:18 | [diff] [blame] | 317 | OUTPUT_NAME "c++experimental" |
| 318 | ) |
Alex Langford | 9627b26 | 2019-10-04 23:08:20 | [diff] [blame] | 319 | cxx_add_common_build_flags(cxx_experimental) |
Eric Fiselier | 27cb2f1 | 2016-05-03 21:30:18 | [diff] [blame] | 320 | endif() |
Louis Dionne | fadc84a | 2019-10-04 22:50:23 | [diff] [blame] | 321 | |
Eric Fiselier | 27cb2f1 | 2016-05-03 21:30:18 | [diff] [blame] | 322 | |
Eric Fiselier | 00f6bea | 2017-01-06 20:05:40 | [diff] [blame] | 323 | if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY) |
Asiri Rathnayake | 8c2bf45 | 2016-09-11 21:46:40 | [diff] [blame] | 324 | file(GLOB LIBCXX_EXTERNAL_THREADING_SUPPORT_SOURCES ../test/support/external_threads.cpp) |
| 325 | |
| 326 | if (LIBCXX_ENABLE_SHARED) |
| 327 | add_library(cxx_external_threads SHARED ${LIBCXX_EXTERNAL_THREADING_SUPPORT_SOURCES}) |
| 328 | else() |
| 329 | add_library(cxx_external_threads STATIC ${LIBCXX_EXTERNAL_THREADING_SUPPORT_SOURCES}) |
| 330 | endif() |
| 331 | |
| 332 | set_target_properties(cxx_external_threads |
| 333 | PROPERTIES |
| 334 | LINK_FLAGS "${LIBCXX_LINK_FLAGS}" |
| 335 | COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}" |
| 336 | OUTPUT_NAME "c++external_threads" |
| 337 | ) |
| 338 | endif() |
| 339 | |
Eric Fiselier | d77135f | 2015-08-26 20:18:21 | [diff] [blame] | 340 | if (LIBCXX_INSTALL_LIBRARY) |
Saleem Abdulrasool | 97d6fcc | 2019-07-09 21:43:01 | [diff] [blame] | 341 | if (LIBCXX_INSTALL_SHARED_LIBRARY) |
| 342 | install(TARGETS cxx_shared |
| 343 | ARCHIVE DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx |
| 344 | LIBRARY DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx |
| 345 | RUNTIME DESTINATION ${LIBCXX_INSTALL_PREFIX}bin COMPONENT cxx) |
Eric Fiselier | 27cb2f1 | 2016-05-03 21:30:18 | [diff] [blame] | 346 | endif() |
Saleem Abdulrasool | 97d6fcc | 2019-07-09 21:43:01 | [diff] [blame] | 347 | |
| 348 | if (LIBCXX_INSTALL_STATIC_LIBRARY) |
| 349 | install(TARGETS cxx_static |
| 350 | ARCHIVE DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx |
| 351 | LIBRARY DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx |
| 352 | RUNTIME DESTINATION ${LIBCXX_INSTALL_PREFIX}bin COMPONENT cxx) |
| 353 | endif() |
| 354 | |
| 355 | if(LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY) |
Louis Dionne | ce36c5a | 2020-03-24 14:06:00 | [diff] [blame] | 356 | install(TARGETS cxx_experimental |
Saleem Abdulrasool | 97d6fcc | 2019-07-09 21:43:01 | [diff] [blame] | 357 | LIBRARY DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx |
| 358 | ARCHIVE DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx |
| 359 | RUNTIME DESTINATION ${LIBCXX_INSTALL_PREFIX}bin COMPONENT cxx) |
| 360 | endif() |
| 361 | |
Eric Fiselier | 8241405 | 2015-10-14 19:54:03 | [diff] [blame] | 362 | # NOTE: This install command must go after the cxx install command otherwise |
| 363 | # it will not be executed after the library symlinks are installed. |
Petr Hosek | 9e49a33 | 2016-08-08 22:57:25 | [diff] [blame] | 364 | if (LIBCXX_ENABLE_SHARED AND LIBCXX_ENABLE_ABI_LINKER_SCRIPT) |
Eric Fiselier | e2dd2fd | 2015-10-22 21:24:01 | [diff] [blame] | 365 | # Replace the libc++ filename with $<TARGET_LINKER_FILE:cxx> |
| 366 | # after we required CMake 3.0. |
Eric Fiselier | cae21e4 | 2015-10-23 07:04:24 | [diff] [blame] | 367 | install(FILES "${LIBCXX_LIBRARY_DIR}/libc++${CMAKE_SHARED_LIBRARY_SUFFIX}" |
Petr Hosek | 81f433b | 2019-05-22 21:08:33 | [diff] [blame] | 368 | DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} |
Eric Fiselier | 8241405 | 2015-10-14 19:54:03 | [diff] [blame] | 369 | COMPONENT libcxx) |
| 370 | endif() |
Eric Fiselier | d77135f | 2015-08-26 20:18:21 | [diff] [blame] | 371 | endif() |
Eric Fiselier | 7cb813f | 2015-08-19 17:41:53 | [diff] [blame] | 372 | |
Eric Fiselier | d77135f | 2015-08-26 20:18:21 | [diff] [blame] | 373 | if (NOT CMAKE_CONFIGURATION_TYPES AND (LIBCXX_INSTALL_LIBRARY OR |
| 374 | LIBCXX_INSTALL_HEADERS)) |
Chris Bieneman | a1b79ae | 2015-12-03 18:52:54 | [diff] [blame] | 375 | if(LIBCXX_INSTALL_LIBRARY) |
Eric Fiselier | 59e9748 | 2016-05-03 05:34:38 | [diff] [blame] | 376 | set(lib_install_target cxx) |
Chris Bieneman | a1b79ae | 2015-12-03 18:52:54 | [diff] [blame] | 377 | endif() |
Eric Fiselier | 27cb2f1 | 2016-05-03 21:30:18 | [diff] [blame] | 378 | if (LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY) |
| 379 | set(experimental_lib_install_target cxx_experimental) |
| 380 | endif() |
Chris Bieneman | 4497e3a | 2016-04-29 22:17:15 | [diff] [blame] | 381 | if(LIBCXX_INSTALL_HEADERS) |
Chris Bieneman | f17227a | 2016-08-24 22:17:06 | [diff] [blame] | 382 | set(header_install_target install-cxx-headers) |
Chris Bieneman | 4497e3a | 2016-04-29 22:17:15 | [diff] [blame] | 383 | endif() |
Louis Dionne | 512c903 | 2020-07-08 19:00:31 | [diff] [blame^] | 384 | if (LIBCXX_ENABLE_PARALLEL_ALGORITHMS) |
| 385 | set(pstl_install_target install-pstl) |
| 386 | endif() |
Chris Bieneman | f17227a | 2016-08-24 22:17:06 | [diff] [blame] | 387 | add_custom_target(install-cxx |
Eric Fiselier | 27cb2f1 | 2016-05-03 21:30:18 | [diff] [blame] | 388 | DEPENDS ${lib_install_target} |
| 389 | ${experimental_lib_install_target} |
| 390 | ${header_install_target} |
Louis Dionne | 512c903 | 2020-07-08 19:00:31 | [diff] [blame^] | 391 | ${pstl_install_target} |
Eric Fiselier | d77135f | 2015-08-26 20:18:21 | [diff] [blame] | 392 | COMMAND "${CMAKE_COMMAND}" |
Chris Bieneman | f17227a | 2016-08-24 22:17:06 | [diff] [blame] | 393 | -DCMAKE_INSTALL_COMPONENT=cxx |
Eric Fiselier | d77135f | 2015-08-26 20:18:21 | [diff] [blame] | 394 | -P "${LIBCXX_BINARY_DIR}/cmake_install.cmake") |
Shoaib Meenai | f7c7944 | 2017-12-06 21:03:42 | [diff] [blame] | 395 | add_custom_target(install-cxx-stripped |
| 396 | DEPENDS ${lib_install_target} |
| 397 | ${experimental_lib_install_target} |
| 398 | ${header_install_target} |
Louis Dionne | 512c903 | 2020-07-08 19:00:31 | [diff] [blame^] | 399 | ${pstl_install_target} |
Shoaib Meenai | f7c7944 | 2017-12-06 21:03:42 | [diff] [blame] | 400 | COMMAND "${CMAKE_COMMAND}" |
| 401 | -DCMAKE_INSTALL_COMPONENT=cxx |
| 402 | -DCMAKE_INSTALL_DO_STRIP=1 |
| 403 | -P "${LIBCXX_BINARY_DIR}/cmake_install.cmake") |
Eric Fiselier | 7cb813f | 2015-08-19 17:41:53 | [diff] [blame] | 404 | endif() |