Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 1 | # Get sources |
Howard Hinnant | 87c61a6 | 2012-03-19 15:40:23 +0000 | [diff] [blame] | 2 | file(GLOB LIBCXX_SOURCES ../src/*.cpp) |
Howard Hinnant | 92a0700 | 2011-09-22 19:10:18 +0000 | [diff] [blame] | 3 | if(WIN32) |
Howard Hinnant | 87c61a6 | 2012-03-19 15:40:23 +0000 | [diff] [blame] | 4 | file(GLOB LIBCXX_WIN32_SOURCES ../src/support/win32/*.cpp) |
| 5 | list(APPEND LIBCXX_SOURCES ${LIBCXX_WIN32_SOURCES}) |
Eric Fiselier | 6cb69ff | 2014-11-25 21:57:41 +0000 | [diff] [blame] | 6 | elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "SunOS") |
| 7 | file(GLOB LIBCXX_SOLARIS_SOURCES ../src/support/solaris/*.c) |
| 8 | list(APPEND LIBCXX_SOURCES ${LIBCXX_SOLARIS_SOURCES}) |
Howard Hinnant | 92a0700 | 2011-09-22 19:10:18 +0000 | [diff] [blame] | 9 | endif() |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 10 | |
| 11 | # Add all the headers to the project for IDEs. |
| 12 | if (MSVC_IDE OR XCODE) |
Howard Hinnant | 87c61a6 | 2012-03-19 15:40:23 +0000 | [diff] [blame] | 13 | file(GLOB_RECURSE LIBCXX_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../include/*) |
Howard Hinnant | 92a0700 | 2011-09-22 19:10:18 +0000 | [diff] [blame] | 14 | if(WIN32) |
Howard Hinnant | 87c61a6 | 2012-03-19 15:40:23 +0000 | [diff] [blame] | 15 | file( GLOB LIBCXX_WIN32_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../include/support/win32/*.h) |
| 16 | list(APPEND LIBCXX_HEADERS ${LIBCXX_WIN32_HEADERS}) |
Howard Hinnant | 92a0700 | 2011-09-22 19:10:18 +0000 | [diff] [blame] | 17 | endif() |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 18 | # Force them all into the headers dir on MSVC, otherwise they end up at |
| 19 | # project scope because they don't have extensions. |
| 20 | if (MSVC_IDE) |
Howard Hinnant | 87c61a6 | 2012-03-19 15:40:23 +0000 | [diff] [blame] | 21 | source_group("Header Files" FILES ${LIBCXX_HEADERS}) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 22 | endif() |
| 23 | endif() |
| 24 | |
| 25 | if (LIBCXX_ENABLE_SHARED) |
| 26 | add_library(cxx SHARED |
Howard Hinnant | 87c61a6 | 2012-03-19 15:40:23 +0000 | [diff] [blame] | 27 | ${LIBCXX_SOURCES} |
| 28 | ${LIBCXX_HEADERS} |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 29 | ) |
| 30 | else() |
| 31 | add_library(cxx STATIC |
Howard Hinnant | 87c61a6 | 2012-03-19 15:40:23 +0000 | [diff] [blame] | 32 | ${LIBCXX_SOURCES} |
| 33 | ${LIBCXX_HEADERS} |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 34 | ) |
| 35 | endif() |
| 36 | |
Eric Fiselier | c0b166e | 2015-03-03 15:59:51 +0000 | [diff] [blame^] | 37 | #if LIBCXX_CXX_ABI_LIBRARY_PATH is defined we want to add it to the search path. |
| 38 | if (DEFINED LIBCXX_CXX_ABI_LIBRARY_PATH) |
| 39 | target_link_libraries(cxx "-L${LIBCXX_CXX_ABI_LIBRARY_PATH}") |
| 40 | endif() |
| 41 | |
Michael J. Spencer | db8a030 | 2012-12-31 19:34:21 +0000 | [diff] [blame] | 42 | if (DEFINED LIBCXX_CXX_ABI_DEPS) |
David Fang | 44ead61 | 2014-06-24 20:32:11 +0000 | [diff] [blame] | 43 | add_dependencies(cxx LIBCXX_CXX_ABI_DEPS) |
Michael J. Spencer | db8a030 | 2012-12-31 19:34:21 +0000 | [diff] [blame] | 44 | endif() |
Michael J. Spencer | a358fbe | 2012-11-30 21:02:29 +0000 | [diff] [blame] | 45 | |
Eric Fiselier | c0b166e | 2015-03-03 15:59:51 +0000 | [diff] [blame^] | 46 | set(libraries "") |
| 47 | if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY) |
| 48 | # TODO(ericwf): Remove these GNU specific linker flags and let CMake do the |
| 49 | # configuration. This will be more portable. |
| 50 | list(APPEND libraries "-Wl,--whole-archive" "-Wl,-Bstatic") |
| 51 | list(APPEND libraries "${LIBCXX_CXX_ABI_LIBRARY}") |
| 52 | list(APPEND libraries "-Wl,-Bdynamic" "-Wl,--no-whole-archive") |
| 53 | else() |
| 54 | list(APPEND libraries "${LIBCXX_CXX_ABI_LIBRARY}") |
| 55 | endif() |
| 56 | |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 57 | # Generate library list. |
| 58 | append_if(libraries LIBCXX_HAS_PTHREAD_LIB pthread) |
| 59 | append_if(libraries LIBCXX_HAS_C_LIB c) |
| 60 | append_if(libraries LIBCXX_HAS_M_LIB m) |
Howard Hinnant | 20542c0 | 2011-05-24 12:54:00 +0000 | [diff] [blame] | 61 | append_if(libraries LIBCXX_HAS_RT_LIB rt) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 62 | append_if(libraries LIBCXX_HAS_GCC_S_LIB gcc_s) |
| 63 | |
| 64 | target_link_libraries(cxx ${libraries}) |
| 65 | |
| 66 | # Setup flags. |
Eric Fiselier | 8e2855c | 2014-11-15 06:26:30 +0000 | [diff] [blame] | 67 | append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_FPIC_FLAG -fPIC) |
| 68 | append_if(LIBCXX_LINK_FLAGS LIBCXX_HAS_NODEFAULTLIBS_FLAG -nodefaultlibs) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 69 | |
Michael Gottesman | 8a1fc89 | 2013-09-02 07:28:03 +0000 | [diff] [blame] | 70 | if ( APPLE ) |
Eric Fiselier | 45969ec | 2015-02-21 02:26:24 +0000 | [diff] [blame] | 71 | if (NOT DEFINED LIBCXX_LIBCPPABI_VERSION) |
| 72 | set(LIBCXX_LIBCPPABI_VERSION "2") |
| 73 | endif() |
| 74 | |
Michael Gottesman | 8a1fc89 | 2013-09-02 07:28:03 +0000 | [diff] [blame] | 75 | if ( CMAKE_OSX_DEPLOYMENT_TARGET STREQUAL "10.6" ) |
Eric Fiselier | 8e2855c | 2014-11-15 06:26:30 +0000 | [diff] [blame] | 76 | list(APPEND LIBCXX_COMPILE_FLAGS "-U__STRICT_ANSI__") |
| 77 | list(APPEND LIBCXX_LINK_FLAGS |
Michael Gottesman | 8a1fc89 | 2013-09-02 07:28:03 +0000 | [diff] [blame] | 78 | "-compatibility_version 1" |
Hans Wennborg | f3b5f0e | 2014-08-12 17:32:07 +0000 | [diff] [blame] | 79 | "-current_version 1" |
Michael Gottesman | 8a1fc89 | 2013-09-02 07:28:03 +0000 | [diff] [blame] | 80 | "-install_name /usr/lib/libc++.1.dylib" |
| 81 | "-Wl,-reexport_library,/usr/lib/libc++abi.dylib" |
| 82 | "-Wl,-unexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/libc++unexp.exp" |
| 83 | "/usr/lib/libSystem.B.dylib") |
| 84 | else() |
| 85 | if ( ${CMAKE_OSX_SYSROOT} ) |
| 86 | list(FIND ${CMAKE_OSX_ARCHITECTURES} "armv7" OSX_HAS_ARMV7) |
| 87 | if (OSX_HAS_ARMV7) |
| 88 | set(OSX_RE_EXPORT_LINE |
| 89 | "${CMAKE_OSX_SYSROOT}/usr/lib/libc++abi.dylib" |
| 90 | "-Wl,-reexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/libc++sjlj-abi.exp") |
| 91 | else() |
| 92 | set(OSX_RE_EXPORT_LINE |
| 93 | "-Wl,-reexport_library,${CMAKE_OSX_SYSROOT}/usr/lib/libc++abi.dylib") |
| 94 | endif() |
| 95 | else() |
| 96 | set (OSX_RE_EXPORT_LINE "/usr/lib/libc++abi.dylib -Wl,-reexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/libc++abi${LIBCXX_LIBCPPABI_VERSION}.exp") |
| 97 | endif() |
| 98 | |
Eric Fiselier | 8e2855c | 2014-11-15 06:26:30 +0000 | [diff] [blame] | 99 | list(APPEND LIBCXX_LINK_FLAGS |
Michael Gottesman | 8a1fc89 | 2013-09-02 07:28:03 +0000 | [diff] [blame] | 100 | "-compatibility_version 1" |
| 101 | "-install_name /usr/lib/libc++.1.dylib" |
| 102 | "-Wl,-unexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/libc++unexp.exp" |
| 103 | "${OSX_RE_EXPORT_LINE}" |
| 104 | "-Wl,-force_symbols_not_weak_list,${CMAKE_CURRENT_SOURCE_DIR}/notweak.exp" |
| 105 | "-Wl,-force_symbols_weak_list,${CMAKE_CURRENT_SOURCE_DIR}/weak.exp") |
| 106 | endif() |
| 107 | endif() |
| 108 | |
Eric Fiselier | 8e2855c | 2014-11-15 06:26:30 +0000 | [diff] [blame] | 109 | string(REPLACE ";" " " LIBCXX_COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}") |
| 110 | string(REPLACE ";" " " LIBCXX_LINK_FLAGS "${LIBCXX_LINK_FLAGS}") |
Michael Gottesman | 8a1fc89 | 2013-09-02 07:28:03 +0000 | [diff] [blame] | 111 | |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 112 | set_target_properties(cxx |
| 113 | PROPERTIES |
Eric Fiselier | 8e2855c | 2014-11-15 06:26:30 +0000 | [diff] [blame] | 114 | COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}" |
| 115 | LINK_FLAGS "${LIBCXX_LINK_FLAGS}" |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 116 | OUTPUT_NAME "c++" |
| 117 | VERSION "1.0" |
| 118 | SOVERSION "1" |
| 119 | ) |
| 120 | |
| 121 | install(TARGETS cxx |
Chandler Carruth | 7a033ca | 2014-12-29 12:15:47 +0000 | [diff] [blame] | 122 | LIBRARY DESTINATION lib${LIBCXX_LIBDIR_SUFFIX} |
| 123 | ARCHIVE DESTINATION lib${LIBCXX_LIBDIR_SUFFIX} |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 124 | ) |