mirror of
https://github.com/darlinghq/darling-libcxx.git
synced 2024-11-23 11:59:52 +00:00
[libc++] Use functions instead of global variables to set libc++ build flags
This commit follows the trend of doing things per-target instead of modifying the C++ flags globally. It does so for visibility-related flags, other basic build flags and Windows-specific flags. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@373517 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
6035dc6838
commit
48a15a7b3a
109
CMakeLists.txt
109
CMakeLists.txt
@ -522,50 +522,60 @@ remove_flags("/D_DEBUG" "/MTd" "/MDd" "/MT" "/Md")
|
|||||||
remove_flags(-Wno-pedantic -pedantic-errors -pedantic)
|
remove_flags(-Wno-pedantic -pedantic-errors -pedantic)
|
||||||
|
|
||||||
# Required flags ==============================================================
|
# Required flags ==============================================================
|
||||||
if (LIBCXX_HAS_MUSL_LIBC OR LIBCXX_TARGETING_CLANG_CL)
|
function(cxx_add_basic_build_flags target)
|
||||||
# musl's pthread implementations uses volatile types in their structs which is
|
if (LIBCXX_HAS_MUSL_LIBC OR LIBCXX_TARGETING_CLANG_CL)
|
||||||
# not a constexpr in C++11 but is in C++14, so we use C++14 with musl.
|
# musl's pthread implementations uses volatile types in their structs which is
|
||||||
set(LIBCXX_STANDARD_VER c++14 CACHE STRING "internal option to change build dialect")
|
# not a constexpr in C++11 but is in C++14, so we use C++14 with musl.
|
||||||
else()
|
set(LIBCXX_STANDARD_VER c++14 CACHE STRING "internal option to change build dialect")
|
||||||
set(LIBCXX_STANDARD_VER c++11 CACHE STRING "internal option to change build dialect")
|
else()
|
||||||
endif()
|
set(LIBCXX_STANDARD_VER c++11 CACHE STRING "internal option to change build dialect")
|
||||||
add_compile_flags_if_supported(-std=${LIBCXX_STANDARD_VER})
|
endif()
|
||||||
add_compile_flags_if_supported("/std:${LIBCXX_STANDARD_VER}")
|
target_add_compile_flags_if_supported(${target} PRIVATE -std=${LIBCXX_STANDARD_VER})
|
||||||
mangle_name("LIBCXX_SUPPORTS_STD_EQ_${LIBCXX_STANDARD_VER}_FLAG" SUPPORTS_DIALECT_NAME)
|
target_add_compile_flags_if_supported(${target} PRIVATE "/std:${LIBCXX_STANDARD_VER}")
|
||||||
mangle_name("LIBCXX_SUPPORTS_STD_COLON_${LIBCXX_STANDARD_VER}_FLAG" SUPPORTS_DIALECT_NAME_MSVC)
|
mangle_name("LIBCXX_SUPPORTS_STD_EQ_${LIBCXX_STANDARD_VER}_FLAG" SUPPORTS_DIALECT_NAME)
|
||||||
if(NOT ${SUPPORTS_DIALECT_NAME} AND NOT ${SUPPORTS_DIALECT_NAME_MSVC})
|
mangle_name("LIBCXX_SUPPORTS_STD_COLON_${LIBCXX_STANDARD_VER}_FLAG" SUPPORTS_DIALECT_NAME_MSVC)
|
||||||
if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" AND NOT "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC")
|
if(NOT ${SUPPORTS_DIALECT_NAME} AND NOT ${SUPPORTS_DIALECT_NAME_MSVC})
|
||||||
message(FATAL_ERROR "C++11 or greater is required but the compiler does not support ${LIBCXX_STANDARD_VER}")
|
if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" AND NOT "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC")
|
||||||
|
message(FATAL_ERROR "C++11 or greater is required but the compiler does not support ${LIBCXX_STANDARD_VER}")
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
endif()
|
|
||||||
|
|
||||||
# On all systems the system c++ standard library headers need to be excluded.
|
# On all systems the system c++ standard library headers need to be excluded.
|
||||||
# MSVC only has -X, which disables all default includes; including the crt.
|
# MSVC only has -X, which disables all default includes; including the crt.
|
||||||
# Thus, we do nothing and hope we don't accidentally include any of the C++
|
# Thus, we do nothing and hope we don't accidentally include any of the C++
|
||||||
# headers
|
# headers
|
||||||
add_compile_flags_if_supported(-nostdinc++)
|
target_add_compile_flags_if_supported(${target} PUBLIC -nostdinc++)
|
||||||
|
|
||||||
# Hide all inline function definitions which have not explicitly been marked
|
# Hide all inline function definitions which have not explicitly been marked
|
||||||
# visible. This prevents new definitions for inline functions from appearing in
|
# visible. This prevents new definitions for inline functions from appearing in
|
||||||
# the dylib when get ODR used by another function.
|
# the dylib when get ODR used by another function.
|
||||||
add_compile_flags_if_supported(-fvisibility-inlines-hidden)
|
target_add_compile_flags_if_supported(${target} PRIVATE -fvisibility-inlines-hidden)
|
||||||
|
|
||||||
if (LIBCXX_CONFIGURE_IDE)
|
# Our visibility annotations are not quite right for non-Clang compilers,
|
||||||
# This simply allows IDE to process <experimental/coroutine>
|
# so we end up not exporting all the symbols we should. In the future, we
|
||||||
add_compile_flags_if_supported(-fcoroutines-ts)
|
# can improve the situation by providing an explicit list of exported
|
||||||
endif()
|
# symbols on all compilers.
|
||||||
|
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||||
|
target_add_compile_flags_if_supported(${target} PRIVATE -fvisibility=hidden)
|
||||||
|
endif()
|
||||||
|
|
||||||
# Let the library headers know they are currently being used to build the
|
if (LIBCXX_CONFIGURE_IDE)
|
||||||
# library.
|
# This simply allows IDE to process <experimental/coroutine>
|
||||||
add_definitions(-D_LIBCPP_BUILDING_LIBRARY)
|
target_add_compile_flags_if_supported(${target} PRIVATE -fcoroutines-ts)
|
||||||
|
endif()
|
||||||
|
|
||||||
if (NOT LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS)
|
# Let the library headers know they are currently being used to build the
|
||||||
add_definitions(-D_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS)
|
# library.
|
||||||
endif()
|
target_compile_definitions(${target} PRIVATE -D_LIBCPP_BUILDING_LIBRARY)
|
||||||
|
|
||||||
if (LIBCXX_HAS_COMMENT_LIB_PRAGMA)
|
if (NOT LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS)
|
||||||
add_definitions(-D_LIBCPP_HAS_COMMENT_LIB_PRAGMA)
|
target_compile_definitions(${target} PRIVATE -D_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if (LIBCXX_HAS_COMMENT_LIB_PRAGMA)
|
||||||
|
target_compile_definitions(${target} PRIVATE -D_LIBCPP_HAS_COMMENT_LIB_PRAGMA)
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
# Warning flags ===============================================================
|
# Warning flags ===============================================================
|
||||||
function(cxx_add_warning_flags target)
|
function(cxx_add_warning_flags target)
|
||||||
@ -714,6 +724,31 @@ if (LIBCXX_STANDALONE_BUILD AND SANITIZER_FLAGS)
|
|||||||
add_flags(${SANITIZER_FLAGS})
|
add_flags(${SANITIZER_FLAGS})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# Windows-related flags =======================================================
|
||||||
|
function(cxx_add_windows_flags target)
|
||||||
|
if(WIN32 AND NOT MINGW)
|
||||||
|
target_compile_definitions(${target} 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()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
# Configuration file flags =====================================================
|
# Configuration file flags =====================================================
|
||||||
if (NOT LIBCXX_ABI_VERSION EQUAL 1)
|
if (NOT LIBCXX_ABI_VERSION EQUAL 1)
|
||||||
config_define(${LIBCXX_ABI_VERSION} _LIBCPP_ABI_VERSION)
|
config_define(${LIBCXX_ABI_VERSION} _LIBCPP_ABI_VERSION)
|
||||||
|
@ -204,35 +204,6 @@ function(cxx_set_common_defines name)
|
|||||||
if(LIBCXX_CXX_ABI_HEADER_TARGET)
|
if(LIBCXX_CXX_ABI_HEADER_TARGET)
|
||||||
add_dependencies(${name} ${LIBCXX_CXX_ABI_HEADER_TARGET})
|
add_dependencies(${name} ${LIBCXX_CXX_ABI_HEADER_TARGET})
|
||||||
endif()
|
endif()
|
||||||
# Our visibility annotations are not quite right for non-Clang compilers,
|
|
||||||
# so we end up not exporting all the symbols we should. In the future, we
|
|
||||||
# can improve the situation by providing an explicit list of exported
|
|
||||||
# symbols on all compilers.
|
|
||||||
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
|
||||||
target_compile_options(${name} PRIVATE -fvisibility=hidden)
|
|
||||||
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 (LIBCXX_ENABLE_PARALLEL_ALGORITHMS)
|
if (LIBCXX_ENABLE_PARALLEL_ALGORITHMS)
|
||||||
target_link_libraries(${name} PUBLIC pstl::ParallelSTL)
|
target_link_libraries(${name} PUBLIC pstl::ParallelSTL)
|
||||||
@ -259,8 +230,10 @@ if (LIBCXX_ENABLE_SHARED)
|
|||||||
SOVERSION "${LIBCXX_ABI_VERSION}"
|
SOVERSION "${LIBCXX_ABI_VERSION}"
|
||||||
DEFINE_SYMBOL ""
|
DEFINE_SYMBOL ""
|
||||||
)
|
)
|
||||||
|
cxx_add_basic_build_flags(cxx_shared)
|
||||||
cxx_set_common_defines(cxx_shared)
|
cxx_set_common_defines(cxx_shared)
|
||||||
cxx_add_warning_flags(cxx_shared)
|
cxx_add_warning_flags(cxx_shared)
|
||||||
|
cxx_add_windows_flags(cxx_shared)
|
||||||
|
|
||||||
# Link against LLVM libunwind
|
# Link against LLVM libunwind
|
||||||
if (LIBCXXABI_USE_LLVM_UNWINDER)
|
if (LIBCXXABI_USE_LLVM_UNWINDER)
|
||||||
@ -360,8 +333,10 @@ if (LIBCXX_ENABLE_STATIC)
|
|||||||
LINK_FLAGS "${LIBCXX_LINK_FLAGS}"
|
LINK_FLAGS "${LIBCXX_LINK_FLAGS}"
|
||||||
OUTPUT_NAME "c++"
|
OUTPUT_NAME "c++"
|
||||||
)
|
)
|
||||||
|
cxx_add_basic_build_flags(cxx_static)
|
||||||
cxx_set_common_defines(cxx_static)
|
cxx_set_common_defines(cxx_static)
|
||||||
cxx_add_warning_flags(cxx_static)
|
cxx_add_warning_flags(cxx_static)
|
||||||
|
cxx_add_windows_flags(cxx_static)
|
||||||
|
|
||||||
if (LIBCXX_HERMETIC_STATIC_LIBRARY)
|
if (LIBCXX_HERMETIC_STATIC_LIBRARY)
|
||||||
# If the hermetic library doesn't define the operator new/delete functions
|
# If the hermetic library doesn't define the operator new/delete functions
|
||||||
|
Loading…
Reference in New Issue
Block a user