diff --git a/ci/build_cpp.sh b/ci/build_cpp.sh index 2083839cb2..1e4fae89ff 100755 --- a/ci/build_cpp.sh +++ b/ci/build_cpp.sh @@ -151,6 +151,7 @@ cmake -G "${CMAKE_GENERATOR:-Ninja}" \ -Dvt_debug_verbose="${VT_DEBUG_VERBOSE:-0}" \ -Dvt_tests_num_nodes="${VT_TESTS_NUM_NODES:-}" \ -Dvt_external_fmt="${VT_EXTERNAL_FMT:-0}" \ + -DLIBUNWIND_ROOT="${LIBUNWIND_ROOT:-/usr}" \ -Dvt_no_color_enabled="${VT_NO_COLOR_ENABLED:-0}" \ -DCMAKE_CXX_STANDARD="${CMAKE_CXX_STANDARD:-17}" \ -DBUILD_SHARED_LIBS="${BUILD_SHARED_LIBS:-0}" \ diff --git a/cmake-modules/Findlibunwind.cmake b/cmake-modules/Findlibunwind.cmake new file mode 100644 index 0000000000..a82910d75e --- /dev/null +++ b/cmake-modules/Findlibunwind.cmake @@ -0,0 +1,42 @@ + +# Users can pass LIBUNWIND_ROOT, LIBUNWIND_INCLUDE_DIR, and LIBUNWIND_LIBRARY as CMake variables. +# If LIBUNWIND_ROOT is provided, the INCLUDE_DIR and LIBRARY variables may be omitted. +# +# LIBUNWIND_FOUND, LIBUNWIND_INCLUDE_DIRS, and LIBUNWIND_LIBRARIES are outputs + +if(LIBUNWIND_ROOT) + set(LIBUNWIND_INCLUDE_DIR ${LIBUNWIND_INCLUDE_DIR};${LIBUNWIND_ROOT}/include) + set(LIBUNWIND_LIBRARY ${LIBUNWIND_LIBRARY};${LIBUNWIND_ROOT}/lib64;${LIBUNWIND_ROOT}/lib) +endif() + +# First, check only in the hinted paths +find_path(LIBUNWIND_INCLUDE_DIRS NAMES libunwind.h + DOC "The libunwind include directory" + HINTS ${LIBUNWIND_INCLUDE_DIR} + NO_DEFAULT_PATH +) +find_library(LIBUNWIND_LIBRARIES NAMES unwind + DOC "The libunwind library" + HINTS ${LIBUNWIND_LIBRARY} + NO_DEFAULT_PATH +) + +# If that fails, check in CMake's default paths +find_path(LIBUNWIND_INCLUDE_DIRS NAMES libunwind.h + DOC "The libunwind include directory" +) +find_library(LIBUNWIND_LIBRARIES NAMES unwind + DOC "The libunwind library" +) + +include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(LIBUNWIND + REQUIRED_VARS LIBUNWIND_LIBRARIES LIBUNWIND_INCLUDE_DIRS) + +if(LIBUNWIND_FOUND) + if(NOT TARGET libunwind) + add_library(libunwind UNKNOWN IMPORTED) + set_target_properties(libunwind PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${LIBUNWIND_INCLUDE_DIRS}") + set_property(TARGET libunwind APPEND PROPERTY IMPORTED_LOCATION "${LIBUNWIND_LIBRARY}") + endif() +endif() diff --git a/cmake/check_system_functions.cmake b/cmake/check_system_functions.cmake index 14aa261bed..4c8a2d4a05 100644 --- a/cmake/check_system_functions.cmake +++ b/cmake/check_system_functions.cmake @@ -10,7 +10,6 @@ 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(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..ffd0b8e821 100644 --- a/cmake/link_vt.cmake +++ b/cmake/link_vt.cmake @@ -94,13 +94,13 @@ 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_feature_cmake_libunwind) if (${ARG_DEBUG_LINK}) message(STATUS "link_target_with_vt: unwind=${ARG_LINK_UNWIND}") endif() if (NOT DEFINED APPLE) target_link_libraries( - ${ARG_TARGET} PUBLIC ${ARG_BUILD_TYPE} unwind + ${ARG_TARGET} PUBLIC ${ARG_BUILD_TYPE} ${LIBUNWIND_LIBRARIES} ) endif() endif() diff --git a/cmake/load_libunwind.cmake b/cmake/load_libunwind.cmake new file mode 100644 index 0000000000..96814f9d51 --- /dev/null +++ b/cmake/load_libunwind.cmake @@ -0,0 +1,11 @@ +set(vt_feature_cmake_libunwind "0") + +if(NOT DEFINED LIBUNWIND_ROOT) + set(LIBUNWIND_ROOT "/usr") +endif() + +find_package(libunwind) + +if(LIBUNWIND_FOUND) + set(vt_feature_cmake_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..ac4d937a4a 100644 --- a/cmake_config.h.in +++ b/cmake_config.h.in @@ -66,6 +66,7 @@ #define vt_feature_cmake_debug_verbose @vt_feature_cmake_debug_verbose@ #define vt_feature_cmake_rdma_tests @vt_feature_cmake_rdma_tests@ #define vt_feature_cmake_external_fmt @vt_feature_cmake_external_fmt@ +#define vt_feature_cmake_libunwind @vt_feature_cmake_libunwind@ #define vt_detected_max_num_nodes @cmake_detected_max_num_nodes@ @@ -89,7 +90,6 @@ #cmakedefine vt_has_unistd_h #cmakedefine vt_has_inttypes_h #cmakedefine vt_has_sysconf -#cmakedefine vt_has_libunwind_h #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..467e0b33eb 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 vt_check_enabled(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 vt_check_enabled(libunwind) unw_cursor_t cursor; unw_context_t context; @@ -152,7 +152,8 @@ DumpStackType dumpStack(int skip) { std::free(symbols); return stack; - #else //neither libnunwind.h or libexecinfo.h is available + #else // neither libunwind.h nor libexecinfo.h is available + (void)skip; return stack; #endif } diff --git a/src/vt/configs/features/features_defines.h b/src/vt/configs/features/features_defines.h index d1455cc10d..d322443be6 100644 --- a/src/vt/configs/features/features_defines.h +++ b/src/vt/configs/features/features_defines.h @@ -73,6 +73,7 @@ #define vt_feature_production_build 0 || vt_feature_cmake_production_build #define vt_feature_debug_verbose 0 || vt_feature_cmake_debug_verbose #define vt_feature_fmt_external 0 || vt_feature_cmake_external_fmt +#define vt_feature_libunwind 0 || vt_feature_cmake_libunwind #define vt_check_enabled(test_option) (vt_feature_ ## test_option != 0) diff --git a/tests/unit/configs/test_stack_dumping.cc b/tests/unit/configs/test_stack_dumping.cc index 9aac6ea480..2b2bc16750 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 vt_check_enabled(libunwind) || defined(vt_has_execinfo_h) struct TestStackDumping : TestParallelHarness {};