diff --git a/cmake-modules/Findlibunwind.cmake b/cmake-modules/Findlibunwind.cmake new file mode 100644 index 0000000000..c1b49386e0 --- /dev/null +++ b/cmake-modules/Findlibunwind.cmake @@ -0,0 +1,70 @@ +# This file downloaded from https://raw.githubusercontent.com/m-a-d-n-e-s-s/madness/master/cmake/modules/FindLibunwind.cmake +# +# - Try to find Libunwind +# Input variables: +# LIBUNWIND_ROOT_DIR - The libunwind install directory +# LIBUNWIND_INCLUDE_DIR - The libunwind include directory +# LIBUNWIND_LIBRARY - The libunwind library directory +# Output variables: +# LIBUNWIND_FOUND - System has libunwind +# LIBUNWIND_INCLUDE_DIRS - The libunwind include directories +# LIBUNWIND_LIBRARIES - The libraries needed to use libunwind +# LIBUNWIND_VERSION - The version string for libunwind + +include(FindPackageHandleStandardArgs) + +if(NOT DEFINED LIBUNWIND_FOUND) + + # Set default sarch paths for libunwind + if(LIBUNWIND_ROOT_DIR) + set(LIBUNWIND_INCLUDE_DIR ${LIBUNWIND_ROOT_DIR}/include CACHE PATH "The include directory for libunwind") + if(CMAKE_SIZEOF_VOID_P EQUAL 8 AND CMAKE_SYSTEM_NAME STREQUAL "Linux") + set(LIBUNWIND_LIBRARY ${LIBUNWIND_ROOT_DIR}/lib64;${LIBUNWIND_ROOT_DIR}/lib CACHE PATH "The library directory for libunwind") + else() + set(LIBUNWIND_LIBRARY ${LIBUNWIND_ROOT_DIR}/lib CACHE PATH "The library directory for libunwind") + endif() + endif() + + find_path(LIBUNWIND_INCLUDE_DIRS NAMES libunwind.h + HINTS ${LIBUNWIND_INCLUDE_DIR}) + + find_library(LIBUNWIND_LIBRARIES unwind + HINTS ${LIBUNWIND_LIBRARY}) + + # Get libunwind version + if(EXISTS "${LIBUNWIND_INCLUDE_DIRS}/libunwind-common.h") + file(READ "${LIBUNWIND_INCLUDE_DIRS}/libunwind-common.h" _libunwind_version_header) + string(REGEX REPLACE ".*define[ \t]+UNW_VERSION_MAJOR[ \t]+([0-9]+).*" "\\1" + LIBUNWIND_MAJOR_VERSION "${_libunwind_version_header}") + string(REGEX REPLACE ".*define[ \t]+UNW_VERSION_MINOR[ \t]+([0-9]+).*" "\\1" + LIBUNWIND_MINOR_VERSION "${_libunwind_version_header}") + string(REGEX REPLACE ".*define[ \t]+UNW_VERSION_EXTRA[ \t]+([0-9]*).*" "\\1" + LIBUNWIND_MICRO_VERSION "${_libunwind_version_header}") + if(LIBUNWIND_MICRO_VERSION) + set(LIBUNWIND_VERSION "${LIBUNWIND_MAJOR_VERSION}.${LIBUNWIND_MINOR_VERSION}.${LIBUNWIND_MICRO_VERSION}") + else() + set(LIBUNWIND_VERSION "${LIBUNWIND_MAJOR_VERSION}.${LIBUNWIND_MINOR_VERSION}") + endif() + unset(_libunwind_version_header) + endif() + + # handle the QUIETLY and REQUIRED arguments and set LIBUNWIND_FOUND to TRUE + # if all listed variables are TRUE + find_package_handle_standard_args(Libunwind + FOUND_VAR LIBUNWIND_FOUND + VERSION_VAR LIBUNWIND_VERSION + REQUIRED_VARS LIBUNWIND_LIBRARIES LIBUNWIND_INCLUDE_DIRS) + + mark_as_advanced(LIBUNWIND_INCLUDE_DIR LIBUNWIND_LIBRARY + LIBUNWIND_INCLUDE_DIRS LIBUNWIND_LIBRARIES) + +endif() + +if(LIBUNWIND_FOUND) + if(NOT TARGET LIBUNWIND::LIBUNWIND) + add_library(LIBUNWIND::LIBUNWIND UNKNOWN IMPORTED) + set_target_properties(LIBUNWIND::LIBUNWIND PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${LIBUNWIND_INCLUDE_DIRS}" + IMPORTED_LOCATION "${LIBUNWIND_LIBRARIES}" ) + endif() +endif() diff --git a/cmake/check_system_functions.cmake b/cmake/check_system_functions.cmake index 14aa261bed..82b9653d5f 100644 --- a/cmake/check_system_functions.cmake +++ b/cmake/check_system_functions.cmake @@ -10,7 +10,7 @@ check_include_files(mach/mach.h vt_has_mach_mach_h) check_include_files(sys/resource.h vt_has_sys_resource_h) check_include_files(unistd.h vt_has_unistd_h) check_include_files(inttypes.h vt_has_inttypes_h) -check_include_files(libunwind.h vt_has_libunwind_h) +# check_include_files(libunwind.h vt_has_libunwind) check_include_files(execinfo.h vt_has_execinfo_h) check_function_exists(mstats vt_has_mstats) diff --git a/cmake/link_vt.cmake b/cmake/link_vt.cmake index e9a5c9c1e7..4c5f6925ed 100644 --- a/cmake/link_vt.cmake +++ b/cmake/link_vt.cmake @@ -94,7 +94,7 @@ function(link_target_with_vt) endif() if (NOT DEFINED ARG_LINK_UNWIND AND ${ARG_DEFAULT_LINK_SET} OR ARG_LINK_UNWIND) - if (vt_has_libunwind_h) + if (vt_has_libunwind) if (${ARG_DEBUG_LINK}) message(STATUS "link_target_with_vt: unwind=${ARG_LINK_UNWIND}") endif() diff --git a/cmake/load_libunwind.cmake b/cmake/load_libunwind.cmake new file mode 100644 index 0000000000..63889a043a --- /dev/null +++ b/cmake/load_libunwind.cmake @@ -0,0 +1,7 @@ +set(vt_has_libunwind 0) + +find_package(libunwind) + +if(libunwind_FOUND) + set(vt_has_libunwind 1) +endif() diff --git a/cmake/load_packages.cmake b/cmake/load_packages.cmake index fa7939d109..5932b51939 100644 --- a/cmake/load_packages.cmake +++ b/cmake/load_packages.cmake @@ -15,6 +15,9 @@ find_package(Perl) # Doxygen package include(cmake/load_doxygen.cmake) +# Optionally link with libunwind +include(cmake/load_libunwind.cmake) + # Optionally link with Zoltan include(cmake/load_zoltan_package.cmake) diff --git a/cmake_config.h.in b/cmake_config.h.in index c10bea5e62..4f91094810 100644 --- a/cmake_config.h.in +++ b/cmake_config.h.in @@ -89,7 +89,7 @@ #cmakedefine vt_has_unistd_h #cmakedefine vt_has_inttypes_h #cmakedefine vt_has_sysconf -#cmakedefine vt_has_libunwind_h +#cmakedefine vt_has_libunwind #cmakedefine vt_has_execinfo_h #if vt_feature_cmake_external_fmt diff --git a/src/vt/configs/error/stack_out.cc b/src/vt/configs/error/stack_out.cc index 97c5fd1520..c681df3bf0 100644 --- a/src/vt/configs/error/stack_out.cc +++ b/src/vt/configs/error/stack_out.cc @@ -47,7 +47,7 @@ #include -#if defined(vt_has_libunwind_h) +#if defined(vt_has_libunwind) # define UNW_LOCAL_ONLY # include #elif defined(vt_has_execinfo_h) @@ -59,7 +59,7 @@ namespace vt { namespace debug { namespace stack { DumpStackType dumpStack(int skip) { DumpStackType stack; - #if defined(vt_has_libunwind_h) + #if defined(vt_has_libunwind) unw_cursor_t cursor; unw_context_t context; diff --git a/tests/unit/configs/test_stack_dumping.cc b/tests/unit/configs/test_stack_dumping.cc index 9aac6ea480..19a454179c 100644 --- a/tests/unit/configs/test_stack_dumping.cc +++ b/tests/unit/configs/test_stack_dumping.cc @@ -49,7 +49,7 @@ namespace vt { namespace tests { namespace unit { -#if defined(vt_has_libunwind_h) || defined(vt_has_execinfo_h) +#if defined(vt_has_libunwind) || defined(vt_has_execinfo_h) struct TestStackDumping : TestParallelHarness {};