Index: CMakeLists.txt =================================================================== --- CMakeLists.txt +++ CMakeLists.txt @@ -142,6 +142,8 @@ # Use a static copy of the ABI library when linking libc++. This option # cannot be used with LIBCXX_ENABLE_ABI_LINKER_SCRIPT. option(LIBCXX_ENABLE_STATIC_ABI_LIBRARY "Statically link the ABI library" OFF) +option(LIBCXX_ENABLE_STATIC_ABI_LIBRARY_FOR_STATIC "Statically link the ABI library for Static Build" ${LIBCXX_ENABLE_STATIC_ABI_LIBRARY}) +option(LIBCXX_ENABLE_STATIC_ABI_LIBRARY_FOR_SHARED "Statically link the ABI library for Shared Build" ${LIBCXX_ENABLE_STATIC_ABI_LIBRARY}) # Generate and install a linker script inplace of libc++.so. The linker script # will link libc++ to the correct ABI library. This option is on by default @@ -149,7 +151,7 @@ # is on. This option is also disabled when the ABI library is not specified # or is specified to be "none". set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE OFF) -if (LLVM_HAVE_LINK_VERSION_SCRIPT AND NOT LIBCXX_ENABLE_STATIC_ABI_LIBRARY +if (LLVM_HAVE_LINK_VERSION_SCRIPT AND NOT LIBCXX_ENABLE_STATIC_ABI_LIBRARY_FOR_SHARED AND NOT LIBCXX_CXX_ABI_LIBNAME STREQUAL "none" AND NOT LIBCXX_CXX_ABI_LIBNAME STREQUAL "default" AND PYTHONINTERP_FOUND @@ -158,7 +160,7 @@ endif() option(LIBCXX_ENABLE_ABI_LINKER_SCRIPT - "Use and install a linker script for the given ABI library" + "Use and install a linker script for the given ABI library for Shared Build" ${ENABLE_LINKER_SCRIPT_DEFAULT_VALUE}) set(ENABLE_NEW_DELETE_DEFAULT ON) @@ -303,11 +305,11 @@ endif() # Check that this option is not enabled on Apple and emit a usage warning. -if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY) +if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY_FOR_STATIC OR LIBCXX_ENABLE_STATIC_ABI_LIBRARY_FOR_SHARED) if (APPLE) - message(FATAL_ERROR "LIBCXX_ENABLE_STATIC_ABI_LIBRARY is not supported on OS X") + message(FATAL_ERROR "LIBCXX_ENABLE_STATIC_ABI_LIBRARY options are not supported on OS X") else() - message(WARNING "LIBCXX_ENABLE_STATIC_ABI_LIBRARY is an experimental option") + message(WARNING "LIBCXX_ENABLE_STATIC_ABI_LIBRARY options are experimental") endif() if (LIBCXX_ENABLE_STATIC AND NOT PYTHONINTERP_FOUND) message(FATAL_ERROR "LIBCXX_ENABLE_STATIC_ABI_LIBRARY requires python but it was not found.") @@ -326,9 +328,9 @@ endif() endif() -if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY AND LIBCXX_ENABLE_ABI_LINKER_SCRIPT) +if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY_FOR_SHARED AND LIBCXX_ENABLE_ABI_LINKER_SCRIPT) message(FATAL_ERROR "Conflicting options given. - LIBCXX_ENABLE_STATIC_ABI_LIBRARY cannot be specified with + LIBCXX_ENABLE_STATIC_ABI_LIBRARY_FOR_SHARED cannot be specified with LIBCXX_ENABLE_ABI_LINKER_SCRIPT") endif() @@ -607,14 +609,6 @@ config_define_if(LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY _LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL) config_define_if(LIBCXX_HAS_MUSL_LIBC _LIBCPP_HAS_MUSL_LIBC) -# By default libc++ on Windows expects to use a shared library, which requires -# the headers to use DLL import/export semantics. However when building a -# static library only we modify the headers to disable DLL import/export. -if (DEFINED WIN32 AND LIBCXX_ENABLE_STATIC AND NOT LIBCXX_ENABLE_SHARED) - message(STATUS "Generating custom __config for non-DLL Windows build") - config_define(ON _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) -endif() - if (LIBCXX_NEEDS_SITE_CONFIG) configure_file("include/__config_site.in" "${LIBCXX_BINARY_DIR}/__config_site" Index: lib/CMakeLists.txt =================================================================== --- lib/CMakeLists.txt +++ lib/CMakeLists.txt @@ -103,12 +103,13 @@ add_interface_library(unwind) endif() endif() - -# Setup flags. -if (NOT WIN32) - add_flags_if_supported(-fPIC) +if (MINGW) + # MINGW_LIBRARIES is defined in config-ix.cmake + list(APPEND LIBCXX_LIBRARIES ${MINGW_LIBRARIES}) endif() +# Setup flags. +add_flags_if_supported(-fPIC) add_link_flags_if_supported(-nodefaultlibs) if (LIBCXX_TARGETING_MSVC) @@ -186,12 +187,19 @@ split_list(LIBCXX_COMPILE_FLAGS) split_list(LIBCXX_LINK_FLAGS) +set(LIBCXX_TARGETS) -# Add an object library that contains the compiled source files. -add_library(cxx_objects OBJECT ${exclude_from_all} ${LIBCXX_SOURCES} ${LIBCXX_HEADERS}) -if(WIN32 AND NOT MINGW) - target_compile_definitions(cxx_objects - PRIVATE +set(LIBCXX_SHARED_COMPILE_FLAGS "") +# Build the shared library. +if (LIBCXX_ENABLE_SHARED) + # Add an object library that contains the compiled source files. + add_library(cxx_shared_objects OBJECT ${exclude_from_all} ${LIBCXX_SOURCES} ${LIBCXX_HEADERS}) + if(LIBCXX_ENABLE_STATIC_ABI_LIBRARY_FOR_SHARED) + set(LIBCXX_SHARED_COMPILE_FLAGS "-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS") + endif() + if(MSVC) + target_compile_definitions(cxx_shared_objects + PRIVATE # Ignore the -MSC_VER mismatch, as we may build # with a different compatibility version. _ALLOW_MSC_VER_MISMATCH @@ -210,18 +218,12 @@ # Use the ISO conforming behaviour for conversion # in printf, scanf. _CRT_STDIO_ISO_WIDE_SPECIFIERS) -endif() - -set_target_properties(cxx_objects - PROPERTIES - COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}" -) - -set(LIBCXX_TARGETS) - -# Build the shared library. -if (LIBCXX_ENABLE_SHARED) - add_library(cxx_shared SHARED $) + endif() + set_target_properties(cxx_shared_objects + PROPERTIES + COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS} ${LIBCXX_SHARED_COMPILE_FLAGS}" + ) + add_library(cxx_shared SHARED $) target_link_libraries(cxx_shared ${LIBCXX_LIBRARIES}) set_target_properties(cxx_shared PROPERTIES @@ -240,9 +242,43 @@ endif() endif() +set(LIBCXX_STATIC_COMPILE_FLAGS "") # Build the static library. if (LIBCXX_ENABLE_STATIC) - add_library(cxx_static STATIC $) + # Add an object library that contains the compiled source files. + add_library(cxx_static_objects OBJECT ${exclude_from_all} ${LIBCXX_SOURCES} ${LIBCXX_HEADERS}) + list(APPEND LIBCXX_STATIC_COMPILE_FLAGS "-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS") + if(LIBCXX_ENABLE_STATIC_ABI_LIBRARY_FOR_STATIC) + list(APPEND LIBCXX_STATIC_COMPILE_FLAGS "-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS") + endif() + if(MSVC) + target_compile_definitions(cxx_static_objects + PRIVATE + # Ignore the -MSC_VER mismatch, as we may build + # with a different compatibility version. + _ALLOW_MSC_VER_MISMATCH + # Don't check the msvcprt iterator debug levels + # as we will define the iterator types; libc++ + # uses a different macro to identify the debug + # level. + _ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH + # We are building the c++ runtime, don't pull in + # msvcprt. + _CRTBLD + # Don't warn on the use of "deprecated" + # "insecure" functions which are standards + # specified. + _CRT_SECURE_NO_WARNINGS + # Use the ISO conforming behaviour for conversion + # in printf, scanf. + _CRT_STDIO_ISO_WIDE_SPECIFIERS) + endif() + split_list(LIBCXX_STATIC_COMPILE_FLAGS) + set_target_properties(cxx_static_objects + PROPERTIES + COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS} ${LIBCXX_STATIC_COMPILE_FLAGS}" + ) + add_library(cxx_static STATIC $) target_link_libraries(cxx_static ${LIBCXX_LIBRARIES}) set(CMAKE_STATIC_LIBRARY_PREFIX "lib") set_target_properties(cxx_static @@ -253,7 +289,7 @@ list(APPEND LIBCXX_TARGETS "cxx_static") # Attempt to merge the libc++.a archive and the ABI library archive into one. - if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY) + if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY_FOR_STATIC) set(MERGE_ARCHIVES_SEARCH_PATHS "") if (LIBCXX_CXX_ABI_LIBRARY_PATH) set(MERGE_ARCHIVES_SEARCH_PATHS "-L${LIBCXX_CXX_ABI_LIBRARY_PATH}") Index: utils/merge_archives.py =================================================================== --- utils/merge_archives.py +++ utils/merge_archives.py @@ -118,7 +118,7 @@ execute_command_verbose([ar_exe, '-x', arc], cwd=temp_directory_root, verbose=args.verbose) - files = glob.glob(os.path.join(temp_directory_root, '*.o')) + files = glob.glob(os.path.join(temp_directory_root, '*.o*')) if not files: print_and_exit('Failed to glob for %s' % glob_path) cmd = [ar_exe, '-qc', args.output] + files