[PATCH] [libc++] On Linux, use libstdc++ as ABI lib by default, and give that lib a new name.

Peter Collingbourne peter at pcc.me.uk
Thu Oct 17 22:29:10 PDT 2013


Building with libstdc++ is most likely to work on Linux, as that OS does
not generally ship libc++abi as a system library.  The library is now
called libc++gnu when built against libstdc++.  The name change allows
a libstdc++-compatible and libstdc++-incompatible libc++ to coexist on a
Linux system.  Also, create a symlink allowing libc++ to be used from a
build directory when built with Clang.

http://llvm-reviews.chandlerc.com/D1969

Files:
  CMakeLists.txt
  lib/CMakeLists.txt
  test/lit.cfg
  test/lit.site.cfg.in

Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -46,7 +46,11 @@
 
 set(CXXABIS none libcxxabi libcxxrt libstdc++ libsupc++)
 if (NOT DEFINED LIBCXX_CXX_ABI)
-  set(LIBCXX_CXX_ABI "none")
+  if(LINUX)
+    set(LIBCXX_CXX_ABI "libstdc++")
+  else()
+    set(LIBCXX_CXX_ABI "none")
+  endif()
 endif()
 set(LIBCXX_CXX_ABI "${LIBCXX_CXX_ABI}" CACHE STRING
     "Specify C++ ABI library to use." FORCE)
@@ -133,13 +137,16 @@
     )
 endmacro()
 
+set(LIBCXX_LIBNAME "c++")
+
 if ("${LIBCXX_CXX_ABI}" STREQUAL "libstdc++" OR
     "${LIBCXX_CXX_ABI}" STREQUAL "libsupc++")
   set(_LIBSUPCXX_INCLUDE_FILES
     cxxabi.h bits/c++config.h bits/os_defines.h bits/cpu_defines.h
     bits/cxxabi_tweaks.h bits/cxxabi_forced.h
     )
   if ("${LIBCXX_CXX_ABI}" STREQUAL "libstdc++")
+    set(LIBCXX_LIBNAME "c++gnu")
     set(_LIBSUPCXX_DEFINES "-DLIBSTDCXX")
     set(_LIBSUPCXX_LIBNAME stdc++)
   else()
Index: lib/CMakeLists.txt
===================================================================
--- lib/CMakeLists.txt
+++ lib/CMakeLists.txt
@@ -90,7 +90,7 @@
   PROPERTIES
     COMPILE_FLAGS "${compile_flags}"
     LINK_FLAGS    "${link_flags}"
-    OUTPUT_NAME   "c++"
+    OUTPUT_NAME   "${LIBCXX_LIBNAME}"
     VERSION       "1.0"
     SOVERSION     "1"
   )
@@ -112,3 +112,13 @@
   PATTERN ".svn" EXCLUDE
   ${LIBCXX_SUPPORT_HEADER_PATTERN}
   )
+
+# This symlink makes it possible for libc++ to be used from the build directory.
+if(UNIX)
+  add_custom_target(cxx_header_symlink
+                    SOURCES ${CMAKE_BINARY_DIR}/include/c++/v1)
+  add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/include/c++/v1 VERBATIM
+                     COMMAND ln -s ${CMAKE_CURRENT_SOURCE_DIR}/../include
+                                   ${CMAKE_BINARY_DIR}/include/c++/v1)
+  add_dependencies(cxx cxx_header_symlink)
+endif()
Index: test/lit.cfg
===================================================================
--- test/lit.cfg
+++ test/lit.cfg
@@ -229,7 +229,8 @@
     use_system_lib = False
     lit_config.note("inferred use_system_lib as: %r" % (use_system_lib,))
 
-link_flags = []
+libname = getattr(config, 'libname', 'c++')
+link_flags = ['-l' + libname]
 link_flags_str = lit_config.params.get('link_flags', None)
 if link_flags_str is None:
     link_flags_str = getattr(config, 'link_flags', None)
@@ -282,7 +283,7 @@
 config.test_format = LibcxxTestFormat(
     cxx_under_test,
     cpp_flags = ['-nostdinc++'] + compile_flags + include_paths,
-    ld_flags = ['-nodefaultlibs'] + library_paths + ['-lc++'] + link_flags,
+    ld_flags = ['-nodefaultlibs'] + library_paths + link_flags,
     exec_env = exec_env)
 
 # Get or infer the target triple.
Index: test/lit.site.cfg.in
===================================================================
--- test/lit.site.cfg.in
+++ test/lit.site.cfg.in
@@ -6,6 +6,7 @@
 config.python_executable     = "@PYTHON_EXECUTABLE@"
 config.enable_shared         = @LIBCXX_ENABLE_SHARED@
 config.cxx_abi               = "@LIBCXX_CXX_ABI@"
+config.libname               = "@LIBCXX_LIBNAME@"
 
 # Let the main config do the real work.
 lit_config.load_config(config, "@LIBCXX_SOURCE_DIR@/test/lit.cfg")
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1969.1.patch
Type: text/x-patch
Size: 3219 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131017/aa4dd576/attachment.bin>


More information about the cfe-commits mailing list