[libcxx] Support building hermetic static library
This is useful when static libc++ library is being linked into shared libraries that may be used in combination with libraries. We want to avoid we exporting libc++ symbols in those cases where this option is useful. This is provided as a CMake option and can be enabled by libc++ vendors as needed. Differential Revision: https://reviews.llvm.org/D55404 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@350489 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -283,6 +283,9 @@ endif()
|
|||||||
option(LIBCXX_CONFIGURE_IDE "Configure libcxx for use within an IDE"
|
option(LIBCXX_CONFIGURE_IDE "Configure libcxx for use within an IDE"
|
||||||
${LIBCXX_CONFIGURE_IDE_DEFAULT})
|
${LIBCXX_CONFIGURE_IDE_DEFAULT})
|
||||||
|
|
||||||
|
option(LIBCXX_HERMETIC_STATIC_LIBRARY
|
||||||
|
"Do not export any symbols from the static library." OFF)
|
||||||
|
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
# Check option configurations
|
# Check option configurations
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
|
|||||||
@@ -222,6 +222,15 @@ libc++ specific options
|
|||||||
|
|
||||||
Define libc++ destination prefix.
|
Define libc++ destination prefix.
|
||||||
|
|
||||||
|
.. option:: LIBCXX_HERMETIC_STATIC_LIBRARY:BOOL
|
||||||
|
|
||||||
|
**Default**: ``OFF``
|
||||||
|
|
||||||
|
Do not export any symbols from the static libc++ library. This is useful when
|
||||||
|
This is useful when the static libc++ library is being linked into shared
|
||||||
|
libraries that may be used in with other shared libraries that use different
|
||||||
|
C++ library. We want to avoid avoid exporting any libc++ symbols in that case.
|
||||||
|
|
||||||
.. _libc++experimental options:
|
.. _libc++experimental options:
|
||||||
|
|
||||||
libc++experimental Specific Options
|
libc++experimental Specific Options
|
||||||
|
|||||||
@@ -175,42 +175,69 @@ endif()
|
|||||||
split_list(LIBCXX_COMPILE_FLAGS)
|
split_list(LIBCXX_COMPILE_FLAGS)
|
||||||
split_list(LIBCXX_LINK_FLAGS)
|
split_list(LIBCXX_LINK_FLAGS)
|
||||||
|
|
||||||
# Add an object library that contains the compiled source files.
|
macro(cxx_object_library name)
|
||||||
add_library(cxx_objects OBJECT ${exclude_from_all} ${LIBCXX_SOURCES} ${LIBCXX_HEADERS})
|
cmake_parse_arguments(ARGS "" "" "DEFINES;FLAGS" ${ARGN})
|
||||||
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()
|
|
||||||
|
|
||||||
set_target_properties(cxx_objects
|
# Add an object library that contains the compiled source files.
|
||||||
PROPERTIES
|
add_library(${name} OBJECT ${exclude_from_all} ${LIBCXX_SOURCES} ${LIBCXX_HEADERS})
|
||||||
COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}"
|
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()
|
||||||
|
|
||||||
|
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_HERMETIC_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)
|
||||||
|
set(cxx_static_sources $<TARGET_OBJECTS:cxx_static_objects>)
|
||||||
|
set(cxx_shared_sources $<TARGET_OBJECTS:cxx_shared_objects>)
|
||||||
|
else()
|
||||||
|
cxx_object_library(cxx_objects)
|
||||||
|
set(cxx_static_sources $<TARGET_OBJECTS:cxx_objects>)
|
||||||
|
set(cxx_shared_sources $<TARGET_OBJECTS:cxx_objects>)
|
||||||
|
endif()
|
||||||
|
|
||||||
# Build the shared library.
|
# Build the shared library.
|
||||||
if (LIBCXX_ENABLE_SHARED)
|
if (LIBCXX_ENABLE_SHARED)
|
||||||
add_library(cxx_shared SHARED $<TARGET_OBJECTS:cxx_objects>)
|
add_library(cxx_shared SHARED ${cxx_shared_sources})
|
||||||
if(COMMAND llvm_setup_rpath)
|
if(COMMAND llvm_setup_rpath)
|
||||||
llvm_setup_rpath(cxx_shared)
|
llvm_setup_rpath(cxx_shared)
|
||||||
endif()
|
endif()
|
||||||
@@ -237,7 +264,7 @@ endif()
|
|||||||
|
|
||||||
# Build the static library.
|
# Build the static library.
|
||||||
if (LIBCXX_ENABLE_STATIC)
|
if (LIBCXX_ENABLE_STATIC)
|
||||||
add_library(cxx_static STATIC $<TARGET_OBJECTS:cxx_objects>)
|
add_library(cxx_static STATIC ${cxx_static_sources})
|
||||||
target_link_libraries(cxx_static ${LIBCXX_LIBRARIES})
|
target_link_libraries(cxx_static ${LIBCXX_LIBRARIES})
|
||||||
set(CMAKE_STATIC_LIBRARY_PREFIX "lib")
|
set(CMAKE_STATIC_LIBRARY_PREFIX "lib")
|
||||||
set_target_properties(cxx_static
|
set_target_properties(cxx_static
|
||||||
|
|||||||
Reference in New Issue
Block a user