Index: libcxxabi/trunk/CMakeLists.txt =================================================================== --- libcxxabi/trunk/CMakeLists.txt +++ libcxxabi/trunk/CMakeLists.txt @@ -155,6 +155,9 @@ set(LIBCXXABI_LIBCXX_PATH "${LIBCXXABI_LIBCXX_PATH}" CACHE PATH "Specify path to libc++ source." FORCE) +option(LIBCXXABI_HERMETIC_STATIC_LIBRARY + "Do not export any symbols from the static library." OFF) + #=============================================================================== # Configure System #=============================================================================== Index: libcxxabi/trunk/cmake/Modules/HandleLibcxxabiFlags.cmake =================================================================== --- libcxxabi/trunk/cmake/Modules/HandleLibcxxabiFlags.cmake +++ libcxxabi/trunk/cmake/Modules/HandleLibcxxabiFlags.cmake @@ -44,6 +44,29 @@ check_cxx_compiler_flag("${flag}" "LIBCXXABI_SUPPORTS_${flagname}_FLAG") endmacro() +macro(append_flags DEST) + foreach(value ${ARGN}) + list(APPEND ${DEST} ${value}) + list(APPEND ${DEST} ${value}) + endforeach() +endmacro() + +# If the specified 'condition' is true then append the specified list of flags to DEST +macro(append_flags_if condition DEST) + if (${condition}) + list(APPEND ${DEST} ${ARGN}) + endif() +endmacro() + +# Add each flag in the list specified by DEST if that flag is supported by the current compiler. +macro(append_flags_if_supported DEST) + foreach(flag ${ARGN}) + mangle_name("${flag}" flagname) + check_cxx_compiler_flag("${flag}" "LIBCXXABI_SUPPORTS_${flagname}_FLAG") + append_flags_if(LIBCXXABI_SUPPORTS_${flagname}_FLAG ${DEST} ${flag}) + endforeach() +endmacro() + # Add a macro definition if condition is true. macro(define_if condition def) if (${condition}) Index: libcxxabi/trunk/src/CMakeLists.txt =================================================================== --- libcxxabi/trunk/src/CMakeLists.txt +++ libcxxabi/trunk/src/CMakeLists.txt @@ -139,24 +139,53 @@ string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}") endif() -# Add a object library that contains the compiled source files. -add_library(cxxabi_objects OBJECT ${LIBCXXABI_SOURCES} ${LIBCXXABI_HEADERS}) -set_target_properties(cxxabi_objects - PROPERTIES - CXX_EXTENSIONS - OFF - CXX_STANDARD - 11 - CXX_STANDARD_REQUIRED - ON - COMPILE_FLAGS - "${LIBCXXABI_COMPILE_FLAGS}" - POSITION_INDEPENDENT_CODE - ON) +macro(cxxabi_object_library name) + cmake_parse_arguments(ARGS "" "" "DEFINES;FLAGS" ${ARGN}) + + # Add a object library that contains the compiled source files. + add_library(${name} OBJECT ${LIBCXXABI_SOURCES} ${LIBCXXABI_HEADERS}) + set_target_properties(${name} + PROPERTIES + CXX_EXTENSIONS + OFF + CXX_STANDARD + 11 + CXX_STANDARD_REQUIRED + ON + COMPILE_FLAGS + "${LIBCXXABI_COMPILE_FLAGS}" + POSITION_INDEPENDENT_CODE + ON) + + if(ARGS_DEFINES) + target_compile_definitions(${name} PRIVATE ${ARGS_DEFINES}) + endif() + + if(ARGS_FLAGS) + target_compile_options(${name} PRIVATE ${ARGS_FLAGS}) + endif() +endmacro() + +if(LIBCXXABI_HERMETIC_STATIC_LIBRARY) + append_flags_if_supported(CXXABI_STATIC_OBJECTS_FLAGS -fvisibility=hidden) + append_flags_if_supported(CXXABI_STATIC_OBJECTS_FLAGS -fvisibility-global-new-delete-hidden) + cxxabi_object_library(cxxabi_static_objects + DEFINES + _LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS + _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS + FLAGS ${CXXABI_STATIC_OBJECTS_FLAGS}) + cxxabi_object_library(cxxabi_shared_objects) + set(cxxabi_static_sources $) + set(cxxabi_shared_sources $) +else() + cxxabi_object_library(cxxabi_objects) + set(cxxabi_static_sources $) + set(cxxabi_shared_sources $) +endif() # Build the shared library. if (LIBCXXABI_ENABLE_SHARED) - add_library(cxxabi_shared SHARED $) + add_library(cxxabi_shared SHARED ${cxxabi_shared_sources}) if(COMMAND llvm_setup_rpath) llvm_setup_rpath(cxxabi_shared) endif() @@ -187,7 +216,6 @@ # Build the static library. if (LIBCXXABI_ENABLE_STATIC) - set(cxxabi_static_sources $) if (LIBCXXABI_USE_LLVM_UNWINDER AND LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY) if (TARGET unwind_static OR HAVE_LIBUNWIND) list(APPEND cxxabi_static_sources $)