Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .arcconfig

This file was deleted.

12 changes: 0 additions & 12 deletions .clang-format

This file was deleted.

177 changes: 119 additions & 58 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,49 @@ endif()

cmake_minimum_required(VERSION 3.13.4)

if(POLICY CMP0042)
cmake_policy(SET CMP0042 NEW) # Set MACOSX_RPATH=YES by default
endif()
set(LLVM_COMMON_CMAKE_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")

# Add path for custom modules
set(CMAKE_MODULE_PATH
list(INSERT CMAKE_MODULE_PATH 0
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
${CMAKE_MODULE_PATH}
"${LLVM_COMMON_CMAKE_UTILS}"
"${LLVM_COMMON_CMAKE_UTILS}/Modules"
)

set(CMAKE_FOLDER "libc++")

set(LIBCXXABI_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(LIBCXXABI_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(LIBCXXABI_LIBCXX_PATH "${CMAKE_CURRENT_LIST_DIR}/../libcxx" CACHE PATH
"Specify path to libc++ source.")

if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR LIBCXXABI_STANDALONE_BUILD)
message(WARNING "The Standalone build is deprecated in this release. Please use one of the ways "
"described at https://libcxx.llvm.org/BuildingLibcxx.html for building libc++abi.")

project(libcxxabi CXX C)

set(PACKAGE_NAME libcxxabi)
set(PACKAGE_VERSION 11.0.0git)
set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
set(PACKAGE_BUGREPORT "llvm-bugs@lists.llvm.org")

# Add the CMake module path of libcxx so we can reuse HandleOutOfTreeLLVM.cmake
set(LIBCXXABI_LIBCXX_CMAKE_PATH "${LIBCXXABI_LIBCXX_PATH}/cmake/Modules")
list(APPEND CMAKE_MODULE_PATH "${LIBCXXABI_LIBCXX_CMAKE_PATH}")
set(LIBCXXABI_STANDALONE_BUILD TRUE)

# In a standalone build, we don't have llvm to automatically generate the
# llvm-lit script for us. So we need to provide an explicit directory that
# the configurator should write the script into.
set(LIBCXXABI_STANDALONE_BUILD 1)
set(LLVM_LIT_OUTPUT_DIR "${LIBCXXABI_BINARY_DIR}/bin")
endif()

# Must go below project(..)
include(GNUInstallDirs)

if (LIBCXXABI_STANDALONE_BUILD)
# Find the LLVM sources and simulate LLVM CMake options.
include(HandleOutOfTreeLLVM)
endif()

if (LIBCXXABI_STANDALONE_BUILD)
find_package(Python3 COMPONENTS Interpreter)
if(NOT Python3_Interpreter_FOUND)
message(WARNING "Python3 not found, using python2 as a fallback")
Expand Down Expand Up @@ -84,13 +88,13 @@ option(LIBCXXABI_ENABLE_EXCEPTIONS
When disabled, libc++abi does not support stack unwinding and other exceptions-related features." ON)
option(LIBCXXABI_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON)
option(LIBCXXABI_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
option(LIBCXXABI_ENABLE_PIC "Build Position-Independent Code, even in static library" ON)
option(LIBCXXABI_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." OFF)
option(LIBCXXABI_ENABLE_STATIC_UNWINDER "Statically link the LLVM unwinder." OFF)
option(LIBCXXABI_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF)
option(LIBCXXABI_ENABLE_THREADS "Build with threads enabled" ON)
option(LIBCXXABI_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread API" OFF)
option(LIBCXXABI_HAS_WIN32_THREAD_API "Ignore auto-detection and force use of win32 thread API" OFF)
option(LIBCXXABI_HAS_EXTERNAL_THREAD_API
"Build libc++abi with an externalized threading API.
This option may only be set to ON when LIBCXXABI_ENABLE_THREADS=ON." OFF)
Expand All @@ -108,14 +112,35 @@ option(LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS
"Build libc++abi with definitions for operator new/delete. These are normally
defined in libc++abi, but it is also possible to define them in libc++, in
which case the definition in libc++abi should be turned off." ON)
option(LIBCXXABI_BUILD_32_BITS "Build 32 bit libc++abi." ${LLVM_BUILD_32_BITS})
option(LIBCXXABI_BUILD_32_BITS "Build 32 bit multilib libc++abi. This option is not supported anymore when building the runtimes. Please specify a full triple instead." ${LLVM_BUILD_32_BITS})
if (LIBCXXABI_BUILD_32_BITS)
message(FATAL_ERROR "LIBCXXABI_BUILD_32_BITS is not supported anymore when building the runtimes, please specify a full triple instead.")
endif()

option(LIBCXXABI_INCLUDE_TESTS "Generate build targets for the libc++abi unit tests." ${LLVM_INCLUDE_TESTS})
set(LIBCXXABI_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
"Define suffix of library directory name (32/64)")
option(LIBCXXABI_INSTALL_LIBRARY "Install the libc++abi library." ON)
set(LIBCXXABI_TARGET_TRIPLE "" CACHE STRING "Target triple for cross compiling.")
set(LIBCXXABI_GCC_TOOLCHAIN "" CACHE PATH "GCC toolchain for cross compiling.")
set(LIBCXXABI_SYSROOT "" CACHE PATH "Sysroot for cross compiling.")

if(NOT CMAKE_SYSROOT AND LIBCXXABI_SYSROOT)
message(WARNING "LIBCXXABI_SYSROOT is deprecated, please use CMAKE_SYSROOT instead")
endif()
if(NOT CMAKE_CXX_COMPILER_TARGET AND LIBCXXABI_TARGET_TRIPLE)
message(WARNING "LIBCXXABI_TARGET_TRIPLE is deprecated, please use CMAKE_CXX_COMPILER_TARGET instead")
endif()
if(NOT CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN AND LIBCXXABI_GCC_TOOLCHAIN)
message(WARNING "LIBCXXABI_GCC_TOOLCHAIN is deprecated, please use CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN instead")
endif()

if(CMAKE_CXX_COMPILER_TARGET)
set(LIBCXXABI_DEFAULT_TARGET_TRIPLE "${CMAKE_CXX_COMPILER_TARGET}")
else()
set(LIBCXXABI_DEFAULT_TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}")
endif()
set(LIBCXXABI_TARGET_TRIPLE "${LIBCXXABI_DEFAULT_TARGET_TRIPLE}" CACHE STRING "Target triple for cross compiling.")
set(LIBCXXABI_GCC_TOOLCHAIN "${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}" CACHE PATH "GCC toolchain for cross compiling.")
set(LIBCXXABI_SYSROOT "${CMAKE_SYSROOT}" CACHE PATH "Sysroot for cross compiling.")

set(LIBCXXABI_LIBCXX_LIBRARY_PATH "" CACHE PATH "The path to libc++ library.")
set(LIBCXXABI_LIBRARY_VERSION "1.0" CACHE STRING
"Version of libc++abi. This will be reflected in the name of the shared \
Expand Down Expand Up @@ -150,20 +175,40 @@ option(LIBCXXABI_BAREMETAL "Build libc++abi for baremetal targets." OFF)
# The default terminate handler attempts to demangle uncaught exceptions, which
# causes extra I/O and demangling code to be pulled in.
option(LIBCXXABI_SILENT_TERMINATE "Set this to make the terminate handler default to a silent alternative" OFF)
option(LIBCXXABI_NON_DEMANGLING_TERMINATE "Set this to make the terminate handler
avoid demangling" OFF)

if (NOT LIBCXXABI_ENABLE_SHARED AND NOT LIBCXXABI_ENABLE_STATIC)
message(FATAL_ERROR "libc++abi must be built as either a shared or static library.")
endif()

set(LIBCXXABI_LIBCXX_INCLUDES "${LIBCXXABI_LIBCXX_PATH}/include" CACHE PATH
# TODO: This is a workaround for the fact that Standalone builds can't use
# targets from the other runtimes (so the cxx-headers target doesn't exist).
set(LIBCXXABI_LIBCXX_INCLUDES "" CACHE PATH
"Specify path to libc++ includes.")
message(STATUS "Libc++abi will be using libc++ includes from ${LIBCXXABI_LIBCXX_INCLUDES}")
if (LIBCXXABI_STANDALONE_BUILD)
if (NOT IS_DIRECTORY ${LIBCXXABI_LIBCXX_INCLUDES})
message(FATAL_ERROR
"LIBCXXABI_LIBCXX_INCLUDES=${LIBCXXABI_LIBCXX_INCLUDES} is not a valid directory. "
"Please provide the path to where the libc++ headers have been installed.")
endif()
add_library(cxx-headers INTERFACE)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" OR "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC")
target_compile_options(cxx-headers INTERFACE /I "${LIBCXXABI_LIBCXX_INCLUDES}")
else()
target_compile_options(cxx-headers INTERFACE -I "${LIBCXXABI_LIBCXX_INCLUDES}")
endif()
endif()

option(LIBCXXABI_HERMETIC_STATIC_LIBRARY
"Do not export any symbols from the static library." OFF)

set(LIBCXXABI_TEST_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/test/lit.site.cfg.in" CACHE STRING
"The Lit testing configuration to use when running the tests.")
"The path to the Lit testing configuration to use when running the tests.
If a relative path is provided, it is assumed to be relative to '<monorepo>/libcxxabi/test/configs'.")
if (NOT IS_ABSOLUTE "${LIBCXXABI_TEST_CONFIG}")
set(LIBCXXABI_TEST_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/test/configs/${LIBCXXABI_TEST_CONFIG}")
endif()
set(LIBCXXABI_TEST_PARAMS "" CACHE STRING
"A list of parameters to run the Lit test suite with.")

Expand All @@ -178,23 +223,30 @@ set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
)

set(LIBCXXABI_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH
"Path where built libc++abi runtime libraries should be installed.")

if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++)
set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++)
set(LIBCXXABI_HEADER_DIR ${LLVM_BINARY_DIR})
set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE})
set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH
"Path where built libc++abi libraries should be installed.")
if(LIBCXX_LIBDIR_SUBDIR)
string(APPEND LIBCXXABI_LIBRARY_DIR /${LIBCXXABI_LIBDIR_SUBDIR})
string(APPEND LIBCXXABI_INSTALL_LIBRARY_DIR /${LIBCXXABI_LIBDIR_SUBDIR})
endif()
elseif(LLVM_LIBRARY_OUTPUT_INTDIR)
set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LIBCXXABI_LIBDIR_SUFFIX})
else()
set(LIBCXXABI_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXXABI_LIBDIR_SUFFIX})
set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LIBCXXABI_LIBDIR_SUFFIX})
if(LLVM_LIBRARY_OUTPUT_INTDIR)
set(LIBCXXABI_HEADER_DIR ${LLVM_BINARY_DIR})
set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
else()
set(LIBCXXABI_HEADER_DIR ${CMAKE_BINARY_DIR})
set(LIBCXXABI_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXXABI_LIBDIR_SUFFIX})
endif()
set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LIBCXXABI_LIBDIR_SUFFIX} CACHE PATH
"Path where built libc++abi libraries should be installed.")
endif()

