+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.4.3)
-
-if (POLICY CMP0042)
- cmake_policy(SET CMP0042 NEW) # Set MACOSX_RPATH=YES by default
-endif()
+cmake_minimum_required(VERSION 3.13.4)
# Add path for custom modules
set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
)
+set(LIBUNWIND_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
+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)
- # Rely on llvm-config.
- set(CONFIG_OUTPUT)
- if(NOT LLVM_CONFIG_PATH)
- find_program(LLVM_CONFIG_PATH "llvm-config")
- endif()
- if (DEFINED LLVM_PATH)
- set(LLVM_INCLUDE_DIR ${LLVM_INCLUDE_DIR} CACHE PATH "Path to llvm/include")
- set(LLVM_PATH ${LLVM_PATH} CACHE PATH "Path to LLVM source tree")
- set(LLVM_MAIN_SRC_DIR ${LLVM_PATH})
- set(LLVM_CMAKE_PATH "${LLVM_PATH}/cmake/modules")
- elseif(LLVM_CONFIG_PATH)
- message(STATUS "Found LLVM_CONFIG_PATH as ${LLVM_CONFIG_PATH}")
- set(CONFIG_COMMAND ${LLVM_CONFIG_PATH} "--includedir" "--prefix" "--src-root")
- execute_process(COMMAND ${CONFIG_COMMAND}
- RESULT_VARIABLE HAD_ERROR
- OUTPUT_VARIABLE CONFIG_OUTPUT)
- if (NOT HAD_ERROR)
- string(REGEX REPLACE "[ \t]*[\r\n]+[ \t]*" ";"
- CONFIG_OUTPUT ${CONFIG_OUTPUT})
- else()
- string(REPLACE ";" " " CONFIG_COMMAND_STR "${CONFIG_COMMAND}")
- message(STATUS "${CONFIG_COMMAND_STR}")
- message(FATAL_ERROR "llvm-config failed with status ${HAD_ERROR}")
- endif()
-
- list(GET CONFIG_OUTPUT 0 INCLUDE_DIR)
- list(GET CONFIG_OUTPUT 1 LLVM_OBJ_ROOT)
- list(GET CONFIG_OUTPUT 2 MAIN_SRC_DIR)
-
- set(LLVM_INCLUDE_DIR ${INCLUDE_DIR} CACHE PATH "Path to llvm/include")
- set(LLVM_BINARY_DIR ${LLVM_OBJ_ROOT} CACHE PATH "Path to LLVM build tree")
- set(LLVM_MAIN_SRC_DIR ${MAIN_SRC_DIR} CACHE PATH "Path to LLVM source tree")
- set(LLVM_LIT_PATH "${LLVM_PATH}/utils/lit/lit.py")
-
- # --cmakedir is supported since llvm r291218 (4.0 release)
- execute_process(
- COMMAND ${LLVM_CONFIG_PATH} --cmakedir
- RESULT_VARIABLE HAD_ERROR
- OUTPUT_VARIABLE CONFIG_OUTPUT
- ERROR_QUIET)
- if(NOT HAD_ERROR)
- string(STRIP "${CONFIG_OUTPUT}" LLVM_CMAKE_PATH_FROM_LLVM_CONFIG)
- file(TO_CMAKE_PATH "${LLVM_CMAKE_PATH_FROM_LLVM_CONFIG}" LLVM_CMAKE_PATH)
- else()
- file(TO_CMAKE_PATH "${LLVM_BINARY_DIR}" LLVM_BINARY_DIR_CMAKE_STYLE)
- set(LLVM_CMAKE_PATH "${LLVM_BINARY_DIR_CMAKE_STYLE}/lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm")
- endif()
- else()
- message(WARNING "UNSUPPORTED LIBUNWIND CONFIGURATION DETECTED: "
- "llvm-config not found and LLVM_MAIN_SRC_DIR not defined. "
- "Reconfigure with -DLLVM_CONFIG=path/to/llvm-config "
- "or -DLLVM_PATH=path/to/llvm-source-root.")
- endif()
-
- if (EXISTS ${LLVM_CMAKE_PATH})
- # Enable warnings, otherwise -w gets added to the cflags by HandleLLVMOptions.
- set(LLVM_ENABLE_WARNINGS ON)
- list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_PATH}")
- include("${LLVM_CMAKE_PATH}/AddLLVM.cmake")
- include("${LLVM_CMAKE_PATH}/HandleLLVMOptions.cmake")
- else()
- message(WARNING "Not found: ${LLVM_CMAKE_PATH}")
- endif()
-
set(PACKAGE_NAME libunwind)
- set(PACKAGE_VERSION 11.1.0)
+ set(PACKAGE_VERSION 13.0.0git)
set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
set(PACKAGE_BUGREPORT "llvm-bugs@lists.llvm.org")
- if (EXISTS ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
- set(LLVM_LIT ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
- else()
- # Seek installed Lit.
- find_program(LLVM_LIT "lit.py" ${LLVM_MAIN_SRC_DIR}/utils/lit
- DOC "Path to lit.py")
- endif()
+ # 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}")
- if (LLVM_LIT)
- # Define the default arguments to use with 'lit', and an option for the user
- # to override.
- set(LIT_ARGS_DEFAULT "-sv")
- if (MSVC OR XCODE)
- set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
- endif()
- set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
-
- # On Win32 hosts, provide an option to specify the path to the GnuWin32 tools.
- if (WIN32 AND NOT CYGWIN)
- set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools")
- endif()
- else()
- set(LLVM_INCLUDE_TESTS OFF)
- endif()
+ # 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")
- set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX})
- set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX})
+ # Find the LLVM sources and simulate LLVM CMake options.
+ include(HandleOutOfTreeLLVM)
else()
set(LLVM_LIT "${CMAKE_SOURCE_DIR}/utils/lit/lit.py")
endif()
option(LIBUNWIND_WEAK_PTHREAD_LIB "Use weak references to refer to pthread functions." OFF)
option(LIBUNWIND_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF)
option(LIBUNWIND_INCLUDE_DOCS "Build the libunwind documentation." ${LLVM_INCLUDE_DOCS})
+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)
set(LIBUNWIND_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
"Define suffix of library directory name (32/64)")
cmake_dependent_option(LIBUNWIND_INSTALL_SHARED_LIBRARY
"Install the shared libunwind library." ON
"LIBUNWIND_ENABLE_SHARED;LIBUNWIND_INSTALL_LIBRARY" OFF)
-set(LIBUNWIND_TARGET_TRIPLE "" CACHE STRING "Target triple for cross compiling.")
+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 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.")
+set(LIBUNWIND_TEST_PARAMS "" CACHE STRING
+ "A list of parameters to run the Lit test suite with.")
if (NOT LIBUNWIND_ENABLE_SHARED AND NOT LIBUNWIND_ENABLE_STATIC)
message(FATAL_ERROR "libunwind must be built as either a shared or static library.")
message(FATAL_ERROR "LIBUNWIND_BUILD_32_BITS=ON is not supported on this platform.")
endif()
-option(LIBUNWIND_HERMETIC_STATIC_LIBRARY
+option(LIBUNWIND_HIDE_SYMBOLS
"Do not export any symbols from the static library." OFF)
#===============================================================================
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
${CMAKE_MODULE_PATH})
-set(LIBUNWIND_COMPILER ${CMAKE_CXX_COMPILER})
-set(LIBUNWIND_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
-set(LIBUNWIND_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
-
-string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION
- ${PACKAGE_VERSION})
-
if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
- set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++)
- set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++)
+ 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
+ "Path where built libunwind libraries should be installed.")
if(LIBCXX_LIBDIR_SUBDIR)
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})
+ 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})
- set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LIBUNWIND_LIBDIR_SUFFIX})
+ set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LIBUNWIND_LIBDIR_SUFFIX} CACHE PATH
+ "Path where built libunwind libraries should be installed.")
endif()
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBUNWIND_LIBRARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBUNWIND_LIBRARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIBUNWIND_LIBRARY_DIR})
-set(LIBUNWIND_INSTALL_PREFIX "" CACHE STRING "Define libunwind destination prefix.")
-
set(LIBUNWIND_C_FLAGS "")
set(LIBUNWIND_CXX_FLAGS "")
set(LIBUNWIND_COMPILE_FLAGS "")
add_target_flags_if(LIBUNWIND_BUILD_32_BITS "-m32")
if(LIBUNWIND_TARGET_TRIPLE)
- add_target_flags("--target=${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("--gcc-toolchain=${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("--sysroot=${LIBUNWIND_SYSROOT}")
+ add_target_flags_if_supported("--sysroot=${LIBUNWIND_SYSROOT}")
elseif(CMAKE_SYSROOT)
set(LIBUNWIND_SYSROOT "${CMAKE_SYSROOT}")
endif()
-if (LIBUNWIND_TARGET_TRIPLE)
- set(TARGET_TRIPLE "${LIBUNWIND_TARGET_TRIPLE}")
-endif()
-
# Configure compiler.
include(config-ix)
add_compile_flags_if_supported(-Wwrite-strings)
add_compile_flags_if_supported(-Wundef)
+add_compile_flags_if_supported(-Wno-suggest-override)
+
+if (WIN32)
+ # The headers lack matching dllexport attributes (_LIBUNWIND_EXPORT);
+ # silence the warning instead of cluttering the headers (which aren't
+ # necessarily the ones that the callers will use anyway) with the
+ # attributes.
+ add_compile_flags_if_supported(-Wno-dll-attribute-on-redeclaration)
+endif()
+
if (LIBUNWIND_ENABLE_WERROR)
add_compile_flags_if_supported(-Werror)
add_compile_flags_if_supported(-WX)
if (LIBUNWIND_HAS_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}")
+ string(REPLACE "--stdlib=libstdc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REPLACE "-stdlib=libc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REPLACE "-stdlib=libstdc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
endif()
add_compile_flags(-D__ARM_WMMX)
endif()
+if(LIBUNWIND_IS_BAREMETAL)
+ add_compile_definitions(_LIBUNWIND_IS_BAREMETAL)
+endif()
+
if(LIBUNWIND_USE_FRAME_HEADER_CACHE)
add_compile_definitions(_LIBUNWIND_USE_FRAME_HEADER_CACHE)
endif()
+if(LIBUNWIND_REMEMBER_HEAP_ALLOC)
+ add_compile_definitions(_LIBUNWIND_REMEMBER_HEAP_ALLOC)
+endif()
+
# This is the _ONLY_ place where add_definitions is called.
if (MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
# Disable DLL annotations on Windows for static builds.
if (WIN32 AND LIBUNWIND_ENABLE_STATIC AND NOT LIBUNWIND_ENABLE_SHARED)
- add_definitions(-D_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS)
+ add_definitions(-D_LIBUNWIND_HIDE_SYMBOLS)
endif()
if (LIBUNWIND_HAS_COMMENT_LIB_PRAGMA)
add_subdirectory(docs)
endif()
-if (EXISTS ${LLVM_CMAKE_PATH})
+if (LIBUNWIND_INCLUDE_TESTS AND EXISTS ${LLVM_CMAKE_PATH})
add_subdirectory(test)
endif()
dwarf2.h
DwarfInstructions.hpp
DwarfParser.hpp
+ EHHeaderParser.hpp
+ FrameHeaderCache.hpp
libunwind_ext.h
Registers.hpp
RWMutex.hpp
+ Unwind-EHABI.h
UnwindCursor.hpp
../include/libunwind.h
../include/unwind.h
endif()
# Setup flags.
-add_link_flags_if_supported(-nodefaultlibs)
+if (LIBUNWIND_SUPPORTS_NOSTDLIBXX_FLAG)
+ add_link_flags_if_supported(-nostdlib++)
+else()
+ add_link_flags_if_supported(-nodefaultlibs)
+endif()
# MINGW_LIBRARIES is defined in config-ix.cmake
add_library_flags_if(MINGW "${MINGW_LIBRARIES}")
else()
target_compile_options(unwind_shared PRIVATE -fno-rtti)
endif()
- if(COMMAND llvm_setup_rpath)
- llvm_setup_rpath(unwind_shared)
- endif()
target_link_libraries(unwind_shared PRIVATE ${LIBUNWIND_LIBRARIES})
- set_target_properties(unwind_shared PROPERTIES
- CXX_EXTENSIONS OFF
- CXX_STANDARD 11
- CXX_STANDARD_REQUIRED ON
- COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}"
- LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"
- LINKER_LANGUAGE C
- OUTPUT_NAME "unwind"
- VERSION "1.0"
- SOVERSION "1")
+ set_target_properties(unwind_shared
+ PROPERTIES
+ CXX_EXTENSIONS OFF
+ CXX_STANDARD 11
+ CXX_STANDARD_REQUIRED ON
+ COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}"
+ LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"
+ LINKER_LANGUAGE C
+ OUTPUT_NAME "unwind"
+ VERSION "1.0"
+ SOVERSION "1"
+ POSITION_INDEPENDENT_CODE ON
+ )
list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_shared")
if (LIBUNWIND_INSTALL_SHARED_LIBRARY)
list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_shared")
target_compile_options(unwind_static PRIVATE -fno-rtti)
endif()
target_link_libraries(unwind_static PRIVATE ${LIBUNWIND_LIBRARIES})
- set_target_properties(unwind_static PROPERTIES
- CXX_EXTENSIONS OFF
- CXX_STANDARD 11
- CXX_STANDARD_REQUIRED ON
- COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}"
- LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"
- LINKER_LANGUAGE C
- OUTPUT_NAME "unwind")
-
- if(LIBUNWIND_HERMETIC_STATIC_LIBRARY)
+ set_target_properties(unwind_static
+ PROPERTIES
+ CXX_EXTENSIONS OFF
+ CXX_STANDARD 11
+ CXX_STANDARD_REQUIRED ON
+ COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}"
+ LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"
+ LINKER_LANGUAGE C
+ OUTPUT_NAME "unwind"
+ POSITION_INDEPENDENT_CODE ON
+ )
+
+ if(LIBUNWIND_HIDE_SYMBOLS)
append_flags_if_supported(UNWIND_STATIC_LIBRARY_FLAGS -fvisibility=hidden)
append_flags_if_supported(UNWIND_STATIC_LIBRARY_FLAGS -fvisibility-global-new-delete-hidden)
target_compile_options(unwind_static PRIVATE ${UNWIND_STATIC_LIBRARY_FLAGS})
- target_compile_definitions(unwind_static PRIVATE _LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS)
+ target_compile_definitions(unwind_static PRIVATE _LIBUNWIND_HIDE_SYMBOLS)
endif()
list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_static")
if (LIBUNWIND_INSTALL_LIBRARY)
install(TARGETS ${LIBUNWIND_INSTALL_TARGETS}
- LIBRARY DESTINATION ${LIBUNWIND_INSTALL_PREFIX}${LIBUNWIND_INSTALL_LIBRARY_DIR} COMPONENT unwind
- ARCHIVE DESTINATION ${LIBUNWIND_INSTALL_PREFIX}${LIBUNWIND_INSTALL_LIBRARY_DIR} COMPONENT unwind)
+ LIBRARY DESTINATION ${LIBUNWIND_INSTALL_LIBRARY_DIR} COMPONENT unwind
+ ARCHIVE DESTINATION ${LIBUNWIND_INSTALL_LIBRARY_DIR} COMPONENT unwind
+ RUNTIME DESTINATION bin COMPONENT unwind)
endif()
if (NOT CMAKE_CONFIGURATION_TYPES AND LIBUNWIND_INSTALL_LIBRARY)