blob: cec0bee14311a754b29b5c8f0f4b2ccda93610db [file] [log] [blame]
Michael J. Spencer626916f2010-12-10 19:47:54 +00001# Get sources
Howard Hinnant87c61a62012-03-19 15:40:23 +00002file(GLOB LIBCXX_SOURCES ../src/*.cpp)
Howard Hinnant92a07002011-09-22 19:10:18 +00003if(WIN32)
Howard Hinnant87c61a62012-03-19 15:40:23 +00004 file(GLOB LIBCXX_WIN32_SOURCES ../src/support/win32/*.cpp)
5 list(APPEND LIBCXX_SOURCES ${LIBCXX_WIN32_SOURCES})
Howard Hinnant92a07002011-09-22 19:10:18 +00006endif()
Michael J. Spencer626916f2010-12-10 19:47:54 +00007
8# Add all the headers to the project for IDEs.
9if (MSVC_IDE OR XCODE)
Howard Hinnant87c61a62012-03-19 15:40:23 +000010 file(GLOB_RECURSE LIBCXX_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../include/*)
Howard Hinnant92a07002011-09-22 19:10:18 +000011 if(WIN32)
Howard Hinnant87c61a62012-03-19 15:40:23 +000012 file( GLOB LIBCXX_WIN32_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../include/support/win32/*.h)
13 list(APPEND LIBCXX_HEADERS ${LIBCXX_WIN32_HEADERS})
Howard Hinnant92a07002011-09-22 19:10:18 +000014 endif()
Michael J. Spencer626916f2010-12-10 19:47:54 +000015 # Force them all into the headers dir on MSVC, otherwise they end up at
16 # project scope because they don't have extensions.
17 if (MSVC_IDE)
Howard Hinnant87c61a62012-03-19 15:40:23 +000018 source_group("Header Files" FILES ${LIBCXX_HEADERS})
Michael J. Spencer626916f2010-12-10 19:47:54 +000019 endif()
20endif()
21
22if (LIBCXX_ENABLE_SHARED)
23 add_library(cxx SHARED
Howard Hinnant87c61a62012-03-19 15:40:23 +000024 ${LIBCXX_SOURCES}
25 ${LIBCXX_HEADERS}
Michael J. Spencer626916f2010-12-10 19:47:54 +000026 )
27else()
28 add_library(cxx STATIC
Howard Hinnant87c61a62012-03-19 15:40:23 +000029 ${LIBCXX_SOURCES}
30 ${LIBCXX_HEADERS}
Michael J. Spencer626916f2010-12-10 19:47:54 +000031 )
32endif()
33
Michael J. Spencerdb8a0302012-12-31 19:34:21 +000034if (DEFINED LIBCXX_CXX_ABI_DEPS)
35 add_dependencies(cxx ${LIBCXX_CXX_ABI_DEPS})
36endif()
Michael J. Spencera358fbe2012-11-30 21:02:29 +000037
Michael J. Spencer626916f2010-12-10 19:47:54 +000038# Generate library list.
Michael J. Spencera358fbe2012-11-30 21:02:29 +000039set(libraries ${LIBCXX_CXX_ABI_LIBRARIES})
Michael J. Spencer626916f2010-12-10 19:47:54 +000040append_if(libraries LIBCXX_HAS_PTHREAD_LIB pthread)
41append_if(libraries LIBCXX_HAS_C_LIB c)
42append_if(libraries LIBCXX_HAS_M_LIB m)
Howard Hinnant20542c02011-05-24 12:54:00 +000043append_if(libraries LIBCXX_HAS_RT_LIB rt)
Michael J. Spencer626916f2010-12-10 19:47:54 +000044append_if(libraries LIBCXX_HAS_GCC_S_LIB gcc_s)
45
46target_link_libraries(cxx ${libraries})
47
48# Setup flags.
49append_if(compile_flags LIBCXX_HAS_FPIC_FLAG -fPIC)
50append_if(link_flags LIBCXX_HAS_NODEFAULTLIBS_FLAG -nodefaultlibs)
51
Michael Gottesman8a1fc892013-09-02 07:28:03 +000052if ( APPLE )
53 if ( CMAKE_OSX_DEPLOYMENT_TARGET STREQUAL "10.6" )
54 list(APPEND compile_flags "-U__STRICT_ANSI__")
55 list(APPEND link_flags
56 "-compatibility_version 1"
57 "-current_version ${LIBCXX_VERSION}"
58 "-install_name /usr/lib/libc++.1.dylib"
59 "-Wl,-reexport_library,/usr/lib/libc++abi.dylib"
60 "-Wl,-unexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/libc++unexp.exp"
61 "/usr/lib/libSystem.B.dylib")
62 else()
63 if ( ${CMAKE_OSX_SYSROOT} )
64 list(FIND ${CMAKE_OSX_ARCHITECTURES} "armv7" OSX_HAS_ARMV7)
65 if (OSX_HAS_ARMV7)
66 set(OSX_RE_EXPORT_LINE
67 "${CMAKE_OSX_SYSROOT}/usr/lib/libc++abi.dylib"
68 "-Wl,-reexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/libc++sjlj-abi.exp")
69 else()
70 set(OSX_RE_EXPORT_LINE
71 "-Wl,-reexport_library,${CMAKE_OSX_SYSROOT}/usr/lib/libc++abi.dylib")
72 endif()
73 else()
74 set (OSX_RE_EXPORT_LINE "/usr/lib/libc++abi.dylib -Wl,-reexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/libc++abi${LIBCXX_LIBCPPABI_VERSION}.exp")
75 endif()
76
77 list(APPEND link_flags
78 "-compatibility_version 1"
79 "-install_name /usr/lib/libc++.1.dylib"
80 "-Wl,-unexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/libc++unexp.exp"
81 "${OSX_RE_EXPORT_LINE}"
82 "-Wl,-force_symbols_not_weak_list,${CMAKE_CURRENT_SOURCE_DIR}/notweak.exp"
83 "-Wl,-force_symbols_weak_list,${CMAKE_CURRENT_SOURCE_DIR}/weak.exp")
84 endif()
85endif()
86
87string(REPLACE ";" " " link_flags "${link_flags}")
88
Michael J. Spencer626916f2010-12-10 19:47:54 +000089set_target_properties(cxx
90 PROPERTIES
91 COMPILE_FLAGS "${compile_flags}"
92 LINK_FLAGS "${link_flags}"
93 OUTPUT_NAME "c++"
94 VERSION "1.0"
95 SOVERSION "1"
96 )
97
98install(TARGETS cxx
99 LIBRARY DESTINATION lib
100 ARCHIVE DESTINATION lib
101 )