set(LIBCXXABI_INSTALL_PREFIX "" CACHE STRING "Define libc++abi destination prefix.")

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBCXXABI_LIBRARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBCXXABI_LIBRARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIBCXXABI_LIBRARY_DIR})
Expand All @@ -206,15 +258,6 @@ if (NOT LIBCXXABI_LIBCXX_LIBRARY_PATH)
"The path to libc++ library." FORCE)
endif()

# Check that we can build with 32 bits if requested.
if (CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32)
if (LIBCXXABI_BUILD_32_BITS AND NOT LLVM_BUILD_32_BITS) # Don't duplicate the output from LLVM
message(STATUS "Building 32 bits executables and libraries.")
endif()
elseif(LIBCXXABI_BUILD_32_BITS)
message(FATAL_ERROR "LIBCXXABI_BUILD_32_BITS=ON is not supported on this platform.")
endif()

# Declare libc++abi configuration variables.
# They are intended for use as follows:
# LIBCXXABI_C_FLAGS: General flags for both the c++ compiler and linker.
Expand All @@ -237,26 +280,17 @@ include(HandleLibcxxabiFlags)
#===============================================================================

# Configure target flags
add_target_flags_if(LIBCXXABI_BUILD_32_BITS "-m32")

if(ZOS)
add_target_flags_if_supported("-fzos-le-char-mode=ebcdic")
endif()
if(LIBCXXABI_TARGET_TRIPLE)
add_target_flags("--target=${LIBCXXABI_TARGET_TRIPLE}")
elseif(CMAKE_CXX_COMPILER_TARGET)
set(LIBCXXABI_TARGET_TRIPLE "${CMAKE_CXX_COMPILER_TARGET}")
add_target_flags_if_supported("--target=${LIBCXXABI_TARGET_TRIPLE}")
endif()
if(LIBCXX_GCC_TOOLCHAIN)
add_target_flags("--gcc-toolchain=${LIBCXXABI_GCC_TOOLCHAIN}")
elseif(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN)
set(LIBCXXABI_GCC_TOOLCHAIN "${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}")
if(LIBCXXABI_GCC_TOOLCHAIN)
add_target_flags_if_supported("--gcc-toolchain=${LIBCXXABI_GCC_TOOLCHAIN}")
endif()
if(LIBCXXABI_SYSROOT)
add_target_flags("--sysroot=${LIBCXXABI_SYSROOT}")
elseif(CMAKE_SYSROOT)
set(LIBCXXABI_SYSROOT "${CMAKE_SYSROOT}")
endif()

