@@ -10,45 +10,49 @@ endif()
1010
1111cmake_minimum_required (VERSION 3.13.4)
1212
13- if (POLICY CMP0042)
14- cmake_policy (SET CMP0042 NEW) # Set MACOSX_RPATH=YES by default
15- endif ()
13+ set (LLVM_COMMON_CMAKE_UTILS "${CMAKE_CURRENT_SOURCE_DIR} /../cmake" )
1614
1715# Add path for custom modules
18- set ( CMAKE_MODULE_PATH
16+ list ( INSERT CMAKE_MODULE_PATH 0
1917 "${CMAKE_CURRENT_SOURCE_DIR} /cmake"
2018 "${CMAKE_CURRENT_SOURCE_DIR} /cmake/Modules"
21- ${CMAKE_MODULE_PATH}
19+ "${LLVM_COMMON_CMAKE_UTILS} "
20+ "${LLVM_COMMON_CMAKE_UTILS} /Modules"
2221 )
2322
23+ set (CMAKE_FOLDER "libc++" )
24+
2425set (LIBCXXABI_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} )
2526set (LIBCXXABI_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} )
2627set (LIBCXXABI_LIBCXX_PATH "${CMAKE_CURRENT_LIST_DIR} /../libcxx" CACHE PATH
2728 "Specify path to libc++ source." )
2829
2930if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR LIBCXXABI_STANDALONE_BUILD)
31+ message (WARNING "The Standalone build is deprecated in this release. Please use one of the ways "
32+ "described at https://libcxx.llvm.org/BuildingLibcxx.html for building libc++abi." )
33+
3034 project (libcxxabi CXX C)
3135
3236 set (PACKAGE_NAME libcxxabi)
3337 set (PACKAGE_VERSION 11.0.0git)
3438 set (PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION} " )
3539 set (PACKAGE_BUGREPORT "llvm-bugs@lists.llvm.org" )
3640
37- # Add the CMake module path of libcxx so we can reuse HandleOutOfTreeLLVM.cmake
38- set (LIBCXXABI_LIBCXX_CMAKE_PATH "${LIBCXXABI_LIBCXX_PATH} /cmake/Modules" )
39- list (APPEND CMAKE_MODULE_PATH "${LIBCXXABI_LIBCXX_CMAKE_PATH} " )
41+ set (LIBCXXABI_STANDALONE_BUILD TRUE )
4042
4143 # In a standalone build, we don't have llvm to automatically generate the
4244 # llvm-lit script for us. So we need to provide an explicit directory that
4345 # the configurator should write the script into.
44- set (LIBCXXABI_STANDALONE_BUILD 1)
4546 set (LLVM_LIT_OUTPUT_DIR "${LIBCXXABI_BINARY_DIR} /bin" )
47+ endif ()
48+
49+ # Must go below project(..)
50+ include (GNUInstallDirs)
4651
52+ if (LIBCXXABI_STANDALONE_BUILD)
4753 # Find the LLVM sources and simulate LLVM CMake options.
4854 include (HandleOutOfTreeLLVM)
49- endif ()
5055
51- if (LIBCXXABI_STANDALONE_BUILD)
5256 find_package (Python3 COMPONENTS Interpreter)
5357 if (NOT Python3_Interpreter_FOUND)
5458 message (WARNING "Python3 not found, using python2 as a fallback" )
@@ -84,13 +88,13 @@ option(LIBCXXABI_ENABLE_EXCEPTIONS
8488 When disabled, libc++abi does not support stack unwinding and other exceptions-related features." ON )
8589option (LIBCXXABI_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON )
8690option (LIBCXXABI_ENABLE_PEDANTIC "Compile with pedantic enabled." ON )
87- option (LIBCXXABI_ENABLE_PIC "Build Position-Independent Code, even in static library" ON )
8891option (LIBCXXABI_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF )
8992option (LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." OFF )
9093option (LIBCXXABI_ENABLE_STATIC_UNWINDER "Statically link the LLVM unwinder." OFF )
9194option (LIBCXXABI_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF )
9295option (LIBCXXABI_ENABLE_THREADS "Build with threads enabled" ON )
9396option (LIBCXXABI_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread API" OFF )
97+ option (LIBCXXABI_HAS_WIN32_THREAD_API "Ignore auto-detection and force use of win32 thread API" OFF )
9498option (LIBCXXABI_HAS_EXTERNAL_THREAD_API
9599 "Build libc++abi with an externalized threading API.
96100 This option may only be set to ON when LIBCXXABI_ENABLE_THREADS=ON." OFF )
@@ -108,14 +112,35 @@ option(LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS
108112 "Build libc++abi with definitions for operator new/delete. These are normally
109113 defined in libc++abi, but it is also possible to define them in libc++, in
110114 which case the definition in libc++abi should be turned off." ON )
111- option (LIBCXXABI_BUILD_32_BITS "Build 32 bit libc++abi." ${LLVM_BUILD_32_BITS} )
115+ 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} )
116+ if (LIBCXXABI_BUILD_32_BITS)
117+ message (FATAL_ERROR "LIBCXXABI_BUILD_32_BITS is not supported anymore when building the runtimes, please specify a full triple instead." )
118+ endif ()
119+
112120option (LIBCXXABI_INCLUDE_TESTS "Generate build targets for the libc++abi unit tests." ${LLVM_INCLUDE_TESTS} )
113121set (LIBCXXABI_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX} " CACHE STRING
114122 "Define suffix of library directory name (32/64)" )
115123option (LIBCXXABI_INSTALL_LIBRARY "Install the libc++abi library." ON )
116- set (LIBCXXABI_TARGET_TRIPLE "" CACHE STRING "Target triple for cross compiling." )
117- set (LIBCXXABI_GCC_TOOLCHAIN "" CACHE PATH "GCC toolchain for cross compiling." )
118- set (LIBCXXABI_SYSROOT "" CACHE PATH "Sysroot for cross compiling." )
124+
125+ if (NOT CMAKE_SYSROOT AND LIBCXXABI_SYSROOT)
126+ message (WARNING "LIBCXXABI_SYSROOT is deprecated, please use CMAKE_SYSROOT instead" )
127+ endif ()
128+ if (NOT CMAKE_CXX_COMPILER_TARGET AND LIBCXXABI_TARGET_TRIPLE)
129+ message (WARNING "LIBCXXABI_TARGET_TRIPLE is deprecated, please use CMAKE_CXX_COMPILER_TARGET instead" )
130+ endif ()
131+ if (NOT CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN AND LIBCXXABI_GCC_TOOLCHAIN)
132+ message (WARNING "LIBCXXABI_GCC_TOOLCHAIN is deprecated, please use CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN instead" )
133+ endif ()
134+
135+ if (CMAKE_CXX_COMPILER_TARGET)
136+ set (LIBCXXABI_DEFAULT_TARGET_TRIPLE "${CMAKE_CXX_COMPILER_TARGET} " )
137+ else ()
138+ set (LIBCXXABI_DEFAULT_TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE} " )
139+ endif ()
140+ set (LIBCXXABI_TARGET_TRIPLE "${LIBCXXABI_DEFAULT_TARGET_TRIPLE} " CACHE STRING "Target triple for cross compiling." )
141+ set (LIBCXXABI_GCC_TOOLCHAIN "${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN} " CACHE PATH "GCC toolchain for cross compiling." )
142+ set (LIBCXXABI_SYSROOT "${CMAKE_SYSROOT} " CACHE PATH "Sysroot for cross compiling." )
143+
119144set (LIBCXXABI_LIBCXX_LIBRARY_PATH "" CACHE PATH "The path to libc++ library." )
120145set (LIBCXXABI_LIBRARY_VERSION "1.0" CACHE STRING
121146"Version of libc++abi. This will be reflected in the name of the shared \
@@ -150,20 +175,40 @@ option(LIBCXXABI_BAREMETAL "Build libc++abi for baremetal targets." OFF)
150175# The default terminate handler attempts to demangle uncaught exceptions, which
151176# causes extra I/O and demangling code to be pulled in.
152177option (LIBCXXABI_SILENT_TERMINATE "Set this to make the terminate handler default to a silent alternative" OFF )
178+ option (LIBCXXABI_NON_DEMANGLING_TERMINATE "Set this to make the terminate handler
179+ avoid demangling" OFF )
153180
154181if (NOT LIBCXXABI_ENABLE_SHARED AND NOT LIBCXXABI_ENABLE_STATIC)
155182 message (FATAL_ERROR "libc++abi must be built as either a shared or static library." )
156183endif ()
157184
158- set (LIBCXXABI_LIBCXX_INCLUDES "${LIBCXXABI_LIBCXX_PATH} /include" CACHE PATH
185+ # TODO: This is a workaround for the fact that Standalone builds can't use
186+ # targets from the other runtimes (so the cxx-headers target doesn't exist).
187+ set (LIBCXXABI_LIBCXX_INCLUDES "" CACHE PATH
159188 "Specify path to libc++ includes." )
160- message (STATUS "Libc++abi will be using libc++ includes from ${LIBCXXABI_LIBCXX_INCLUDES} " )
189+ if (LIBCXXABI_STANDALONE_BUILD)
190+ if (NOT IS_DIRECTORY ${LIBCXXABI_LIBCXX_INCLUDES} )
191+ message (FATAL_ERROR
192+ "LIBCXXABI_LIBCXX_INCLUDES=${LIBCXXABI_LIBCXX_INCLUDES} is not a valid directory. "
193+ "Please provide the path to where the libc++ headers have been installed." )
194+ endif ()
195+ add_library (cxx-headers INTERFACE )
196+ if ("${CMAKE_CXX_COMPILER_ID} " STREQUAL "MSVC" OR "${CMAKE_CXX_SIMULATE_ID} " STREQUAL "MSVC" )
197+ target_compile_options (cxx-headers INTERFACE /I "${LIBCXXABI_LIBCXX_INCLUDES} " )
198+ else ()
199+ target_compile_options (cxx-headers INTERFACE -I "${LIBCXXABI_LIBCXX_INCLUDES} " )
200+ endif ()
201+ endif ()
161202
162203option (LIBCXXABI_HERMETIC_STATIC_LIBRARY
163204 "Do not export any symbols from the static library." OFF )
164205
165206set (LIBCXXABI_TEST_CONFIG "${CMAKE_CURRENT_SOURCE_DIR} /test/lit.site.cfg.in" CACHE STRING
166- "The Lit testing configuration to use when running the tests." )
207+ "The path to the Lit testing configuration to use when running the tests.
208+ If a relative path is provided, it is assumed to be relative to '<monorepo>/libcxxabi/test/configs'." )
209+ if (NOT IS_ABSOLUTE "${LIBCXXABI_TEST_CONFIG} " )
210+ set (LIBCXXABI_TEST_CONFIG "${CMAKE_CURRENT_SOURCE_DIR} /test/configs/${LIBCXXABI_TEST_CONFIG} " )
211+ endif ()
167212set (LIBCXXABI_TEST_PARAMS "" CACHE STRING
168213 "A list of parameters to run the Lit test suite with." )
169214
@@ -178,23 +223,30 @@ set(CMAKE_MODULE_PATH
178223 ${CMAKE_MODULE_PATH}
179224 )
180225
226+ set (LIBCXXABI_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR} " CACHE PATH
227+ "Path where built libc++abi runtime libraries should be installed." )
228+
181229if (LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE )
182- set (LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR} /${LLVM_DEFAULT_TARGET_TRIPLE} /c++)
183- set (LIBCXXABI_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX} /${LLVM_DEFAULT_TARGET_TRIPLE} /c++)
230+ set (LIBCXXABI_HEADER_DIR ${LLVM_BINARY_DIR} )
231+ set (LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR} /${LLVM_DEFAULT_TARGET_TRIPLE} )
232+ set (LIBCXXABI_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX} /${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH
233+ "Path where built libc++abi libraries should be installed." )
184234 if (LIBCXX_LIBDIR_SUBDIR)
185235 string (APPEND LIBCXXABI_LIBRARY_DIR /${LIBCXXABI_LIBDIR_SUBDIR} )
186236 string (APPEND LIBCXXABI_INSTALL_LIBRARY_DIR /${LIBCXXABI_LIBDIR_SUBDIR} )
187237 endif ()
188- elseif (LLVM_LIBRARY_OUTPUT_INTDIR)
189- set (LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR} )
190- set (LIBCXXABI_INSTALL_LIBRARY_DIR lib${LIBCXXABI_LIBDIR_SUFFIX} )
191238else ()
192- set (LIBCXXABI_LIBRARY_DIR ${CMAKE_BINARY_DIR} /lib${LIBCXXABI_LIBDIR_SUFFIX} )
193- set (LIBCXXABI_INSTALL_LIBRARY_DIR lib${LIBCXXABI_LIBDIR_SUFFIX} )
239+ if (LLVM_LIBRARY_OUTPUT_INTDIR)
240+ set (LIBCXXABI_HEADER_DIR ${LLVM_BINARY_DIR} )
241+ set (LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR} )
242+ else ()
243+ set (LIBCXXABI_HEADER_DIR ${CMAKE_BINARY_DIR} )
244+ set (LIBCXXABI_LIBRARY_DIR ${CMAKE_BINARY_DIR} /lib${LIBCXXABI_LIBDIR_SUFFIX} )
245+ endif ()
246+ set (LIBCXXABI_INSTALL_LIBRARY_DIR lib${LIBCXXABI_LIBDIR_SUFFIX} CACHE PATH
247+ "Path where built libc++abi libraries should be installed." )
194248endif ()
195249
196- set (LIBCXXABI_INSTALL_PREFIX "" CACHE STRING "Define libc++abi destination prefix." )
197-
198250set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBCXXABI_LIBRARY_DIR} )
199251set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBCXXABI_LIBRARY_DIR} )
200252set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIBCXXABI_LIBRARY_DIR} )
@@ -206,15 +258,6 @@ if (NOT LIBCXXABI_LIBCXX_LIBRARY_PATH)
206258 "The path to libc++ library." FORCE)
207259endif ()
208260
209- # Check that we can build with 32 bits if requested.
210- if (CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
211- if (LIBCXXABI_BUILD_32_BITS AND NOT LLVM_BUILD_32_BITS) # Don't duplicate the output from LLVM
212- message (STATUS "Building 32 bits executables and libraries." )
213- endif ()
214- elseif (LIBCXXABI_BUILD_32_BITS)
215- message (FATAL_ERROR "LIBCXXABI_BUILD_32_BITS=ON is not supported on this platform." )
216- endif ()
217-
218261# Declare libc++abi configuration variables.
219262# They are intended for use as follows:
220263# LIBCXXABI_C_FLAGS: General flags for both the c++ compiler and linker.
@@ -237,26 +280,17 @@ include(HandleLibcxxabiFlags)
237280#===============================================================================
238281
239282# Configure target flags
240- add_target_flags_if(LIBCXXABI_BUILD_32_BITS "-m32" )
241-
283+ if (ZOS)
284+ add_target_flags_if_supported("-fzos-le-char-mode=ebcdic" )
285+ endif ()
242286if (LIBCXXABI_TARGET_TRIPLE)
243- add_target_flags("--target=${LIBCXXABI_TARGET_TRIPLE} " )
244- elseif (CMAKE_CXX_COMPILER_TARGET)
245- set (LIBCXXABI_TARGET_TRIPLE "${CMAKE_CXX_COMPILER_TARGET} " )
287+ add_target_flags_if_supported("--target=${LIBCXXABI_TARGET_TRIPLE} " )
246288endif ()
247- if (LIBCXX_GCC_TOOLCHAIN)
248- add_target_flags("--gcc-toolchain=${LIBCXXABI_GCC_TOOLCHAIN} " )
249- elseif (CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN)
250- set (LIBCXXABI_GCC_TOOLCHAIN "${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN} " )
289+ if (LIBCXXABI_GCC_TOOLCHAIN)
290+ add_target_flags_if_supported("--gcc-toolchain=${LIBCXXABI_GCC_TOOLCHAIN} " )
251291endif ()
252292if (LIBCXXABI_SYSROOT)
253- add_target_flags("--sysroot=${LIBCXXABI_SYSROOT} " )
254- elseif (CMAKE_SYSROOT)
255- set (LIBCXXABI_SYSROOT "${CMAKE_SYSROOT} " )
256- endif ()
257-
258- if (LIBCXXABI_TARGET_TRIPLE)
259- set (TARGET_TRIPLE "${LIBCXXABI_TARGET_TRIPLE} " )
293+ add_target_flags_if_supported("--sysroot=${LIBCXXABI_SYSROOT} " )
260294endif ()
261295
262296# Configure compiler. Must happen after setting the target flags.
@@ -374,6 +408,11 @@ if (NOT LIBCXXABI_ENABLE_THREADS)
374408 " be set to ON when LIBCXXABI_ENABLE_THREADS"
375409 " is also set to ON." )
376410 endif ()
411+ if (LIBCXXABI_HAS_WIN32_THREAD_API)
412+ message (FATAL_ERROR "LIBCXXABI_HAS_WIN32_THREAD_API can only"
413+ " be set to ON when LIBCXXABI_ENABLE_THREADS"
414+ " is also set to ON." )
415+ endif ()
377416 if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
378417 message (FATAL_ERROR "LIBCXXABI_HAS_EXTERNAL_THREAD_API can only"
379418 " be set to ON when LIBCXXABI_ENABLE_THREADS"
@@ -385,7 +424,6 @@ if (NOT LIBCXXABI_ENABLE_THREADS)
385424 " is also set to ON." )
386425 endif ()
387426 add_definitions (-D_LIBCXXABI_HAS_NO_THREADS)
388- add_definitions (-D_LIBCPP_HAS_NO_THREADS)
389427endif ()
390428
391429if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
@@ -394,13 +432,26 @@ if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
394432 " and LIBCXXABI_HAS_PTHREAD_API cannot be both"
395433 " set to ON at the same time." )
396434 endif ()
435+ if (LIBCXXABI_HAS_WIN32_THREAD_API)
436+ message (FATAL_ERROR "The options LIBCXXABI_HAS_EXTERNAL_THREAD_API"
437+ " and LIBCXXABI_HAS_WIN32_THREAD_API cannot be both"
438+ " set to ON at the same time." )
439+ endif ()
397440 if (LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY)
398441 message (FATAL_ERROR "The options LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY"
399442 " and LIBCXXABI_HAS_EXTERNAL_THREAD_API cannot be both"
400443 " set to ON at the same time." )
401444 endif ()
402445endif ()
403446
447+ if (LIBCXXABI_HAS_PTHREAD_API)
448+ if (LIBCXXABI_HAS_WIN32_THREAD_API)
449+ message (FATAL_ERROR "The options LIBCXXABI_HAS_PTHREAD_API"
450+ "and LIBCXXABI_HAS_WIN32_THREAD_API cannot be both"
451+ "set to ON at the same time." )
452+ endif ()
453+ endif ()
454+
404455if (LLVM_ENABLE_MODULES)
405456 # Ignore that the rest of the modules flags are now unused.
406457 add_compile_flags_if_supported(-Wno-unused-command -line-argument)
@@ -428,6 +479,10 @@ if (LIBCXXABI_HAS_PTHREAD_API)
428479 add_definitions (-D_LIBCPP_HAS_THREAD_API_PTHREAD)
429480endif ()
430481
482+ if (LIBCXXABI_HAS_WIN32_THREAD_API)
483+ add_definitions (-D_LIBCPP_HAS_THREAD_API_WIN32)
484+ endif ()
485+
431486if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
432487 add_definitions (-D_LIBCPP_HAS_THREAD_API_EXTERNAL)
433488endif ()
@@ -439,10 +494,6 @@ endif()
439494# Prevent libc++abi from having library dependencies on libc++
440495add_definitions (-D_LIBCPP_DISABLE_EXTERN_TEMPLATE)
441496
442- # Bring back `std::unexpected`, which is removed in C++17, to support
443- # pre-C++17.
444- add_definitions (-D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS)
445-
446497if (MSVC )
447498 add_definitions (-D_CRT_SECURE_NO_WARNINGS)
448499endif ()
@@ -456,6 +507,10 @@ if (LIBCXXABI_SILENT_TERMINATE)
456507 add_definitions (-DLIBCXXABI_SILENT_TERMINATE)
457508endif ()
458509
510+ if (LIBCXXABI_NON_DEMANGLING_TERMINATE)
511+ add_definitions (-DLIBCXXABI_NON_DEMANGLING_TERMINATE)
512+ endif ()
513+
459514if (LIBCXXABI_BAREMETAL)
460515 add_definitions (-DLIBCXXABI_BAREMETAL)
461516endif ()
@@ -470,6 +525,12 @@ string(REPLACE ";" " " LIBCXXABI_CXX_FLAGS "${LIBCXXABI_CXX_FLAGS}")
470525set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LIBCXXABI_CXX_FLAGS} " )
471526set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBCXXABI_C_FLAGS} " )
472527
528+ # On AIX, avoid picking up VMX extensions(i.e. vec_malloc) which would change
529+ # the default alignment of the allocators here.
530+ if (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "AIX" )
531+ add_definitions ("-D_XOPEN_SOURCE=700" )
532+ endif ()
533+
473534#===============================================================================
474535# Setup Source Code
475536#===============================================================================
0 commit comments