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 |
Eric Fiselier | 6af1b7d | 2017-06-15 01:53:12 | [diff] [blame] | 4 | # FIXME: Don't use glob here |
Howard Hinnant | b2f52bb | 2012-03-19 15:40:23 | [diff] [blame] | 5 | file(GLOB LIBCXX_SOURCES ../src/*.cpp) |
Howard Hinnant | 3c78ca0 | 2011-09-22 19:10:18 | [diff] [blame] | 6 | if(WIN32) |
Howard Hinnant | b2f52bb | 2012-03-19 15:40:23 | [diff] [blame] | 7 | file(GLOB LIBCXX_WIN32_SOURCES ../src/support/win32/*.cpp) |
| 8 | list(APPEND LIBCXX_SOURCES ${LIBCXX_WIN32_SOURCES}) |
Eric Fiselier | 53deb60 | 2014-11-25 21:57:41 | [diff] [blame] | 9 | elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "SunOS") |
Michal Gorny | ef634ec | 2016-10-18 16:54:59 | [diff] [blame] | 10 | file(GLOB LIBCXX_SOLARIS_SOURCES ../src/support/solaris/*.cpp) |
Eric Fiselier | 53deb60 | 2014-11-25 21:57:41 | [diff] [blame] | 11 | list(APPEND LIBCXX_SOURCES ${LIBCXX_SOLARIS_SOURCES}) |
Howard Hinnant | 3c78ca0 | 2011-09-22 19:10:18 | [diff] [blame] | 12 | endif() |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 13 | |
| 14 | # Add all the headers to the project for IDEs. |
Eric Fiselier | 6627c70 | 2015-12-16 23:41:05 | [diff] [blame] | 15 | if (LIBCXX_CONFIGURE_IDE) |
Howard Hinnant | b2f52bb | 2012-03-19 15:40:23 | [diff] [blame] | 16 | file(GLOB_RECURSE LIBCXX_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../include/*) |
Howard Hinnant | 3c78ca0 | 2011-09-22 19:10:18 | [diff] [blame] | 17 | if(WIN32) |
Howard Hinnant | b2f52bb | 2012-03-19 15:40:23 | [diff] [blame] | 18 | file( GLOB LIBCXX_WIN32_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../include/support/win32/*.h) |
| 19 | list(APPEND LIBCXX_HEADERS ${LIBCXX_WIN32_HEADERS}) |
Howard Hinnant | 3c78ca0 | 2011-09-22 19:10:18 | [diff] [blame] | 20 | endif() |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 21 | # Force them all into the headers dir on MSVC, otherwise they end up at |
| 22 | # project scope because they don't have extensions. |
| 23 | if (MSVC_IDE) |
Howard Hinnant | b2f52bb | 2012-03-19 15:40:23 | [diff] [blame] | 24 | source_group("Header Files" FILES ${LIBCXX_HEADERS}) |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 25 | endif() |
| 26 | endif() |
| 27 | |
Chris Bieneman | a1b79ae | 2015-12-03 18:52:54 | [diff] [blame] | 28 | if(NOT LIBCXX_INSTALL_LIBRARY) |
| 29 | set(exclude_from_all EXCLUDE_FROM_ALL) |
| 30 | endif() |
| 31 | |
Saleem Abdulrasool | 99c19ad | 2017-01-04 05:49:55 | [diff] [blame] | 32 | # If LIBCXX_CXX_ABI_LIBRARY_PATH is defined we want to add it to the search path. |
| 33 | add_link_flags_if(LIBCXX_CXX_ABI_LIBRARY_PATH |
| 34 | "${CMAKE_LIBRARY_PATH_FLAG}${LIBCXX_CXX_ABI_LIBRARY_PATH}") |
Eric Fiselier | 0357171 | 2015-03-03 15:59:51 | [diff] [blame] | 35 | |
Eric Fiselier | 2aeac46 | 2017-03-11 03:24:18 | [diff] [blame] | 36 | |
| 37 | if (LIBCXX_GENERATE_COVERAGE AND NOT LIBCXX_COVERAGE_LIBRARY) |
| 38 | find_compiler_rt_library(profile LIBCXX_COVERAGE_LIBRARY) |
| 39 | endif() |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 40 | add_library_flags_if(LIBCXX_COVERAGE_LIBRARY "${LIBCXX_COVERAGE_LIBRARY}") |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 41 | |
Eric Fiselier | 054fc4c | 2016-10-09 21:34:03 | [diff] [blame] | 42 | if (APPLE AND (LIBCXX_CXX_ABI_LIBNAME STREQUAL "libcxxabi" OR |
Eric Fiselier | 1285e4d | 2017-01-03 01:18:48 | [diff] [blame] | 43 | LIBCXX_CXX_ABI_LIBNAME STREQUAL "default")) |
Louis Dionne | 3aeeaff | 2018-11-27 20:59:47 | [diff] [blame] | 44 | set(LIBCXX_OSX_REEXPORT_LIBCXXABI_SYMBOLS ON) |
Eric Fiselier | 054fc4c | 2016-10-09 21:34:03 | [diff] [blame] | 45 | endif() |
| 46 | |
Petr Hosek | 058c04c | 2018-07-24 07:06:17 | [diff] [blame] | 47 | if (LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY) |
Michal Gorny | 2433b26 | 2016-10-08 10:27:45 | [diff] [blame] | 48 | add_library_flags("-Wl,--whole-archive" "-Wl,-Bstatic") |
| 49 | add_library_flags("${LIBCXX_CXX_ABI_LIBRARY}") |
| 50 | add_library_flags("-Wl,-Bdynamic" "-Wl,--no-whole-archive") |
Louis Dionne | 3aeeaff | 2018-11-27 20:59:47 | [diff] [blame] | 51 | elseif (LIBCXX_OSX_REEXPORT_LIBCXXABI_SYMBOLS) |
Michal Gorny | 2433b26 | 2016-10-08 10:27:45 | [diff] [blame] | 52 | add_library_flags("${LIBCXX_CXX_ABI_LIBRARY}") |
Eric Fiselier | 054fc4c | 2016-10-09 21:34:03 | [diff] [blame] | 53 | else () |
| 54 | add_interface_library("${LIBCXX_CXX_ABI_LIBRARY}") |
Michal Gorny | 2433b26 | 2016-10-08 10:27:45 | [diff] [blame] | 55 | endif() |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 56 | |
Eric Fiselier | d1bac4c | 2015-07-22 00:33:36 | [diff] [blame] | 57 | if (APPLE AND LLVM_USE_SANITIZER) |
Kuba Brecka | 50bc34ca31 | 2016-09-15 11:04:53 | [diff] [blame] | 58 | if (("${LLVM_USE_SANITIZER}" STREQUAL "Address") OR |
| 59 | ("${LLVM_USE_SANITIZER}" STREQUAL "Address;Undefined") OR |
| 60 | ("${LLVM_USE_SANITIZER}" STREQUAL "Undefined;Address")) |
Eric Fiselier | d1bac4c | 2015-07-22 00:33:36 | [diff] [blame] | 61 | set(LIBFILE "libclang_rt.asan_osx_dynamic.dylib") |
| 62 | elseif("${LLVM_USE_SANITIZER}" STREQUAL "Undefined") |
| 63 | set(LIBFILE "libclang_rt.ubsan_osx_dynamic.dylib") |
Kuba Brecka | d634df5 | 2016-09-14 14:12:50 | [diff] [blame] | 64 | elseif("${LLVM_USE_SANITIZER}" STREQUAL "Thread") |
| 65 | set(LIBFILE "libclang_rt.tsan_osx_dynamic.dylib") |
Eric Fiselier | d1bac4c | 2015-07-22 00:33:36 | [diff] [blame] | 66 | else() |
| 67 | message(WARNING "LLVM_USE_SANITIZER=${LLVM_USE_SANITIZER} is not supported on OS X") |
| 68 | endif() |
| 69 | if (LIBFILE) |
Eric Fiselier | 2aeac46 | 2017-03-11 03:24:18 | [diff] [blame] | 70 | find_compiler_rt_dir(LIBDIR) |
Eric Fiselier | d1bac4c | 2015-07-22 00:33:36 | [diff] [blame] | 71 | if (NOT IS_DIRECTORY "${LIBDIR}") |
| 72 | message(FATAL_ERROR "Cannot find compiler-rt directory on OS X required for LLVM_USE_SANITIZER") |
| 73 | endif() |
| 74 | set(LIBCXX_SANITIZER_LIBRARY "${LIBDIR}/${LIBFILE}") |
| 75 | set(LIBCXX_SANITIZER_LIBRARY "${LIBCXX_SANITIZER_LIBRARY}" PARENT_SCOPE) |
| 76 | message(STATUS "Manually linking compiler-rt library: ${LIBCXX_SANITIZER_LIBRARY}") |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 77 | add_library_flags("${LIBCXX_SANITIZER_LIBRARY}") |
| 78 | add_link_flags("-Wl,-rpath,${LIBDIR}") |
Eric Fiselier | d1bac4c | 2015-07-22 00:33:36 | [diff] [blame] | 79 | endif() |
| 80 | endif() |
| 81 | |
Michal Gorny | 2433b26 | 2016-10-08 10:27:45 | [diff] [blame] | 82 | # Generate private library list. |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 83 | add_library_flags_if(LIBCXX_HAS_PTHREAD_LIB pthread) |
| 84 | add_library_flags_if(LIBCXX_HAS_C_LIB c) |
| 85 | add_library_flags_if(LIBCXX_HAS_M_LIB m) |
| 86 | add_library_flags_if(LIBCXX_HAS_RT_LIB rt) |
Petr Hosek | 963bcd2 | 2017-04-05 22:53:05 | [diff] [blame] | 87 | if (LIBCXX_USE_COMPILER_RT) |
| 88 | find_compiler_rt_library(builtins LIBCXX_BUILTINS_LIBRARY) |
| 89 | add_library_flags_if(LIBCXX_BUILTINS_LIBRARY "${LIBCXX_BUILTINS_LIBRARY}") |
| 90 | else() |
| 91 | add_library_flags_if(LIBCXX_HAS_GCC_S_LIB gcc_s) |
| 92 | endif() |
Eric Fiselier | a23470e | 2016-07-18 06:01:50 | [diff] [blame] | 93 | add_library_flags_if(LIBCXX_HAVE_CXX_ATOMICS_WITH_LIB atomic) |
Martin Storsjo | 783d433 | 2017-09-04 19:46:53 | [diff] [blame] | 94 | add_library_flags_if(MINGW "${MINGW_LIBRARIES}") |
Eric Fiselier | 78fdf2d | 2015-03-31 04:15:45 | [diff] [blame] | 95 | |
Michal Gorny | 2433b26 | 2016-10-08 10:27:45 | [diff] [blame] | 96 | # Add the unwinder library. |
| 97 | if (LIBCXXABI_USE_LLVM_UNWINDER) |
Petr Hosek | b494288 | 2017-02-09 02:19:43 | [diff] [blame] | 98 | if (NOT LIBCXXABI_ENABLE_STATIC_UNWINDER AND (TARGET unwind_shared OR HAVE_LIBUNWIND)) |
Eric Fiselier | 054fc4c | 2016-10-09 21:34:03 | [diff] [blame] | 99 | add_interface_library(unwind_shared) |
Petr Hosek | b494288 | 2017-02-09 02:19:43 | [diff] [blame] | 100 | elseif (LIBCXXABI_ENABLE_STATIC_UNWINDER AND (TARGET unwind_static OR HAVE_LIBUNWIND)) |
Eric Fiselier | 054fc4c | 2016-10-09 21:34:03 | [diff] [blame] | 101 | add_interface_library(unwind_static) |
| 102 | else() |
| 103 | add_interface_library(unwind) |
| 104 | endif() |
Michal Gorny | 2433b26 | 2016-10-08 10:27:45 | [diff] [blame] | 105 | endif() |
| 106 | |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 107 | # Setup flags. |
Saleem Abdulrasool | 394d351 | 2016-09-01 20:49:54 | [diff] [blame] | 108 | if (NOT WIN32) |
| 109 | add_flags_if_supported(-fPIC) |
| 110 | endif() |
Eric Fiselier | 7e3ee09 | 2017-01-14 07:54:39 | [diff] [blame] | 111 | |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 112 | add_link_flags_if_supported(-nodefaultlibs) |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 113 | |
Eric Fiselier | cc1f65c | 2017-01-14 06:06:47 | [diff] [blame] | 114 | if (LIBCXX_TARGETING_MSVC) |
Eric Fiselier | 7e3ee09 | 2017-01-14 07:54:39 | [diff] [blame] | 115 | if (LIBCXX_DEBUG_BUILD) |
| 116 | set(LIB_SUFFIX "d") |
| 117 | else() |
| 118 | set(LIB_SUFFIX "") |
| 119 | endif() |
Eric Fiselier | cc1f65c | 2017-01-14 06:06:47 | [diff] [blame] | 120 | add_compile_flags(/Zl) |
| 121 | add_link_flags(/nodefaultlib) |
Eric Fiselier | 7e3ee09 | 2017-01-14 07:54:39 | [diff] [blame] | 122 | |
| 123 | add_library_flags(ucrt${LIB_SUFFIX}) # Universal C runtime |
| 124 | add_library_flags(vcruntime${LIB_SUFFIX}) # C++ runtime |
| 125 | add_library_flags(msvcrt${LIB_SUFFIX}) # C runtime startup files |
Eric Fiselier | 3e254a6 | 2017-05-08 01:17:50 | [diff] [blame] | 126 | add_library_flags(msvcprt${LIB_SUFFIX}) # C++ standard library. Required for exception_ptr internals. |
Eric Fiselier | cc1f65c | 2017-01-14 06:06:47 | [diff] [blame] | 127 | # Required for standards-complaint wide character formatting functions |
| 128 | # (e.g. `printfw`/`scanfw`) |
| 129 | add_library_flags(iso_stdio_wide_specifiers) |
| 130 | endif() |
| 131 | |
Louis Dionne | 3aeeaff | 2018-11-27 20:59:47 | [diff] [blame] | 132 | if (LIBCXX_OSX_REEXPORT_LIBCXXABI_SYMBOLS) |
Eric Fiselier | d2852b6 | 2015-02-21 02:26:24 | [diff] [blame] | 133 | if (NOT DEFINED LIBCXX_LIBCPPABI_VERSION) |
Eric Fiselier | a0dd664 | 2016-06-14 21:55:14 | [diff] [blame] | 134 | set(LIBCXX_LIBCPPABI_VERSION "2") # Default value |
| 135 | execute_process( |
| 136 | COMMAND xcrun --show-sdk-version |
| 137 | OUTPUT_VARIABLE sdk_ver |
| 138 | RESULT_VARIABLE res |
| 139 | OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 140 | if (res EQUAL 0) |
| 141 | message(STATUS "Found SDK version ${sdk_ver}") |
| 142 | string(REPLACE "10." "" sdk_ver "${sdk_ver}") |
| 143 | if (sdk_ver LESS 9) |
| 144 | set(LIBCXX_LIBCPPABI_VERSION "") |
| 145 | else() |
| 146 | set(LIBCXX_LIBCPPABI_VERSION "2") |
| 147 | endif() |
| 148 | endif() |
Eric Fiselier | d2852b6 | 2015-02-21 02:26:24 | [diff] [blame] | 149 | endif() |
| 150 | |
Michael Gottesman | 05c4b55 | 2013-09-02 07:28:03 | [diff] [blame] | 151 | if ( CMAKE_OSX_DEPLOYMENT_TARGET STREQUAL "10.6" ) |
Louis Dionne | 950b8e1 | 2018-10-16 00:31:32 | [diff] [blame] | 152 | message(FATAL_ERROR "Mac OSX 10.6 is not supported anymore as a deployment " |
| 153 | "target. If you need support for this, please contact " |
| 154 | "the libc++ maintainers.") |
Michael Gottesman | 05c4b55 | 2013-09-02 07:28:03 | [diff] [blame] | 155 | else() |
Louis Dionne | 3aeeaff | 2018-11-27 20:59:47 | [diff] [blame] | 156 | if ("armv7" IN_LIST CMAKE_OSX_ARCHITECTURES) |
| 157 | set(RE_EXPORT_LIST "${CMAKE_CURRENT_SOURCE_DIR}/libc++sjlj-abi.exp") |
Michael Gottesman | 05c4b55 | 2013-09-02 07:28:03 | [diff] [blame] | 158 | else() |
Louis Dionne | 3aeeaff | 2018-11-27 20:59:47 | [diff] [blame] | 159 | set(RE_EXPORT_LIST "${CMAKE_CURRENT_SOURCE_DIR}/libc++abi${LIBCXX_LIBCPPABI_VERSION}.exp") |
Michael Gottesman | 05c4b55 | 2013-09-02 07:28:03 | [diff] [blame] | 160 | endif() |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 161 | add_link_flags( |
Michael Gottesman | 05c4b55 | 2013-09-02 07:28:03 | [diff] [blame] | 162 | "-compatibility_version 1" |
| 163 | "-install_name /usr/lib/libc++.1.dylib" |
Louis Dionne | 1497359 | 2018-11-27 21:13:31 | [diff] [blame] | 164 | "-Wl,-unexported_symbols_list,\"${CMAKE_CURRENT_SOURCE_DIR}/libc++unexp.exp\"" |
| 165 | "-Wl,-reexported_symbols_list,\"${RE_EXPORT_LIST}\"" |
| 166 | "-Wl,-force_symbols_not_weak_list,\"${CMAKE_CURRENT_SOURCE_DIR}/notweak.exp\"" |
| 167 | "-Wl,-force_symbols_weak_list,\"${CMAKE_CURRENT_SOURCE_DIR}/weak.exp\"") |
Louis Dionne | 3aeeaff | 2018-11-27 20:59:47 | [diff] [blame] | 168 | |
| 169 | if (NOT LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS) |
Louis Dionne | 1497359 | 2018-11-27 21:13:31 | [diff] [blame] | 170 | add_link_flags("-Wl,-reexported_symbols_list,\"${CMAKE_CURRENT_SOURCE_DIR}/libc++abi-new-delete.exp\"") |
Louis Dionne | 3aeeaff | 2018-11-27 20:59:47 | [diff] [blame] | 171 | endif() |
Michael Gottesman | 05c4b55 | 2013-09-02 07:28:03 | [diff] [blame] | 172 | endif() |
| 173 | endif() |
| 174 | |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 175 | split_list(LIBCXX_COMPILE_FLAGS) |
| 176 | split_list(LIBCXX_LINK_FLAGS) |
Michael Gottesman | 05c4b55 | 2013-09-02 07:28:03 | [diff] [blame] | 177 | |
Petr Hosek | a2685cd | 2019-01-06 06:14:31 | [diff] [blame^] | 178 | macro(cxx_object_library name) |
| 179 | cmake_parse_arguments(ARGS "" "" "DEFINES;FLAGS" ${ARGN}) |
Petr Hosek | 9e49a33 | 2016-08-08 22:57:25 | [diff] [blame] | 180 | |
Petr Hosek | a2685cd | 2019-01-06 06:14:31 | [diff] [blame^] | 181 | # Add an object library that contains the compiled source files. |
| 182 | add_library(${name} OBJECT ${exclude_from_all} ${LIBCXX_SOURCES} ${LIBCXX_HEADERS}) |
| 183 | if(LIBCXX_CXX_ABI_HEADER_TARGET) |
| 184 | add_dependencies(${name} ${LIBCXX_CXX_ABI_HEADER_TARGET}) |
| 185 | endif() |
| 186 | if(WIN32 AND NOT MINGW) |
| 187 | target_compile_definitions(${name} |
| 188 | PRIVATE |
| 189 | # Ignore the -MSC_VER mismatch, as we may build |
| 190 | # with a different compatibility version. |
| 191 | _ALLOW_MSC_VER_MISMATCH |
| 192 | # Don't check the msvcprt iterator debug levels |
| 193 | # as we will define the iterator types; libc++ |
| 194 | # uses a different macro to identify the debug |
| 195 | # level. |
| 196 | _ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH |
| 197 | # We are building the c++ runtime, don't pull in |
| 198 | # msvcprt. |
| 199 | _CRTBLD |
| 200 | # Don't warn on the use of "deprecated" |
| 201 | # "insecure" functions which are standards |
| 202 | # specified. |
| 203 | _CRT_SECURE_NO_WARNINGS |
| 204 | # Use the ISO conforming behaviour for conversion |
| 205 | # in printf, scanf. |
| 206 | _CRT_STDIO_ISO_WIDE_SPECIFIERS) |
| 207 | endif() |
| 208 | |
| 209 | if(ARGS_DEFINES) |
| 210 | target_compile_definitions(${name} PRIVATE ${ARGS_DEFINES}) |
| 211 | endif() |
| 212 | |
| 213 | set_target_properties(${name} |
| 214 | PROPERTIES |
| 215 | COMPILE_FLAGS ${LIBCXX_COMPILE_FLAGS} |
| 216 | ) |
| 217 | |
| 218 | if(ARGS_FLAGS) |
| 219 | target_compile_options(${name} PRIVATE ${ARGS_FLAGS}) |
| 220 | endif() |
| 221 | endmacro() |
| 222 | |
| 223 | if(LIBCXX_HERMETIC_STATIC_LIBRARY) |
| 224 | append_flags_if_supported(CXX_STATIC_OBJECTS_FLAGS -fvisibility=hidden) |
| 225 | append_flags_if_supported(CXX_STATIC_OBJECTS_FLAGS -fvisibility-global-new-delete-hidden) |
| 226 | cxx_object_library(cxx_static_objects |
| 227 | DEFINES _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS |
| 228 | FLAGS ${CXX_STATIC_OBJECTS_FLAGS}) |
| 229 | cxx_object_library(cxx_shared_objects) |
| 230 | set(cxx_static_sources $<TARGET_OBJECTS:cxx_static_objects>) |
| 231 | set(cxx_shared_sources $<TARGET_OBJECTS:cxx_shared_objects>) |
| 232 | else() |
| 233 | cxx_object_library(cxx_objects) |
| 234 | set(cxx_static_sources $<TARGET_OBJECTS:cxx_objects>) |
| 235 | set(cxx_shared_sources $<TARGET_OBJECTS:cxx_objects>) |
| 236 | endif() |
Petr Hosek | 9e49a33 | 2016-08-08 22:57:25 | [diff] [blame] | 237 | |
Petr Hosek | 9e49a33 | 2016-08-08 22:57:25 | [diff] [blame] | 238 | # Build the shared library. |
| 239 | if (LIBCXX_ENABLE_SHARED) |
Petr Hosek | a2685cd | 2019-01-06 06:14:31 | [diff] [blame^] | 240 | add_library(cxx_shared SHARED ${cxx_shared_sources}) |
Don Hinton | 88434fe | 2018-01-27 18:55:30 | [diff] [blame] | 241 | if(COMMAND llvm_setup_rpath) |
Don Hinton | d21aeff | 2018-01-26 01:34:51 | [diff] [blame] | 242 | llvm_setup_rpath(cxx_shared) |
| 243 | endif() |
Eric Fiselier | 054fc4c | 2016-10-09 21:34:03 | [diff] [blame] | 244 | target_link_libraries(cxx_shared ${LIBCXX_LIBRARIES}) |
Petr Hosek | 9e49a33 | 2016-08-08 22:57:25 | [diff] [blame] | 245 | set_target_properties(cxx_shared |
| 246 | PROPERTIES |
| 247 | LINK_FLAGS "${LIBCXX_LINK_FLAGS}" |
| 248 | OUTPUT_NAME "c++" |
| 249 | VERSION "${LIBCXX_ABI_VERSION}.0" |
| 250 | SOVERSION "${LIBCXX_ABI_VERSION}" |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 251 | ) |
Petr Hosek | 4a1e14e | 2018-07-24 23:27:51 | [diff] [blame] | 252 | list(APPEND LIBCXX_BUILD_TARGETS "cxx_shared") |
| 253 | if (LIBCXX_INSTALL_SHARED_LIBRARY) |
| 254 | list(APPEND LIBCXX_INSTALL_TARGETS "cxx_shared") |
| 255 | endif() |
Saleem Abdulrasool | 2d2ed1c | 2017-01-02 21:09:19 | [diff] [blame] | 256 | if(WIN32 AND NOT MINGW AND NOT "${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows") |
| 257 | # Since we most likely do not have a mt.exe replacement, disable the |
| 258 | # manifest bundling. This allows a normal cmake invocation to pass which |
| 259 | # will attempt to use the manifest tool to generate the bundled manifest |
| 260 | set_target_properties(cxx_shared PROPERTIES |
| 261 | APPEND_STRING PROPERTY LINK_FLAGS " /MANIFEST:NO") |
| 262 | endif() |
Petr Hosek | 9e49a33 | 2016-08-08 22:57:25 | [diff] [blame] | 263 | endif() |
| 264 | |
| 265 | # Build the static library. |
| 266 | if (LIBCXX_ENABLE_STATIC) |
Petr Hosek | a2685cd | 2019-01-06 06:14:31 | [diff] [blame^] | 267 | add_library(cxx_static STATIC ${cxx_static_sources}) |
Eric Fiselier | 054fc4c | 2016-10-09 21:34:03 | [diff] [blame] | 268 | target_link_libraries(cxx_static ${LIBCXX_LIBRARIES}) |
Martell Malone | 8fd2d37 | 2017-05-25 22:37:15 | [diff] [blame] | 269 | set(CMAKE_STATIC_LIBRARY_PREFIX "lib") |
Petr Hosek | 9e49a33 | 2016-08-08 22:57:25 | [diff] [blame] | 270 | set_target_properties(cxx_static |
| 271 | PROPERTIES |
| 272 | LINK_FLAGS "${LIBCXX_LINK_FLAGS}" |
Martell Malone | 8fd2d37 | 2017-05-25 22:37:15 | [diff] [blame] | 273 | OUTPUT_NAME "c++" |
Petr Hosek | 9e49a33 | 2016-08-08 22:57:25 | [diff] [blame] | 274 | ) |
Petr Hosek | 4a1e14e | 2018-07-24 23:27:51 | [diff] [blame] | 275 | list(APPEND LIBCXX_BUILD_TARGETS "cxx_static") |
| 276 | if (LIBCXX_INSTALL_STATIC_LIBRARY) |
| 277 | list(APPEND LIBCXX_INSTALL_TARGETS "cxx_static") |
| 278 | endif() |
Eric Fiselier | bf58c8e | 2016-11-18 19:53:45 | [diff] [blame] | 279 | # 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] | 280 | if (LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY) |
Eric Fiselier | bf58c8e | 2016-11-18 19:53:45 | [diff] [blame] | 281 | set(MERGE_ARCHIVES_SEARCH_PATHS "") |
| 282 | if (LIBCXX_CXX_ABI_LIBRARY_PATH) |
| 283 | set(MERGE_ARCHIVES_SEARCH_PATHS "-L${LIBCXX_CXX_ABI_LIBRARY_PATH}") |
| 284 | endif() |
Petr Hosek | 06d3c51 | 2017-01-16 00:33:09 | [diff] [blame] | 285 | if ((TARGET ${LIBCXX_CXX_ABI_LIBRARY}) OR |
Leo Li | 95e45f9 | 2017-07-18 19:48:02 | [diff] [blame] | 286 | (${LIBCXX_CXX_ABI_LIBRARY} MATCHES "cxxabi(_static|_shared)?" AND HAVE_LIBCXXABI)) |
Petr Hosek | 058c04c | 2018-07-24 07:06:17 | [diff] [blame] | 287 | set(MERGE_ARCHIVES_ABI_TARGET "$<TARGET_LINKER_FILE:cxxabi_static>") |
Eric Fiselier | bf58c8e | 2016-11-18 19:53:45 | [diff] [blame] | 288 | else() |
Saleem Abdulrasool | f1ae11a | 2017-01-04 05:49:57 | [diff] [blame] | 289 | set(MERGE_ARCHIVES_ABI_TARGET |
| 290 | "${CMAKE_STATIC_LIBRARY_PREFIX}${LIBCXX_CXX_ABI_LIBRARY}${CMAKE_STATIC_LIBRARY_SUFFIX}") |
Eric Fiselier | bf58c8e | 2016-11-18 19:53:45 | [diff] [blame] | 291 | endif() |
| 292 | add_custom_command(TARGET cxx_static POST_BUILD |
| 293 | COMMAND |
| 294 | ${PYTHON_EXECUTABLE} ${LIBCXX_SOURCE_DIR}/utils/merge_archives.py |
| 295 | ARGS |
| 296 | -o $<TARGET_LINKER_FILE:cxx_static> |
Martin Storsjo | fb8eb6f | 2017-09-13 06:55:44 | [diff] [blame] | 297 | --ar "${CMAKE_AR}" |
Eric Fiselier | bf58c8e | 2016-11-18 19:53:45 | [diff] [blame] | 298 | "$<TARGET_LINKER_FILE:cxx_static>" |
| 299 | "${MERGE_ARCHIVES_ABI_TARGET}" |
| 300 | "${MERGE_ARCHIVES_SEARCH_PATHS}" |
| 301 | WORKING_DIRECTORY ${LIBCXX_BUILD_DIR} |
| 302 | ) |
| 303 | endif() |
Petr Hosek | 9e49a33 | 2016-08-08 22:57:25 | [diff] [blame] | 304 | endif() |
| 305 | |
Eric Fiselier | 67ea02b | 2018-07-27 03:47:46 | [diff] [blame] | 306 | # Add a meta-target for both libraries. |
| 307 | add_custom_target(cxx DEPENDS cxx-headers ${LIBCXX_BUILD_TARGETS}) |
| 308 | |
Eric Fiselier | 998a5c8 | 2018-07-27 03:07:09 | [diff] [blame] | 309 | if (LIBCXX_ENABLE_FILESYSTEM) |
| 310 | set(LIBCXX_FILESYSTEM_SOURCES |
| 311 | ../src/filesystem/operations.cpp |
| 312 | ../src/filesystem/directory_iterator.cpp) |
| 313 | |
| 314 | # Filesystem uses __int128_t, which requires a definition of __muloi4 when |
| 315 | # compiled with UBSAN. This definition is not provided by libgcc_s, but is |
| 316 | # provided by compiler-rt. So we need to disable it to avoid having multiple |
| 317 | # definitions. See filesystem/int128_builtins.cpp. |
| 318 | if (NOT LIBCXX_USE_COMPILER_RT) |
| 319 | list(APPEND LIBCXX_FILESYSTEM_SOURCES ../src/filesystem/int128_builtins.cpp) |
| 320 | endif() |
| 321 | |
| 322 | add_library(cxx_filesystem STATIC ${LIBCXX_FILESYSTEM_SOURCES}) |
| 323 | if (LIBCXX_ENABLE_SHARED) |
| 324 | target_link_libraries(cxx_filesystem cxx_shared) |
| 325 | else() |
| 326 | target_link_libraries(cxx_filesystem cxx_static) |
| 327 | endif() |
| 328 | |
| 329 | set(filesystem_flags "${LIBCXX_COMPILE_FLAGS}") |
| 330 | check_flag_supported(-std=c++14) |
| 331 | if (NOT MSVC AND LIBCXX_SUPPORTS_STD_EQ_CXX14_FLAG) |
| 332 | string(REPLACE "-std=c++11" "-std=c++14" filesystem_flags "${LIBCXX_COMPILE_FLAGS}") |
| 333 | endif() |
| 334 | set_target_properties(cxx_filesystem |
| 335 | PROPERTIES |
| 336 | COMPILE_FLAGS "${filesystem_flags}" |
| 337 | OUTPUT_NAME "c++fs" |
| 338 | ) |
| 339 | endif() |
| 340 | |
| 341 | |
Eric Fiselier | 27cb2f1 | 2016-05-03 21:30:18 | [diff] [blame] | 342 | if (LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY) |
| 343 | file(GLOB LIBCXX_EXPERIMENTAL_SOURCES ../src/experimental/*.cpp) |
Eric Fiselier | 998a5c8 | 2018-07-27 03:07:09 | [diff] [blame] | 344 | add_library(cxx_experimental STATIC ${LIBCXX_EXPERIMENTAL_SOURCES}) |
Petr Hosek | 9e49a33 | 2016-08-08 22:57:25 | [diff] [blame] | 345 | if (LIBCXX_ENABLE_SHARED) |
| 346 | target_link_libraries(cxx_experimental cxx_shared) |
| 347 | else() |
| 348 | target_link_libraries(cxx_experimental cxx_static) |
| 349 | endif() |
Eric Fiselier | a5e201f | 2016-05-10 16:17:43 | [diff] [blame] | 350 | |
| 351 | set(experimental_flags "${LIBCXX_COMPILE_FLAGS}") |
| 352 | check_flag_supported(-std=c++14) |
| 353 | if (NOT MSVC AND LIBCXX_SUPPORTS_STD_EQ_CXX14_FLAG) |
| 354 | string(REPLACE "-std=c++11" "-std=c++14" experimental_flags "${LIBCXX_COMPILE_FLAGS}") |
| 355 | endif() |
Eric Fiselier | 27cb2f1 | 2016-05-03 21:30:18 | [diff] [blame] | 356 | set_target_properties(cxx_experimental |
| 357 | PROPERTIES |
Eric Fiselier | a5e201f | 2016-05-10 16:17:43 | [diff] [blame] | 358 | COMPILE_FLAGS "${experimental_flags}" |
Eric Fiselier | 27cb2f1 | 2016-05-03 21:30:18 | [diff] [blame] | 359 | OUTPUT_NAME "c++experimental" |
| 360 | ) |
| 361 | endif() |
| 362 | |
Eric Fiselier | 00f6bea | 2017-01-06 20:05:40 | [diff] [blame] | 363 | if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY) |
Asiri Rathnayake | 8c2bf45 | 2016-09-11 21:46:40 | [diff] [blame] | 364 | file(GLOB LIBCXX_EXTERNAL_THREADING_SUPPORT_SOURCES ../test/support/external_threads.cpp) |
| 365 | |
| 366 | if (LIBCXX_ENABLE_SHARED) |
| 367 | add_library(cxx_external_threads SHARED ${LIBCXX_EXTERNAL_THREADING_SUPPORT_SOURCES}) |
| 368 | else() |
| 369 | add_library(cxx_external_threads STATIC ${LIBCXX_EXTERNAL_THREADING_SUPPORT_SOURCES}) |
| 370 | endif() |
| 371 | |
| 372 | set_target_properties(cxx_external_threads |
| 373 | PROPERTIES |
| 374 | LINK_FLAGS "${LIBCXX_LINK_FLAGS}" |
| 375 | COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}" |
| 376 | OUTPUT_NAME "c++external_threads" |
| 377 | ) |
| 378 | endif() |
| 379 | |
Eric Fiselier | 8241405 | 2015-10-14 19:54:03 | [diff] [blame] | 380 | # Generate a linker script inplace of a libc++.so symlink. Rerun this command |
| 381 | # after cxx builds. |
Petr Hosek | 9e49a33 | 2016-08-08 22:57:25 | [diff] [blame] | 382 | if (LIBCXX_ENABLE_SHARED AND LIBCXX_ENABLE_ABI_LINKER_SCRIPT) |
Eric Fiselier | 8241405 | 2015-10-14 19:54:03 | [diff] [blame] | 383 | # Get the name of the ABI library and handle the case where CXXABI_LIBNAME |
| 384 | # is a target name and not a library. Ex cxxabi_shared. |
Eric Fiselier | 054fc4c | 2016-10-09 21:34:03 | [diff] [blame] | 385 | set(LIBCXX_INTERFACE_LIBRARY_NAMES) |
| 386 | foreach(lib ${LIBCXX_INTERFACE_LIBRARIES}) |
| 387 | # FIXME: Handle cxxabi_static and unwind_static. |
Petr Hosek | 06d3c51 | 2017-01-16 00:33:09 | [diff] [blame] | 388 | if (TARGET ${lib} OR |
| 389 | (${lib} MATCHES "cxxabi(_static|_shared)?" AND HAVE_LIBCXXABI) OR |
| 390 | (${lib} MATCHES "unwind(_static|_shared)?" AND HAVE_LIBUNWIND)) |
Eric Fiselier | 054fc4c | 2016-10-09 21:34:03 | [diff] [blame] | 391 | list(APPEND LIBCXX_INTERFACE_LIBRARY_NAMES "$<TARGET_PROPERTY:${lib},OUTPUT_NAME>") |
Hal Finkel | 5b5f4f0 | 2016-10-09 02:49:31 | [diff] [blame] | 392 | else() |
Eric Fiselier | 054fc4c | 2016-10-09 21:34:03 | [diff] [blame] | 393 | list(APPEND LIBCXX_INTERFACE_LIBRARY_NAMES "${lib}") |
Hal Finkel | 5b5f4f0 | 2016-10-09 02:49:31 | [diff] [blame] | 394 | endif() |
| 395 | endforeach() |
Eric Fiselier | 054fc4c | 2016-10-09 21:34:03 | [diff] [blame] | 396 | #split_list(LIBCXX_INTERFACE_LIBRARY_NAMES) |
Eric Fiselier | 8241405 | 2015-10-14 19:54:03 | [diff] [blame] | 397 | # Generate a linker script inplace of a libc++.so symlink. Rerun this command |
| 398 | # after cxx builds. |
Petr Hosek | 9e49a33 | 2016-08-08 22:57:25 | [diff] [blame] | 399 | add_custom_command(TARGET cxx_shared POST_BUILD |
Eric Fiselier | 8241405 | 2015-10-14 19:54:03 | [diff] [blame] | 400 | COMMAND |
Eric Fiselier | 0b37f20 | 2017-02-09 22:53:14 | [diff] [blame] | 401 | ${PYTHON_EXECUTABLE} ${LIBCXX_SOURCE_DIR}/utils/gen_link_script.py |
Eric Fiselier | 8241405 | 2015-10-14 19:54:03 | [diff] [blame] | 402 | ARGS |
Petr Hosek | 9e49a33 | 2016-08-08 22:57:25 | [diff] [blame] | 403 | "$<TARGET_LINKER_FILE:cxx_shared>" |
Eric Fiselier | 054fc4c | 2016-10-09 21:34:03 | [diff] [blame] | 404 | ${LIBCXX_INTERFACE_LIBRARY_NAMES} |
Eric Fiselier | 8241405 | 2015-10-14 19:54:03 | [diff] [blame] | 405 | WORKING_DIRECTORY ${LIBCXX_BUILD_DIR} |
| 406 | ) |
| 407 | endif() |
| 408 | |
Eric Fiselier | d77135f | 2015-08-26 20:18:21 | [diff] [blame] | 409 | if (LIBCXX_INSTALL_LIBRARY) |
Eric Fiselier | 998a5c8 | 2018-07-27 03:07:09 | [diff] [blame] | 410 | if (LIBCXX_INSTALL_FILESYSTEM_LIBRARY) |
| 411 | set(filesystem_lib cxx_filesystem) |
| 412 | endif() |
Eric Fiselier | 27cb2f1 | 2016-05-03 21:30:18 | [diff] [blame] | 413 | if (LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY) |
| 414 | set(experimental_lib cxx_experimental) |
| 415 | endif() |
Eric Fiselier | 998a5c8 | 2018-07-27 03:07:09 | [diff] [blame] | 416 | install(TARGETS ${LIBCXX_INSTALL_TARGETS} ${filesystem_lib} ${experimental_lib} |
Petr Hosek | 510e70f | 2017-07-11 02:39:50 | [diff] [blame] | 417 | LIBRARY DESTINATION ${LIBCXX_INSTALL_PREFIX}lib${LIBCXX_LIBDIR_SUFFIX} COMPONENT cxx |
| 418 | ARCHIVE DESTINATION ${LIBCXX_INSTALL_PREFIX}lib${LIBCXX_LIBDIR_SUFFIX} COMPONENT cxx |
Eric Fiselier | d77135f | 2015-08-26 20:18:21 | [diff] [blame] | 419 | ) |
Eric Fiselier | 8241405 | 2015-10-14 19:54:03 | [diff] [blame] | 420 | # NOTE: This install command must go after the cxx install command otherwise |
| 421 | # it will not be executed after the library symlinks are installed. |
Petr Hosek | 9e49a33 | 2016-08-08 22:57:25 | [diff] [blame] | 422 | if (LIBCXX_ENABLE_SHARED AND LIBCXX_ENABLE_ABI_LINKER_SCRIPT) |
Eric Fiselier | e2dd2fd | 2015-10-22 21:24:01 | [diff] [blame] | 423 | # Replace the libc++ filename with $<TARGET_LINKER_FILE:cxx> |
| 424 | # after we required CMake 3.0. |
Eric Fiselier | cae21e4 | 2015-10-23 07:04:24 | [diff] [blame] | 425 | install(FILES "${LIBCXX_LIBRARY_DIR}/libc++${CMAKE_SHARED_LIBRARY_SUFFIX}" |
Petr Hosek | 510e70f | 2017-07-11 02:39:50 | [diff] [blame] | 426 | DESTINATION ${LIBCXX_INSTALL_PREFIX}lib${LIBCXX_LIBDIR_SUFFIX} |
Eric Fiselier | 8241405 | 2015-10-14 19:54:03 | [diff] [blame] | 427 | COMPONENT libcxx) |
| 428 | endif() |
Eric Fiselier | d77135f | 2015-08-26 20:18:21 | [diff] [blame] | 429 | endif() |
Eric Fiselier | 7cb813f | 2015-08-19 17:41:53 | [diff] [blame] | 430 | |
Eric Fiselier | d77135f | 2015-08-26 20:18:21 | [diff] [blame] | 431 | if (NOT CMAKE_CONFIGURATION_TYPES AND (LIBCXX_INSTALL_LIBRARY OR |
| 432 | LIBCXX_INSTALL_HEADERS)) |
Chris Bieneman | a1b79ae | 2015-12-03 18:52:54 | [diff] [blame] | 433 | if(LIBCXX_INSTALL_LIBRARY) |
Eric Fiselier | 59e9748 | 2016-05-03 05:34:38 | [diff] [blame] | 434 | set(lib_install_target cxx) |
Chris Bieneman | a1b79ae | 2015-12-03 18:52:54 | [diff] [blame] | 435 | endif() |
Eric Fiselier | 998a5c8 | 2018-07-27 03:07:09 | [diff] [blame] | 436 | if (LIBCXX_INSTALL_FILESYSTEM_LIBRARY) |
| 437 | set(filesystem_lib_install_target cxx_filesystem) |
| 438 | endif() |
Eric Fiselier | 27cb2f1 | 2016-05-03 21:30:18 | [diff] [blame] | 439 | if (LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY) |
| 440 | set(experimental_lib_install_target cxx_experimental) |
| 441 | endif() |
Chris Bieneman | 4497e3a | 2016-04-29 22:17:15 | [diff] [blame] | 442 | if(LIBCXX_INSTALL_HEADERS) |
Chris Bieneman | f17227a | 2016-08-24 22:17:06 | [diff] [blame] | 443 | set(header_install_target install-cxx-headers) |
Chris Bieneman | 4497e3a | 2016-04-29 22:17:15 | [diff] [blame] | 444 | endif() |
Chris Bieneman | f17227a | 2016-08-24 22:17:06 | [diff] [blame] | 445 | add_custom_target(install-cxx |
Eric Fiselier | 27cb2f1 | 2016-05-03 21:30:18 | [diff] [blame] | 446 | DEPENDS ${lib_install_target} |
| 447 | ${experimental_lib_install_target} |
Eric Fiselier | 998a5c8 | 2018-07-27 03:07:09 | [diff] [blame] | 448 | ${filesystem_lib_install_target} |
Eric Fiselier | 27cb2f1 | 2016-05-03 21:30:18 | [diff] [blame] | 449 | ${header_install_target} |
Eric Fiselier | d77135f | 2015-08-26 20:18:21 | [diff] [blame] | 450 | COMMAND "${CMAKE_COMMAND}" |
Chris Bieneman | f17227a | 2016-08-24 22:17:06 | [diff] [blame] | 451 | -DCMAKE_INSTALL_COMPONENT=cxx |
Eric Fiselier | d77135f | 2015-08-26 20:18:21 | [diff] [blame] | 452 | -P "${LIBCXX_BINARY_DIR}/cmake_install.cmake") |
Shoaib Meenai | f7c7944 | 2017-12-06 21:03:42 | [diff] [blame] | 453 | add_custom_target(install-cxx-stripped |
| 454 | DEPENDS ${lib_install_target} |
| 455 | ${experimental_lib_install_target} |
Eric Fiselier | 998a5c8 | 2018-07-27 03:07:09 | [diff] [blame] | 456 | ${filesystem_lib_install_target} |
Shoaib Meenai | f7c7944 | 2017-12-06 21:03:42 | [diff] [blame] | 457 | ${header_install_target} |
| 458 | COMMAND "${CMAKE_COMMAND}" |
| 459 | -DCMAKE_INSTALL_COMPONENT=cxx |
| 460 | -DCMAKE_INSTALL_DO_STRIP=1 |
| 461 | -P "${LIBCXX_BINARY_DIR}/cmake_install.cmake") |
Chris Bieneman | f17227a | 2016-08-24 22:17:06 | [diff] [blame] | 462 | add_custom_target(install-libcxx DEPENDS install-cxx) |
Eric Fiselier | 7cb813f | 2015-08-19 17:41:53 | [diff] [blame] | 463 | endif() |