if (LIBCXXABI_TARGET_TRIPLE)
set(TARGET_TRIPLE "${LIBCXXABI_TARGET_TRIPLE}")
add_target_flags_if_supported("--sysroot=${LIBCXXABI_SYSROOT}")
endif()

# Configure compiler. Must happen after setting the target flags.
Expand Down Expand Up @@ -374,6 +408,11 @@ if (NOT LIBCXXABI_ENABLE_THREADS)
" be set to ON when LIBCXXABI_ENABLE_THREADS"
" is also set to ON.")
endif()
if (LIBCXXABI_HAS_WIN32_THREAD_API)
message(FATAL_ERROR "LIBCXXABI_HAS_WIN32_THREAD_API can only"
" be set to ON when LIBCXXABI_ENABLE_THREADS"
" is also set to ON.")
endif()
if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
message(FATAL_ERROR "LIBCXXABI_HAS_EXTERNAL_THREAD_API can only"
" be set to ON when LIBCXXABI_ENABLE_THREADS"
Expand All @@ -385,7 +424,6 @@ if (NOT LIBCXXABI_ENABLE_THREADS)
" is also set to ON.")
endif()
add_definitions(-D_LIBCXXABI_HAS_NO_THREADS)
add_definitions(-D_LIBCPP_HAS_NO_THREADS)
endif()

