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") |
| 9 | file(GLOB LIBCXX_SOLARIS_SOURCES ../src/support/solaris/*.c) |
| 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. |
| 14 | if (MSVC_IDE OR XCODE) |
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 | |
| 27 | if (LIBCXX_ENABLE_SHARED) |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 28 | add_library(cxx SHARED ${LIBCXX_SOURCES} ${LIBCXX_HEADERS}) |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 29 | else() |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 30 | add_library(cxx STATIC ${LIBCXX_SOURCES} ${LIBCXX_HEADERS}) |
Eric Fiselier | 0357171 | 2015-03-03 15:59:51 | [diff] [blame] | 31 | endif() |
| 32 | |
Michael J. Spencer | bb8cfd0 | 2012-12-31 19:34:21 | [diff] [blame] | 33 | if (DEFINED LIBCXX_CXX_ABI_DEPS) |
David Fang | ed7987d | 2014-06-24 20:32:11 | [diff] [blame] | 34 | add_dependencies(cxx LIBCXX_CXX_ABI_DEPS) |
Michael J. Spencer | bb8cfd0 | 2012-12-31 19:34:21 | [diff] [blame] | 35 | endif() |
Michael J. Spencer | 299fc29a | 2012-11-30 21:02:29 | [diff] [blame] | 36 | |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 37 | #if LIBCXX_CXX_ABI_LIBRARY_PATH is defined we want to add it to the search path. |
| 38 | add_link_flags_if(LIBCXX_CXX_ABI_LIBRARY_PATH "-L${LIBCXX_CXX_ABI_LIBRARY_PATH}") |
Eric Fiselier | 0357171 | 2015-03-03 15:59:51 | [diff] [blame] | 39 | |
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 | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 42 | add_library_flags_if(LIBCXX_ENABLE_STATIC_ABI_LIBRARY "-Wl,--whole-archive" "-Wl,-Bstatic") |
| 43 | add_library_flags("${LIBCXX_CXX_ABI_LIBRARY}") |
| 44 | add_library_flags_if(LIBCXX_ENABLE_STATIC_ABI_LIBRARY "-Wl,-Bdynamic" "-Wl,--no-whole-archive") |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 45 | |
Eric Fiselier | d1bac4c | 2015-07-22 00:33:36 | [diff] [blame] | 46 | if (APPLE AND LLVM_USE_SANITIZER) |
| 47 | if ("${LLVM_USE_SANITIZER}" STREQUAL "Address") |
| 48 | set(LIBFILE "libclang_rt.asan_osx_dynamic.dylib") |
| 49 | elseif("${LLVM_USE_SANITIZER}" STREQUAL "Undefined") |
| 50 | set(LIBFILE "libclang_rt.ubsan_osx_dynamic.dylib") |
| 51 | else() |
| 52 | message(WARNING "LLVM_USE_SANITIZER=${LLVM_USE_SANITIZER} is not supported on OS X") |
| 53 | endif() |
| 54 | if (LIBFILE) |
| 55 | execute_process(COMMAND ${CMAKE_CXX_COMPILER} -print-file-name=lib OUTPUT_VARIABLE LIBDIR RESULT_VARIABLE Result) |
| 56 | if (NOT ${Result} EQUAL "0") |
| 57 | message(FATAL "Failed to find library resource directory") |
| 58 | endif() |
| 59 | string(STRIP "${LIBDIR}" LIBDIR) |
| 60 | set(LIBDIR "${LIBDIR}/darwin/") |
| 61 | if (NOT IS_DIRECTORY "${LIBDIR}") |
| 62 | message(FATAL_ERROR "Cannot find compiler-rt directory on OS X required for LLVM_USE_SANITIZER") |
| 63 | endif() |
| 64 | set(LIBCXX_SANITIZER_LIBRARY "${LIBDIR}/${LIBFILE}") |
| 65 | set(LIBCXX_SANITIZER_LIBRARY "${LIBCXX_SANITIZER_LIBRARY}" PARENT_SCOPE) |
| 66 | message(STATUS "Manually linking compiler-rt library: ${LIBCXX_SANITIZER_LIBRARY}") |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 67 | add_library_flags("${LIBCXX_SANITIZER_LIBRARY}") |
| 68 | add_link_flags("-Wl,-rpath,${LIBDIR}") |
Eric Fiselier | d1bac4c | 2015-07-22 00:33:36 | [diff] [blame] | 69 | endif() |
| 70 | endif() |
| 71 | |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 72 | # Generate library list. |
| 73 | add_library_flags_if(LIBCXX_HAS_PTHREAD_LIB pthread) |
| 74 | add_library_flags_if(LIBCXX_HAS_C_LIB c) |
| 75 | add_library_flags_if(LIBCXX_HAS_M_LIB m) |
| 76 | add_library_flags_if(LIBCXX_HAS_RT_LIB rt) |
| 77 | add_library_flags_if(LIBCXX_HAS_GCC_S_LIB gcc_s) |
Eric Fiselier | 78fdf2d | 2015-03-31 04:15:45 | [diff] [blame] | 78 | |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 79 | # Setup flags. |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 80 | add_flags_if_supported(-fPIC) |
| 81 | add_link_flags_if_supported(-nodefaultlibs) |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 82 | |
Eric Fiselier | e035c7c | 2015-03-27 09:00:45 | [diff] [blame] | 83 | if ( APPLE AND (LIBCXX_CXX_ABI_LIBNAME STREQUAL "libcxxabi" OR |
| 84 | LIBCXX_CXX_ABI_LIBNAME STREQUAL "none")) |
Eric Fiselier | d2852b6 | 2015-02-21 02:26:24 | [diff] [blame] | 85 | if (NOT DEFINED LIBCXX_LIBCPPABI_VERSION) |
| 86 | set(LIBCXX_LIBCPPABI_VERSION "2") |
| 87 | endif() |
| 88 | |
Michael Gottesman | 05c4b55 | 2013-09-02 07:28:03 | [diff] [blame] | 89 | if ( CMAKE_OSX_DEPLOYMENT_TARGET STREQUAL "10.6" ) |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 90 | add_definitions(-D__STRICT_ANSI__) |
| 91 | add_link_flags( |
Michael Gottesman | 05c4b55 | 2013-09-02 07:28:03 | [diff] [blame] | 92 | "-compatibility_version 1" |
Hans Wennborg | 4714826 | 2014-08-12 17:32:07 | [diff] [blame] | 93 | "-current_version 1" |
Michael Gottesman | 05c4b55 | 2013-09-02 07:28:03 | [diff] [blame] | 94 | "-install_name /usr/lib/libc++.1.dylib" |
| 95 | "-Wl,-reexport_library,/usr/lib/libc++abi.dylib" |
| 96 | "-Wl,-unexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/libc++unexp.exp" |
| 97 | "/usr/lib/libSystem.B.dylib") |
| 98 | else() |
| 99 | if ( ${CMAKE_OSX_SYSROOT} ) |
| 100 | list(FIND ${CMAKE_OSX_ARCHITECTURES} "armv7" OSX_HAS_ARMV7) |
| 101 | if (OSX_HAS_ARMV7) |
| 102 | set(OSX_RE_EXPORT_LINE |
| 103 | "${CMAKE_OSX_SYSROOT}/usr/lib/libc++abi.dylib" |
| 104 | "-Wl,-reexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/libc++sjlj-abi.exp") |
| 105 | else() |
| 106 | set(OSX_RE_EXPORT_LINE |
| 107 | "-Wl,-reexport_library,${CMAKE_OSX_SYSROOT}/usr/lib/libc++abi.dylib") |
| 108 | endif() |
| 109 | else() |
Eric Fiselier | 9dbb558 | 2015-10-05 19:28:48 | [diff] [blame] | 110 | set(OSX_RE_EXPORT_LINE "/usr/lib/libc++abi.dylib -Wl,-reexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/libc++abi${LIBCXX_LIBCPPABI_VERSION}.exp") |
Michael Gottesman | 05c4b55 | 2013-09-02 07:28:03 | [diff] [blame] | 111 | endif() |
| 112 | |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 113 | add_link_flags( |
Michael Gottesman | 05c4b55 | 2013-09-02 07:28:03 | [diff] [blame] | 114 | "-compatibility_version 1" |
| 115 | "-install_name /usr/lib/libc++.1.dylib" |
| 116 | "-Wl,-unexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/libc++unexp.exp" |
| 117 | "${OSX_RE_EXPORT_LINE}" |
| 118 | "-Wl,-force_symbols_not_weak_list,${CMAKE_CURRENT_SOURCE_DIR}/notweak.exp" |
| 119 | "-Wl,-force_symbols_weak_list,${CMAKE_CURRENT_SOURCE_DIR}/weak.exp") |
| 120 | endif() |
| 121 | endif() |
| 122 | |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 123 | target_link_libraries(cxx ${LIBCXX_LIBRARIES}) |
| 124 | split_list(LIBCXX_COMPILE_FLAGS) |
| 125 | split_list(LIBCXX_LINK_FLAGS) |
Michael Gottesman | 05c4b55 | 2013-09-02 07:28:03 | [diff] [blame] | 126 | |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 127 | set_target_properties(cxx |
| 128 | PROPERTIES |
Eric Fiselier | 5aedca9 | 2014-11-15 06:26:30 | [diff] [blame] | 129 | COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}" |
| 130 | LINK_FLAGS "${LIBCXX_LINK_FLAGS}" |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 131 | OUTPUT_NAME "c++" |
Evgeniy Stepanov | a66a7b3 | 2015-10-13 23:48:28 | [diff] [blame] | 132 | VERSION "${LIBCXX_ABI_VERSION}.0" |
| 133 | SOVERSION "${LIBCXX_ABI_VERSION}" |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 134 | ) |
| 135 | |
Eric Fiselier | 8241405 | 2015-10-14 19:54:03 | [diff] [blame] | 136 | # Generate a linker script inplace of a libc++.so symlink. Rerun this command |
| 137 | # after cxx builds. |
| 138 | if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT) |
| 139 | # Get the name of the ABI library and handle the case where CXXABI_LIBNAME |
| 140 | # is a target name and not a library. Ex cxxabi_shared. |
Eric Fiselier | 27dec39 | 2015-10-14 21:20:28 | [diff] [blame] | 141 | set(SCRIPT_ABI_LIBNAME "${LIBCXX_CXX_ABI_LIBRARY}") |
Eric Fiselier | 8241405 | 2015-10-14 19:54:03 | [diff] [blame] | 142 | if (SCRIPT_ABI_LIBNAME STREQUAL "cxxabi_shared") |
Eric Fiselier | a15785b | 2015-10-15 23:04:54 | [diff] [blame] | 143 | set(SCRIPT_ABI_LIBNAME "c++abi") |
Eric Fiselier | 8241405 | 2015-10-14 19:54:03 | [diff] [blame] | 144 | endif() |
| 145 | # Generate a linker script inplace of a libc++.so symlink. Rerun this command |
| 146 | # after cxx builds. |
| 147 | add_custom_command(TARGET cxx POST_BUILD |
| 148 | COMMAND |
| 149 | ${PYTHON_EXECUTABLE} ${LIBCXX_SOURCE_DIR}/utils/gen_link_script/gen_link_script.py |
| 150 | ARGS |
| 151 | "$<TARGET_LINKER_FILE:cxx>" |
| 152 | "${SCRIPT_ABI_LIBNAME}" |
| 153 | WORKING_DIRECTORY ${LIBCXX_BUILD_DIR} |
| 154 | ) |
| 155 | endif() |
| 156 | |
Eric Fiselier | d77135f | 2015-08-26 20:18:21 | [diff] [blame] | 157 | if (LIBCXX_INSTALL_LIBRARY) |
| 158 | install(TARGETS cxx |
| 159 | LIBRARY DESTINATION lib${LIBCXX_LIBDIR_SUFFIX} COMPONENT libcxx |
| 160 | ARCHIVE DESTINATION lib${LIBCXX_LIBDIR_SUFFIX} COMPONENT libcxx |
| 161 | ) |
Eric Fiselier | 8241405 | 2015-10-14 19:54:03 | [diff] [blame] | 162 | # NOTE: This install command must go after the cxx install command otherwise |
| 163 | # it will not be executed after the library symlinks are installed. |
| 164 | if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT) |
Eric Fiselier | e2dd2fd | 2015-10-22 21:24:01 | [diff] [blame^] | 165 | # Replace the libc++ filename with $<TARGET_LINKER_FILE:cxx> |
| 166 | # after we required CMake 3.0. |
| 167 | install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libc++${CMAKE_SHARED_LIBRARY_SUFFIX}" |
Eric Fiselier | 8241405 | 2015-10-14 19:54:03 | [diff] [blame] | 168 | DESTINATION lib${LIBCXX_LIBDIR_SUFFIX} |
| 169 | COMPONENT libcxx) |
| 170 | endif() |
Eric Fiselier | d77135f | 2015-08-26 20:18:21 | [diff] [blame] | 171 | endif() |
Eric Fiselier | 7cb813f | 2015-08-19 17:41:53 | [diff] [blame] | 172 | |
Eric Fiselier | d77135f | 2015-08-26 20:18:21 | [diff] [blame] | 173 | if (NOT CMAKE_CONFIGURATION_TYPES AND (LIBCXX_INSTALL_LIBRARY OR |
| 174 | LIBCXX_INSTALL_HEADERS)) |
| 175 | add_custom_target(install-libcxx |
| 176 | DEPENDS cxx |
| 177 | COMMAND "${CMAKE_COMMAND}" |
| 178 | -DCMAKE_INSTALL_COMPONENT=libcxx |
| 179 | -P "${LIBCXX_BINARY_DIR}/cmake_install.cmake") |
Eric Fiselier | 7cb813f | 2015-08-19 17:41:53 | [diff] [blame] | 180 | endif() |