Index: libcxx/CMakeLists.txt =================================================================== --- libcxx/CMakeLists.txt +++ libcxx/CMakeLists.txt @@ -283,6 +283,9 @@ option(LIBCXX_CONFIGURE_IDE "Configure libcxx for use within an IDE" ${LIBCXX_CONFIGURE_IDE_DEFAULT}) +option(LIBCXX_HIDDEN_VISIBILITY_IN_STATIC_LIBRARY + "Use hidden visibility when building the static library." OFF) + #=============================================================================== # Check option configurations #=============================================================================== Index: libcxx/lib/CMakeLists.txt =================================================================== --- libcxx/lib/CMakeLists.txt +++ libcxx/lib/CMakeLists.txt @@ -175,42 +175,69 @@ split_list(LIBCXX_COMPILE_FLAGS) split_list(LIBCXX_LINK_FLAGS) -# Add an object library that contains the compiled source files. -add_library(cxx_objects OBJECT ${exclude_from_all} ${LIBCXX_SOURCES} ${LIBCXX_HEADERS}) -if(LIBCXX_CXX_ABI_HEADER_TARGET) - add_dependencies(cxx_objects ${LIBCXX_CXX_ABI_HEADER_TARGET}) -endif() -if(WIN32 AND NOT MINGW) - target_compile_definitions(cxx_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() +macro(cxx_object_library name) + cmake_parse_arguments(ARGS "" "" "DEFINES;FLAGS" ${ARGN}) + + # Add an object library that contains the compiled source files. + add_library(${name} OBJECT ${exclude_from_all} ${LIBCXX_SOURCES} ${LIBCXX_HEADERS}) + if(LIBCXX_CXX_ABI_HEADER_TARGET) + add_dependencies(${name} ${LIBCXX_CXX_ABI_HEADER_TARGET}) + endif() + if(WIN32 AND NOT MINGW) + target_compile_definitions(${name} + 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() -set_target_properties(cxx_objects - PROPERTIES - COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}" -) + if(ARGS_DEFINES) + target_compile_definitions(${name} PRIVATE ${ARGS_DEFINES}) + endif() + + set_target_properties(${name} + PROPERTIES + COMPILE_FLAGS ${LIBCXX_COMPILE_FLAGS} + ) + + if(ARGS_FLAGS) + target_compile_options(${name} PRIVATE ${ARGS_FLAGS}) + endif() +endmacro() + +if(LIBCXX_HIDDEN_VISIBILITY_IN_STATIC_LIBRARY) + append_flags_if_supported(CXX_STATIC_OBJECTS_FLAGS -fvisibility=hidden) + append_flags_if_supported(CXX_STATIC_OBJECTS_FLAGS -fvisibility-global-new-delete-hidden) + cxx_object_library(cxx_static_objects + DEFINES _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS + FLAGS ${CXX_STATIC_OBJECTS_FLAGS}) + cxx_object_library(cxx_shared_objects) +else() + cxx_object_library(cxx_objects) +endif() # Build the shared library. if (LIBCXX_ENABLE_SHARED) - add_library(cxx_shared SHARED $) + if(LIBCXX_HIDDEN_VISIBILITY_IN_STATIC_LIBRARY) + add_library(cxx_shared SHARED $) + else() + add_library(cxx_shared SHARED $) + endif() if(COMMAND llvm_setup_rpath) llvm_setup_rpath(cxx_shared) endif() @@ -237,7 +264,11 @@ # Build the static library. if (LIBCXX_ENABLE_STATIC) - add_library(cxx_static STATIC $) + if(LIBCXX_HIDDEN_VISIBILITY_IN_STATIC_LIBRARY) + add_library(cxx_static STATIC $) + else() + add_library(cxx_static STATIC $) + endif() target_link_libraries(cxx_static ${LIBCXX_LIBRARIES}) set(CMAKE_STATIC_LIBRARY_PREFIX "lib") set_target_properties(cxx_static