[PATCH] [libc++] Change how CMake links libc++ with OS X.
Eric Fiselier
eric at efcs.ca
Mon Feb 9 09:57:39 PST 2015
Hi danalbert, jroelofs, mclow.lists,
As it stands now CMake will always link against /usr/lib/libc++abi.dylib on OS X; Even when -DLIBCXX_CXX_ABI_PATH is given; Even if we are using libcxxrt as the ABI library.
Furthermore, when LIBCXX_CXX_ABI_PATH is given libc++ will end up linked against two version of libc++abi. This patch, while not pretty, changes it so that CMake will guess the location of libc++abi.dylib and attempt to link libc++ against only the version of libc++abi.dylib it has guessed.
Note: We cannot actually ensure that the libc++abi.dylib that we guessed actually exists at configure time (because it may be created between configuring and building).
Any suggestions on cleaning this up is greatly appreciated.
http://reviews.llvm.org/D7511
Files:
lib/CMakeLists.txt
Index: lib/CMakeLists.txt
===================================================================
--- lib/CMakeLists.txt
+++ lib/CMakeLists.txt
@@ -38,47 +38,72 @@
add_dependencies(cxx LIBCXX_CXX_ABI_DEPS)
endif()
+# We need to use a bunch of special link flags for apple in these cases.
+if (APPLE AND (LIBCXX_CXX_ABI_LIBNAME STREQUAL "none" OR
+ LIBCXX_CXX_ABI_LIBNAME STREQUAL "libcxxabi"))
+ set(APPLE_SPECIAL_LINK_CONFIG TRUE)
+endif()
+
+
+if (NOT APPLE_SPECIAL_LINK_CONFIG)
+ #if LIBCXX_CXX_ABI_LIBRARY_PATH is defined we want to add it to the search path.
+ if (DEFINED LIBCXX_CXX_ABI_LIBRARY_PATH)
+ target_link_libraries(cxx "-L${LIBCXX_CXX_ABI_LIBRARY_PATH}"
+ "-Wl,-rpath,${LIBCXX_CXX_ABI_LIBRARY_PATH}")
+ endif()
+ # Link libc++ to the ABI library.
+ target_link_libraries(cxx ${LIBCXX_CXX_ABI_LIBRARY})
+endif()
+
# Generate library list.
-set(libraries ${LIBCXX_CXX_ABI_LIBRARY})
+set(libraries "")
append_if(libraries LIBCXX_HAS_PTHREAD_LIB pthread)
append_if(libraries LIBCXX_HAS_C_LIB c)
append_if(libraries LIBCXX_HAS_M_LIB m)
append_if(libraries LIBCXX_HAS_RT_LIB rt)
append_if(libraries LIBCXX_HAS_GCC_S_LIB gcc_s)
-
-#if LIBCXX_CXX_ABI_LIBRARY_PATH is defined we want to add it to the search path.
-if (DEFINED LIBCXX_CXX_ABI_LIBRARY_PATH)
- target_link_libraries(cxx "-L${LIBCXX_CXX_ABI_LIBRARY_PATH}")
-endif()
target_link_libraries(cxx ${libraries})
# Setup flags.
append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_FPIC_FLAG -fPIC)
append_if(LIBCXX_LINK_FLAGS LIBCXX_HAS_NODEFAULTLIBS_FLAG -nodefaultlibs)
-if ( APPLE )
+
+if ( APPLE_SPECIAL_LINK_CONFIG )
+ # Attempt to guess the location of libc++abi.dylib. Start by setting it to the
+ # Default location.
+ set(LIBCXX_CXX_ABI_LIBRARY_LOCATION "${CMAKE_OSX_SYSROOT}/usr/lib/libc++abi.dylib")
+ # If libc++abi is an intree CMake target get its name from the target
+ # properties.
+ if(LIBCXX_CXX_ABI_LIBRARY STREQUAL "cxxabi")
+ get_target_property(LIBCXX_CXX_ABI_LIBRARY_LOCATION TARGET cxxabi PROPERTY LOCATION)
+ # Otherwise if the user has told us where to look then construct the name
+ # from the patch.
+ elseif (LIBCXX_CXX_ABI_LIBRARY STREQUAL "c++abi" AND DEFINED LIBCXX_CXX_ABI_LIBRARY_PATH)
+ set(LIBCXX_CXX_ABI_LIBRARY_LOCATION "${LIBCXX_CXX_ABI_LIBRARY_PATH}/libc++abi.dylib")
+ endif()
if ( CMAKE_OSX_DEPLOYMENT_TARGET STREQUAL "10.6" )
list(APPEND LIBCXX_COMPILE_FLAGS "-U__STRICT_ANSI__")
list(APPEND LIBCXX_LINK_FLAGS
"-compatibility_version 1"
"-current_version 1"
"-install_name /usr/lib/libc++.1.dylib"
- "-Wl,-reexport_library,/usr/lib/libc++abi.dylib"
+ "-Wl,-reexport_library,${LIBCXX_CXX_ABI_LIBRARY_LOCATION}"
"-Wl,-unexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/libc++unexp.exp"
+ "${LIBCXX_CXX_ABI_LIBRARY_LOCATION}"
"/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")
+ "-Wl,-reexport_library,${LIBCXX_CXX_ABI_LIBRARY_LOCATION}")
endif()
else()
- set (OSX_RE_EXPORT_LINE "/usr/lib/libc++abi.dylib -Wl,-reexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/libc++abi${LIBCXX_LIBCPPABI_VERSION}.exp")
+ set (OSX_RE_EXPORT_LINE "-Wl,-reexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/libc++abi${LIBCXX_LIBCPPABI_VERSION}.exp")
endif()
list(APPEND LIBCXX_LINK_FLAGS
@@ -87,7 +112,8 @@
"-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")
+ "-Wl,-force_symbols_weak_list,${CMAKE_CURRENT_SOURCE_DIR}/weak.exp"
+ "${LIBCXX_CXX_ABI_LIBRARY_LOCATION}")
endif()
endif()
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7511.19594.patch
Type: text/x-patch
Size: 4210 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150209/bec3b33d/attachment.bin>
More information about the cfe-commits
mailing list