if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
Expand All @@ -394,13 +432,26 @@ if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
" and LIBCXXABI_HAS_PTHREAD_API cannot be both"
" set to ON at the same time.")
endif()
if (LIBCXXABI_HAS_WIN32_THREAD_API)
message(FATAL_ERROR "The options LIBCXXABI_HAS_EXTERNAL_THREAD_API"
" and LIBCXXABI_HAS_WIN32_THREAD_API cannot be both"
" set to ON at the same time.")
endif()
if (LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY)
message(FATAL_ERROR "The options LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY"
" and LIBCXXABI_HAS_EXTERNAL_THREAD_API cannot be both"
" set to ON at the same time.")
endif()
endif()

if (LIBCXXABI_HAS_PTHREAD_API)
if (LIBCXXABI_HAS_WIN32_THREAD_API)
message(FATAL_ERROR "The options LIBCXXABI_HAS_PTHREAD_API"
"and LIBCXXABI_HAS_WIN32_THREAD_API cannot be both"
"set to ON at the same time.")
endif()
endif()

if (LLVM_ENABLE_MODULES)
# Ignore that the rest of the modules flags are now unused.
add_compile_flags_if_supported(-Wno-unused-command-line-argument)
Expand Down Expand Up @@ -428,6 +479,10 @@ if (LIBCXXABI_HAS_PTHREAD_API)
add_definitions(-D_LIBCPP_HAS_THREAD_API_PTHREAD)
endif()

if (LIBCXXABI_HAS_WIN32_THREAD_API)
add_definitions(-D_LIBCPP_HAS_THREAD_API_WIN32)
endif()

if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
add_definitions(-D_LIBCPP_HAS_THREAD_API_EXTERNAL)
endif()
Expand All @@ -439,10 +494,6 @@ endif()
# Prevent libc++abi from having library dependencies on libc++
add_definitions(-D_LIBCPP_DISABLE_EXTERN_TEMPLATE)

# Bring back `std::unexpected`, which is removed in C++17, to support
# pre-C++17.
add_definitions(-D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS)

if (MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif()
Expand All @@ -456,6 +507,10 @@ if (LIBCXXABI_SILENT_TERMINATE)
add_definitions(-DLIBCXXABI_SILENT_TERMINATE)
endif()

if (LIBCXXABI_NON_DEMANGLING_TERMINATE)
add_definitions(-DLIBCXXABI_NON_DEMANGLING_TERMINATE)
endif()

if (LIBCXXABI_BAREMETAL)
add_definitions(-DLIBCXXABI_BAREMETAL)
endif()
Expand All @@ -470,6 +525,12 @@ string(REPLACE ";" " " LIBCXXABI_CXX_FLAGS "${LIBCXXABI_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LIBCXXABI_CXX_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBCXXABI_C_FLAGS}")

# On AIX, avoid picking up VMX extensions(i.e. vec_malloc) which would change
# the default alignment of the allocators here.
if (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "AIX")
add_definitions("-D_XOPEN_SOURCE=700")
endif()

#===============================================================================
# Setup Source Code
#===============================================================================
Expand Down
Loading