summaryrefslogtreecommitdiff
path: root/gnu/llvm/libunwind/CMakeLists.txt
diff options
context:
space:
mode:
authorRobert Nagy <robert@cvs.openbsd.org>2024-01-26 11:39:04 +0000
committerRobert Nagy <robert@cvs.openbsd.org>2024-01-26 11:39:04 +0000
commitb1753aa1d9e7405725a321381f05c92e80e997ac (patch)
tree2a9f8a4af2227ed2ef3b714084cd2babd032dbf0 /gnu/llvm/libunwind/CMakeLists.txt
parentc9e2866066bb17c8868e9df6b974e6b7716ef0b2 (diff)
import of llvm libunwind 16.0.6
Diffstat (limited to 'gnu/llvm/libunwind/CMakeLists.txt')
-rw-r--r--gnu/llvm/libunwind/CMakeLists.txt153
1 files changed, 70 insertions, 83 deletions
diff --git a/gnu/llvm/libunwind/CMakeLists.txt b/gnu/llvm/libunwind/CMakeLists.txt
index 81eddbc2487..5c547883f99 100644
--- a/gnu/llvm/libunwind/CMakeLists.txt
+++ b/gnu/llvm/libunwind/CMakeLists.txt
@@ -1,18 +1,17 @@
-if (NOT IS_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/../libcxx")
- message(FATAL_ERROR "libunwind requires being built in a monorepo layout with libcxx available")
-endif()
-
#===============================================================================
# Setup Project
#===============================================================================
cmake_minimum_required(VERSION 3.13.4)
+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(LIBUNWIND_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
@@ -20,29 +19,7 @@ set(LIBUNWIND_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(LIBUNWIND_LIBCXX_PATH "${CMAKE_CURRENT_LIST_DIR}/../libcxx" CACHE PATH
"Specify path to libc++ source.")
-if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR LIBUNWIND_STANDALONE_BUILD)
- project(libunwind LANGUAGES C CXX ASM)
-
- set(PACKAGE_NAME libunwind)
- set(PACKAGE_VERSION 13.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(LIBUNWIND_LIBCXX_CMAKE_PATH "${LIBUNWIND_LIBCXX_PATH}/cmake/Modules")
- list(APPEND CMAKE_MODULE_PATH "${LIBUNWIND_LIBCXX_CMAKE_PATH}")
-
- # 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(LIBUNWIND_STANDALONE_BUILD 1)
- set(LLVM_LIT_OUTPUT_DIR "${LIBUNWIND_BINARY_DIR}/bin")
-
- # Find the LLVM sources and simulate LLVM CMake options.
- include(HandleOutOfTreeLLVM)
-else()
- set(LLVM_LIT "${CMAKE_SOURCE_DIR}/utils/lit/lit.py")
-endif()
+include(GNUInstallDirs)
#===============================================================================
# Setup CMake Options
@@ -51,7 +28,12 @@ include(CMakeDependentOption)
include(HandleCompilerRT)
# Define options.
-option(LIBUNWIND_BUILD_32_BITS "Build 32 bit libunwind" ${LLVM_BUILD_32_BITS})
+option(LIBUNWIND_BUILD_32_BITS "Build 32 bit multilib libunwind. This option is not supported anymore when building the runtimes. Please specify a full triple instead." ${LLVM_BUILD_32_BITS})
+if (LIBUNWIND_BUILD_32_BITS)
+ message(FATAL_ERROR "LIBUNWIND_BUILD_32_BITS is not supported anymore when building the runtimes, please specify a full triple instead.")
+endif()
+
+option(LIBUNWIND_ENABLE_CET "Build libunwind with CET enabled." OFF)
option(LIBUNWIND_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON)
option(LIBUNWIND_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
option(LIBUNWIND_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
@@ -67,6 +49,7 @@ option(LIBUNWIND_INCLUDE_TESTS "Build the libunwind tests." ${LLVM_INCLUDE_TESTS
option(LIBUNWIND_IS_BAREMETAL "Build libunwind for baremetal targets." OFF)
option(LIBUNWIND_USE_FRAME_HEADER_CACHE "Cache frame headers for unwinding. Requires locking dl_iterate_phdr." OFF)
option(LIBUNWIND_REMEMBER_HEAP_ALLOC "Use heap instead of the stack for .cfi_remember_state." OFF)
+option(LIBUNWIND_INSTALL_HEADERS "Install the libunwind headers." ON)
set(LIBUNWIND_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
"Define suffix of library directory name (32/64)")
@@ -77,15 +60,24 @@ cmake_dependent_option(LIBUNWIND_INSTALL_STATIC_LIBRARY
cmake_dependent_option(LIBUNWIND_INSTALL_SHARED_LIBRARY
"Install the shared libunwind library." ON
"LIBUNWIND_ENABLE_SHARED;LIBUNWIND_INSTALL_LIBRARY" OFF)
-set(LIBUNWIND_TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}" CACHE STRING "Target triple for cross compiling.")
-set(LIBUNWIND_GCC_TOOLCHAIN "" CACHE PATH "GCC toolchain for cross compiling.")
-set(LIBUNWIND_SYSROOT "" CACHE PATH "Sysroot for cross compiling.")
-set(LIBUNWIND_TEST_LINKER_FLAGS "" CACHE STRING
- "Additional linker flags for test programs.")
-set(LIBUNWIND_TEST_COMPILER_FLAGS "" CACHE STRING
- "Additional compiler flags for test programs.")
-set(LIBUNWIND_TEST_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/test/lit.site.cfg.in" CACHE STRING
- "The Lit testing configuration to use when running the tests.")
+
+# TODO: Remove this after branching for LLVM 15
+if(LIBUNWIND_SYSROOT OR LIBUNWIND_TARGET_TRIPLE OR LIBUNWIND_GCC_TOOLCHAIN)
+ message(WARNING "LIBUNWIND_SYSROOT, LIBUNWIND_TARGET_TRIPLE and LIBUNWIND_GCC_TOOLCHAIN are not supported anymore, please use the native CMake equivalents instead")
+endif()
+
+if (LIBUNWIND_ENABLE_SHARED)
+ set(LIBUNWIND_DEFAULT_TEST_CONFIG "llvm-libunwind-shared.cfg.in")
+else()
+ set(LIBUNWIND_DEFAULT_TEST_CONFIG "llvm-libunwind-static.cfg.in")
+endif()
+set(LIBUNWIND_TEST_CONFIG "${LIBUNWIND_DEFAULT_TEST_CONFIG}" CACHE STRING
+ "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>/libunwind/test/configs'.")
+if (NOT IS_ABSOLUTE "${LIBUNWIND_TEST_CONFIG}")
+ set(LIBUNWIND_TEST_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/test/configs/${LIBUNWIND_TEST_CONFIG}")
+endif()
+message(STATUS "Using libunwind testing configuration: ${LIBUNWIND_TEST_CONFIG}")
set(LIBUNWIND_TEST_PARAMS "" CACHE STRING
"A list of parameters to run the Lit test suite with.")
@@ -93,17 +85,17 @@ if (NOT LIBUNWIND_ENABLE_SHARED AND NOT LIBUNWIND_ENABLE_STATIC)
message(FATAL_ERROR "libunwind must be built as either a shared or static library.")
endif()
-# Check that we can build with 32 bits if requested.
-if (CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32)
- if (LIBUNWIND_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(LIBUNWIND_BUILD_32_BITS)
- message(FATAL_ERROR "LIBUNWIND_BUILD_32_BITS=ON is not supported on this platform.")
+if (LIBUNWIND_ENABLE_CET AND MSVC)
+ message(FATAL_ERROR "libunwind CET support is not available for MSVC!")
endif()
+if (WIN32)
+ set(LIBUNWIND_DEFAULT_HIDE_SYMBOLS TRUE)
+else()
+ set(LIBUNWIND_DEFAULT_HIDE_SYMBOLS FALSE)
+endif()
option(LIBUNWIND_HIDE_SYMBOLS
- "Do not export any symbols from the static library." OFF)
+ "Do not export any symbols from the static library." ${LIBUNWIND_DEFAULT_HIDE_SYMBOLS})
#===============================================================================
# Configure System
@@ -114,6 +106,14 @@ set(CMAKE_MODULE_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
${CMAKE_MODULE_PATH})
+set(LIBUNWIND_INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}" CACHE PATH
+ "Path where built libunwind headers should be installed.")
+set(LIBUNWIND_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH
+ "Path where built libunwind runtime libraries should be installed.")
+
+set(LIBUNWIND_SHARED_OUTPUT_NAME "unwind" CACHE STRING "Output name for the shared libunwind runtime library.")
+set(LIBUNWIND_STATIC_OUTPUT_NAME "unwind" CACHE STRING "Output name for the static libunwind runtime library.")
+
if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE})
set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH
@@ -122,12 +122,12 @@ if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
string(APPEND LIBUNWIND_LIBRARY_DIR /${LIBUNWIND_LIBDIR_SUBDIR})
string(APPEND LIBUNWIND_INSTALL_LIBRARY_DIR /${LIBUNWIND_LIBDIR_SUBDIR})
endif()
-elseif(LLVM_LIBRARY_OUTPUT_INTDIR)
- set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
- set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LIBUNWIND_LIBDIR_SUFFIX} CACHE PATH
- "Path where built libunwind libraries should be installed.")
else()
- set(LIBUNWIND_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBUNWIND_LIBDIR_SUFFIX})
+ if(LLVM_LIBRARY_OUTPUT_INTDIR)
+ set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
+ else()
+ set(LIBUNWIND_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBUNWIND_LIBDIR_SUFFIX})
+ endif()
set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LIBUNWIND_LIBDIR_SUFFIX} CACHE PATH
"Path where built libunwind libraries should be installed.")
endif()
@@ -148,25 +148,6 @@ include(HandleLibunwindFlags)
# Setup Compiler Flags
#===============================================================================
-# Get required flags.
-add_target_flags_if(LIBUNWIND_BUILD_32_BITS "-m32")
-
-if(LIBUNWIND_TARGET_TRIPLE)
- add_target_flags_if_supported("--target=${LIBUNWIND_TARGET_TRIPLE}")
-elseif(CMAKE_CXX_COMPILER_TARGET)
- set(LIBUNWIND_TARGET_TRIPLE "${CMAKE_CXX_COMPILER_TARGET}")
-endif()
-if(LIBUNWIND_GCC_TOOLCHAIN)
- add_target_flags_if_supported("--gcc-toolchain=${LIBUNWIND_GCC_TOOLCHAIN}")
-elseif(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN)
- set(LIBUNWIND_GCC_TOOLCHAIN "${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}")
-endif()
-if(LIBUNWIND_SYSROOT)
- add_target_flags_if_supported("--sysroot=${LIBUNWIND_SYSROOT}")
-elseif(CMAKE_SYSROOT)
- set(LIBUNWIND_SYSROOT "${CMAKE_SYSROOT}")
-endif()
-
# Configure compiler.
include(config-ix)
@@ -176,6 +157,17 @@ endif()
add_compile_flags_if_supported(-Werror=return-type)
+if (LIBUNWIND_ENABLE_CET)
+ add_compile_flags_if_supported(-fcf-protection=full)
+ add_compile_flags_if_supported(-mshstk)
+ if (NOT CXX_SUPPORTS_FCF_PROTECTION_EQ_FULL_FLAG)
+ message(SEND_ERROR "Compiler doesn't support CET -fcf-protection option!")
+ endif()
+ if (NOT CXX_SUPPORTS_MSHSTK_FLAG)
+ message(SEND_ERROR "Compiler doesn't support CET -mshstk option!")
+ endif()
+endif()
+
# Get warning flags
add_compile_flags_if_supported(-W)
add_compile_flags_if_supported(-Wall)
@@ -243,7 +235,7 @@ set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
add_compile_flags_if_supported(-funwind-tables)
set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE})
-if (LIBUNWIND_USES_ARM_EHABI AND NOT LIBUNWIND_SUPPORTS_FUNWIND_TABLES_FLAG)
+if (LIBUNWIND_USES_ARM_EHABI AND NOT CXX_SUPPORTS_FUNWIND_TABLES_FLAG)
message(SEND_ERROR "The -funwind-tables flag must be supported "
"because this target uses ARM Exception Handling ABI")
endif()
@@ -252,7 +244,7 @@ add_cxx_compile_flags_if_supported(-fno-exceptions)
add_cxx_compile_flags_if_supported(-fno-rtti)
# Ensure that we don't depend on C++ standard library.
-if (LIBUNWIND_HAS_NOSTDINCXX_FLAG)
+if (CXX_SUPPORTS_NOSTDINCXX_FLAG)
list(APPEND LIBUNWIND_COMPILE_FLAGS -nostdinc++)
# Remove -stdlib flags to prevent them from causing an unused flag warning.
string(REPLACE "--stdlib=libc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
@@ -271,11 +263,11 @@ if (LIBUNWIND_ENABLE_ASSERTIONS)
# On Release builds cmake automatically defines NDEBUG, so we
# explicitly undefine it:
- if (uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE")
+ if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
add_compile_flags(-UNDEBUG)
endif()
else()
- if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE")
+ if (uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
add_compile_flags(-DNDEBUG)
endif()
endif()
@@ -316,12 +308,7 @@ if (MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif()
-# Disable DLL annotations on Windows for static builds.
-if (WIN32 AND LIBUNWIND_ENABLE_STATIC AND NOT LIBUNWIND_ENABLE_SHARED)
- add_definitions(-D_LIBUNWIND_HIDE_SYMBOLS)
-endif()
-
-if (LIBUNWIND_HAS_COMMENT_LIB_PRAGMA)
+if (C_SUPPORTS_COMMENT_LIB_PRAGMA)
if (LIBUNWIND_HAS_DL_LIB)
add_definitions(-D_LIBUNWIND_LINK_DL_LIB)
endif()
@@ -334,7 +321,7 @@ endif()
# Setup Source Code
#===============================================================================
-include_directories(include)
+add_subdirectory(include)
add_subdirectory(src)
@@ -342,6 +329,6 @@ if (LIBUNWIND_INCLUDE_DOCS)
add_subdirectory(docs)
endif()
-if (LIBUNWIND_INCLUDE_TESTS AND EXISTS ${LLVM_CMAKE_PATH})
+if (LIBUNWIND_INCLUDE_TESTS AND EXISTS ${LLVM_CMAKE_DIR})
add_subdirectory(test)
endif()