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