2015-03-31 12:15:45 +08:00
|
|
|
set(LIBCXX_LIB_CMAKEFILES_DIR "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}" PARENT_SCOPE)
|
|
|
|
|
2010-12-11 03:47:54 +08:00
|
|
|
# Get sources
|
2012-03-19 23:40:23 +08:00
|
|
|
file(GLOB LIBCXX_SOURCES ../src/*.cpp)
|
2011-09-23 03:10:18 +08:00
|
|
|
if(WIN32)
|
2012-03-19 23:40:23 +08:00
|
|
|
file(GLOB LIBCXX_WIN32_SOURCES ../src/support/win32/*.cpp)
|
|
|
|
list(APPEND LIBCXX_SOURCES ${LIBCXX_WIN32_SOURCES})
|
2014-11-26 05:57:41 +08:00
|
|
|
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "SunOS")
|
|
|
|
file(GLOB LIBCXX_SOLARIS_SOURCES ../src/support/solaris/*.c)
|
|
|
|
list(APPEND LIBCXX_SOURCES ${LIBCXX_SOLARIS_SOURCES})
|
2011-09-23 03:10:18 +08:00
|
|
|
endif()
|
2010-12-11 03:47:54 +08:00
|
|
|
|
|
|
|
# Add all the headers to the project for IDEs.
|
|
|
|
if (MSVC_IDE OR XCODE)
|
2012-03-19 23:40:23 +08:00
|
|
|
file(GLOB_RECURSE LIBCXX_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../include/*)
|
2011-09-23 03:10:18 +08:00
|
|
|
if(WIN32)
|
2012-03-19 23:40:23 +08:00
|
|
|
file( GLOB LIBCXX_WIN32_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../include/support/win32/*.h)
|
|
|
|
list(APPEND LIBCXX_HEADERS ${LIBCXX_WIN32_HEADERS})
|
2011-09-23 03:10:18 +08:00
|
|
|
endif()
|
2010-12-11 03:47:54 +08:00
|
|
|
# Force them all into the headers dir on MSVC, otherwise they end up at
|
|
|
|
# project scope because they don't have extensions.
|
|
|
|
if (MSVC_IDE)
|
2012-03-19 23:40:23 +08:00
|
|
|
source_group("Header Files" FILES ${LIBCXX_HEADERS})
|
2010-12-11 03:47:54 +08:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if (LIBCXX_ENABLE_SHARED)
|
2015-07-31 06:30:34 +08:00
|
|
|
add_library(cxx SHARED ${LIBCXX_SOURCES} ${LIBCXX_HEADERS})
|
2010-12-11 03:47:54 +08:00
|
|
|
else()
|
2015-07-31 06:30:34 +08:00
|
|
|
add_library(cxx STATIC ${LIBCXX_SOURCES} ${LIBCXX_HEADERS})
|
2015-03-03 23:59:51 +08:00
|
|
|
endif()
|
|
|
|
|
2013-01-01 03:34:21 +08:00
|
|
|
if (DEFINED LIBCXX_CXX_ABI_DEPS)
|
2014-06-25 04:32:11 +08:00
|
|
|
add_dependencies(cxx LIBCXX_CXX_ABI_DEPS)
|
2013-01-01 03:34:21 +08:00
|
|
|
endif()
|
2012-12-01 05:02:29 +08:00
|
|
|
|
2015-07-31 06:30:34 +08:00
|
|
|
#if LIBCXX_CXX_ABI_LIBRARY_PATH is defined we want to add it to the search path.
|
|
|
|
add_link_flags_if(LIBCXX_CXX_ABI_LIBRARY_PATH "-L${LIBCXX_CXX_ABI_LIBRARY_PATH}")
|
2015-07-30 05:07:28 +08:00
|
|
|
|
2015-07-31 06:30:34 +08:00
|
|
|
add_library_flags_if(LIBCXX_COVERAGE_LIBRARY "${LIBCXX_COVERAGE_LIBRARY}")
|
|
|
|
|
|
|
|
add_library_flags_if(LIBCXX_ENABLE_STATIC_ABI_LIBRARY "-Wl,--whole-archive" "-Wl,-Bstatic")
|
|
|
|
add_library_flags("${LIBCXX_CXX_ABI_LIBRARY}")
|
|
|
|
add_library_flags_if(LIBCXX_ENABLE_STATIC_ABI_LIBRARY "-Wl,-Bdynamic" "-Wl,--no-whole-archive")
|
2010-12-11 03:47:54 +08:00
|
|
|
|
2015-07-22 08:33:36 +08:00
|
|
|
if (APPLE AND LLVM_USE_SANITIZER)
|
|
|
|
if ("${LLVM_USE_SANITIZER}" STREQUAL "Address")
|
|
|
|
set(LIBFILE "libclang_rt.asan_osx_dynamic.dylib")
|
|
|
|
elseif("${LLVM_USE_SANITIZER}" STREQUAL "Undefined")
|
|
|
|
set(LIBFILE "libclang_rt.ubsan_osx_dynamic.dylib")
|
|
|
|
else()
|
|
|
|
message(WARNING "LLVM_USE_SANITIZER=${LLVM_USE_SANITIZER} is not supported on OS X")
|
|
|
|
endif()
|
|
|
|
if (LIBFILE)
|
|
|
|
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -print-file-name=lib OUTPUT_VARIABLE LIBDIR RESULT_VARIABLE Result)
|
|
|
|
if (NOT ${Result} EQUAL "0")
|
|
|
|
message(FATAL "Failed to find library resource directory")
|
|
|
|
endif()
|
|
|
|
string(STRIP "${LIBDIR}" LIBDIR)
|
|
|
|
set(LIBDIR "${LIBDIR}/darwin/")
|
|
|
|
if (NOT IS_DIRECTORY "${LIBDIR}")
|
|
|
|
message(FATAL_ERROR "Cannot find compiler-rt directory on OS X required for LLVM_USE_SANITIZER")
|
|
|
|
endif()
|
|
|
|
set(LIBCXX_SANITIZER_LIBRARY "${LIBDIR}/${LIBFILE}")
|
|
|
|
set(LIBCXX_SANITIZER_LIBRARY "${LIBCXX_SANITIZER_LIBRARY}" PARENT_SCOPE)
|
|
|
|
message(STATUS "Manually linking compiler-rt library: ${LIBCXX_SANITIZER_LIBRARY}")
|
2015-07-31 06:30:34 +08:00
|
|
|
add_library_flags("${LIBCXX_SANITIZER_LIBRARY}")
|
|
|
|
add_link_flags("-Wl,-rpath,${LIBDIR}")
|
2015-07-22 08:33:36 +08:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2015-07-31 06:30:34 +08:00
|
|
|
# Generate library list.
|
|
|
|
add_library_flags_if(LIBCXX_HAS_PTHREAD_LIB pthread)
|
|
|
|
add_library_flags_if(LIBCXX_HAS_C_LIB c)
|
|
|
|
add_library_flags_if(LIBCXX_HAS_M_LIB m)
|
|
|
|
add_library_flags_if(LIBCXX_HAS_RT_LIB rt)
|
|
|
|
add_library_flags_if(LIBCXX_HAS_GCC_S_LIB gcc_s)
|
2015-03-31 12:15:45 +08:00
|
|
|
|
2010-12-11 03:47:54 +08:00
|
|
|
# Setup flags.
|
2015-07-31 06:30:34 +08:00
|
|
|
add_flags_if_supported(-fPIC)
|
|
|
|
add_link_flags_if_supported(-nodefaultlibs)
|
2010-12-11 03:47:54 +08:00
|
|
|
|
2015-03-27 17:00:45 +08:00
|
|
|
if ( APPLE AND (LIBCXX_CXX_ABI_LIBNAME STREQUAL "libcxxabi" OR
|
|
|
|
LIBCXX_CXX_ABI_LIBNAME STREQUAL "none"))
|
2015-02-21 10:26:24 +08:00
|
|
|
if (NOT DEFINED LIBCXX_LIBCPPABI_VERSION)
|
|
|
|
set(LIBCXX_LIBCPPABI_VERSION "2")
|
|
|
|
endif()
|
|
|
|
|
2013-09-02 15:28:03 +08:00
|
|
|
if ( CMAKE_OSX_DEPLOYMENT_TARGET STREQUAL "10.6" )
|
2015-07-31 06:30:34 +08:00
|
|
|
add_definitions(-D__STRICT_ANSI__)
|
|
|
|
add_link_flags(
|
2013-09-02 15:28:03 +08:00
|
|
|
"-compatibility_version 1"
|
2014-08-13 01:32:07 +08:00
|
|
|
"-current_version 1"
|
2013-09-02 15:28:03 +08:00
|
|
|
"-install_name /usr/lib/libc++.1.dylib"
|
|
|
|
"-Wl,-reexport_library,/usr/lib/libc++abi.dylib"
|
|
|
|
"-Wl,-unexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/libc++unexp.exp"
|
|
|
|
"/usr/lib/libSystem.B.dylib")
|
|
|
|
else()
|
|
|
|
if ( ${CMAKE_OSX_SYSROOT} )
|
|
|
|
list(FIND ${CMAKE_OSX_ARCHITECTURES} "armv7" OSX_HAS_ARMV7)
|
|
|
|
if (OSX_HAS_ARMV7)
|
|
|
|
set(OSX_RE_EXPORT_LINE
|
|
|
|
"${CMAKE_OSX_SYSROOT}/usr/lib/libc++abi.dylib"
|
|
|
|
"-Wl,-reexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/libc++sjlj-abi.exp")
|
|
|
|
else()
|
|
|
|
set(OSX_RE_EXPORT_LINE
|
|
|
|
"-Wl,-reexport_library,${CMAKE_OSX_SYSROOT}/usr/lib/libc++abi.dylib")
|
|
|
|
endif()
|
|
|
|
else()
|
2015-10-06 03:28:48 +08:00
|
|
|
set(OSX_RE_EXPORT_LINE "/usr/lib/libc++abi.dylib -Wl,-reexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/libc++abi${LIBCXX_LIBCPPABI_VERSION}.exp")
|
2013-09-02 15:28:03 +08:00
|
|
|
endif()
|
|
|
|
|
2015-07-31 06:30:34 +08:00
|
|
|
add_link_flags(
|
2013-09-02 15:28:03 +08:00
|
|
|
"-compatibility_version 1"
|
|
|
|
"-install_name /usr/lib/libc++.1.dylib"
|
|
|
|
"-Wl,-unexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/libc++unexp.exp"
|
|
|
|
"${OSX_RE_EXPORT_LINE}"
|
|
|
|
"-Wl,-force_symbols_not_weak_list,${CMAKE_CURRENT_SOURCE_DIR}/notweak.exp"
|
|
|
|
"-Wl,-force_symbols_weak_list,${CMAKE_CURRENT_SOURCE_DIR}/weak.exp")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2015-07-31 06:30:34 +08:00
|
|
|
target_link_libraries(cxx ${LIBCXX_LIBRARIES})
|
|
|
|
split_list(LIBCXX_COMPILE_FLAGS)
|
|
|
|
split_list(LIBCXX_LINK_FLAGS)
|
2013-09-02 15:28:03 +08:00
|
|
|
|
2010-12-11 03:47:54 +08:00
|
|
|
set_target_properties(cxx
|
|
|
|
PROPERTIES
|
2014-11-15 14:26:30 +08:00
|
|
|
COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}"
|
|
|
|
LINK_FLAGS "${LIBCXX_LINK_FLAGS}"
|
2010-12-11 03:47:54 +08:00
|
|
|
OUTPUT_NAME "c++"
|
2015-10-14 07:48:28 +08:00
|
|
|
VERSION "${LIBCXX_ABI_VERSION}.0"
|
|
|
|
SOVERSION "${LIBCXX_ABI_VERSION}"
|
2010-12-11 03:47:54 +08:00
|
|
|
)
|
|
|
|
|
2015-10-15 03:54:03 +08:00
|
|
|
# Generate a linker script inplace of a libc++.so symlink. Rerun this command
|
|
|
|
# after cxx builds.
|
|
|
|
if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
|
|
|
|
# Get the name of the ABI library and handle the case where CXXABI_LIBNAME
|
|
|
|
# is a target name and not a library. Ex cxxabi_shared.
|
2015-10-15 05:20:28 +08:00
|
|
|
set(SCRIPT_ABI_LIBNAME "${LIBCXX_CXX_ABI_LIBRARY}")
|
2015-10-15 03:54:03 +08:00
|
|
|
if (SCRIPT_ABI_LIBNAME STREQUAL "cxxabi_shared")
|
2015-10-16 07:04:54 +08:00
|
|
|
set(SCRIPT_ABI_LIBNAME "c++abi")
|
2015-10-15 03:54:03 +08:00
|
|
|
endif()
|
|
|
|
# Generate a linker script inplace of a libc++.so symlink. Rerun this command
|
|
|
|
# after cxx builds.
|
|
|
|
add_custom_command(TARGET cxx POST_BUILD
|
|
|
|
COMMAND
|
|
|
|
${PYTHON_EXECUTABLE} ${LIBCXX_SOURCE_DIR}/utils/gen_link_script/gen_link_script.py
|
|
|
|
ARGS
|
|
|
|
"$<TARGET_LINKER_FILE:cxx>"
|
|
|
|
"${SCRIPT_ABI_LIBNAME}"
|
|
|
|
WORKING_DIRECTORY ${LIBCXX_BUILD_DIR}
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2015-08-27 04:18:21 +08:00
|
|
|
if (LIBCXX_INSTALL_LIBRARY)
|
|
|
|
install(TARGETS cxx
|
|
|
|
LIBRARY DESTINATION lib${LIBCXX_LIBDIR_SUFFIX} COMPONENT libcxx
|
|
|
|
ARCHIVE DESTINATION lib${LIBCXX_LIBDIR_SUFFIX} COMPONENT libcxx
|
|
|
|
)
|
2015-10-15 03:54:03 +08:00
|
|
|
# NOTE: This install command must go after the cxx install command otherwise
|
|
|
|
# it will not be executed after the library symlinks are installed.
|
|
|
|
if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
|
2015-10-23 05:24:01 +08:00
|
|
|
# Replace the libc++ filename with $<TARGET_LINKER_FILE:cxx>
|
|
|
|
# after we required CMake 3.0.
|
2015-10-23 15:04:24 +08:00
|
|
|
install(FILES "${LIBCXX_LIBRARY_DIR}/libc++${CMAKE_SHARED_LIBRARY_SUFFIX}"
|
2015-10-15 03:54:03 +08:00
|
|
|
DESTINATION lib${LIBCXX_LIBDIR_SUFFIX}
|
|
|
|
COMPONENT libcxx)
|
|
|
|
endif()
|
2015-08-27 04:18:21 +08:00
|
|
|
endif()
|
2015-08-20 01:41:53 +08:00
|
|
|
|
2015-08-27 04:18:21 +08:00
|
|
|
if (NOT CMAKE_CONFIGURATION_TYPES AND (LIBCXX_INSTALL_LIBRARY OR
|
|
|
|
LIBCXX_INSTALL_HEADERS))
|
|
|
|
add_custom_target(install-libcxx
|
|
|
|
DEPENDS cxx
|
|
|
|
COMMAND "${CMAKE_COMMAND}"
|
|
|
|
-DCMAKE_INSTALL_COMPONENT=libcxx
|
|
|
|
-P "${LIBCXX_BINARY_DIR}/cmake_install.cmake")
|
2015-08-20 01:41:53 +08:00
|
|
|
endif()
|