From 227fe09b3ea9aa7bfc25f0dfa0195fbf21268ff7 Mon Sep 17 00:00:00 2001 From: Caleb Schilly Date: Wed, 31 Jul 2024 12:16:25 -0400 Subject: [PATCH 01/10] #2320: add Findlibunwind.cmake file --- cmake-modules/Findlibunwind.cmake | 70 ++++++++++++++++++++++++ cmake/check_system_functions.cmake | 2 +- cmake/link_vt.cmake | 2 +- cmake/load_libunwind.cmake | 7 +++ cmake/load_packages.cmake | 3 + cmake_config.h.in | 2 +- src/vt/configs/error/stack_out.cc | 4 +- tests/unit/configs/test_stack_dumping.cc | 2 +- 8 files changed, 86 insertions(+), 6 deletions(-) create mode 100644 cmake-modules/Findlibunwind.cmake create mode 100644 cmake/load_libunwind.cmake 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 {}; From 681e7dbb5143a3485be5a0922a8db99348d83b6b Mon Sep 17 00:00:00 2001 From: Caleb Schilly Date: Wed, 31 Jul 2024 12:35:32 -0400 Subject: [PATCH 02/10] #2320: remove libunwind from check_system_functions --- cmake/check_system_functions.cmake | 1 - 1 file changed, 1 deletion(-) diff --git a/cmake/check_system_functions.cmake b/cmake/check_system_functions.cmake index 82b9653d5f..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) check_include_files(execinfo.h vt_has_execinfo_h) check_function_exists(mstats vt_has_mstats) From 4f3893a6e24d17844545e6d09a65d9fa3ab81729 Mon Sep 17 00:00:00 2001 From: Caleb Schilly Date: Wed, 31 Jul 2024 15:41:09 -0400 Subject: [PATCH 03/10] #2320: resolve unused parameter warning --- src/vt/configs/error/stack_out.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/vt/configs/error/stack_out.cc b/src/vt/configs/error/stack_out.cc index c681df3bf0..b176918c02 100644 --- a/src/vt/configs/error/stack_out.cc +++ b/src/vt/configs/error/stack_out.cc @@ -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 } From d21f59fe27f3372e67581f3894ee5aefb02c770e Mon Sep 17 00:00:00 2001 From: Caleb Schilly Date: Wed, 31 Jul 2024 16:29:27 -0400 Subject: [PATCH 04/10] #2320: fix linking with unwind --- cmake/link_vt.cmake | 2 +- cmake/load_libunwind.cmake | 6 +++--- cmake_config.h.in | 2 +- src/vt/configs/error/stack_out.cc | 4 ++-- src/vt/configs/features/features_defines.h | 1 + tests/unit/configs/test_stack_dumping.cc | 2 +- 6 files changed, 9 insertions(+), 8 deletions(-) diff --git a/cmake/link_vt.cmake b/cmake/link_vt.cmake index 4c5f6925ed..1e0dda92ab 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) + if (vt_feature_cmake_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 index 63889a043a..7051a35393 100644 --- a/cmake/load_libunwind.cmake +++ b/cmake/load_libunwind.cmake @@ -1,7 +1,7 @@ -set(vt_has_libunwind 0) +set(vt_feature_cmake_libunwind "0") find_package(libunwind) -if(libunwind_FOUND) - set(vt_has_libunwind 1) +if(LIBUNWIND_FOUND) + set(vt_feature_cmake_libunwind "1") endif() diff --git a/cmake_config.h.in b/cmake_config.h.in index 4f91094810..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 #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 b176918c02..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) +#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) + #if vt_check_enabled(libunwind) unw_cursor_t cursor; unw_context_t context; 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 19a454179c..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) || defined(vt_has_execinfo_h) +#if vt_check_enabled(libunwind) || defined(vt_has_execinfo_h) struct TestStackDumping : TestParallelHarness {}; From 731dd72b233baf097439879b06d64a454f1bf923 Mon Sep 17 00:00:00 2001 From: Caleb Schilly Date: Thu, 1 Aug 2024 16:46:59 -0400 Subject: [PATCH 05/10] #2320: prioritize HINTS over CMake's default search path --- ci/build_cpp.sh | 1 + cmake-modules/Findlibunwind.cmake | 22 ++++++++++++++-------- cmake/link_vt.cmake | 2 +- cmake/load_libunwind.cmake | 4 ++++ 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/ci/build_cpp.sh b/ci/build_cpp.sh index 2083839cb2..40c2852de7 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}" \ + -D libunwind_ROOT_DIR="${LIBUNWIND_ROOT_DIR:-/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 index c1b49386e0..209726052c 100644 --- a/cmake-modules/Findlibunwind.cmake +++ b/cmake-modules/Findlibunwind.cmake @@ -2,7 +2,7 @@ # # - Try to find Libunwind # Input variables: -# LIBUNWIND_ROOT_DIR - The libunwind install directory +# libunwind_ROOT_DIR - The libunwind install directory # LIBUNWIND_INCLUDE_DIR - The libunwind include directory # LIBUNWIND_LIBRARY - The libunwind library directory # Output variables: @@ -16,20 +16,26 @@ 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(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") + 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") + set(LIBUNWIND_LIBRARY ${libunwind_ROOT_DIR}/lib CACHE PATH "The library directory for libunwind") endif() endif() + # First, try searching in libunwind_ROOT ("/usr" by default) find_path(LIBUNWIND_INCLUDE_DIRS NAMES libunwind.h - HINTS ${LIBUNWIND_INCLUDE_DIR}) - + HINTS ${LIBUNWIND_INCLUDE_DIR} + NO_DEFAULT_PATH) find_library(LIBUNWIND_LIBRARIES unwind - HINTS ${LIBUNWIND_LIBRARY}) + HINTS ${LIBUNWIND_LIBRARY} + NO_DEFAULT_PATH) + + # If that fails, use CMake's default path + find_path(LIBUNWIND_INCLUDE_DIRS NAMES libunwind.h) + find_library(LIBUNWIND_LIBRARIES unwind) # Get libunwind version if(EXISTS "${LIBUNWIND_INCLUDE_DIRS}/libunwind-common.h") diff --git a/cmake/link_vt.cmake b/cmake/link_vt.cmake index 1e0dda92ab..ffd0b8e821 100644 --- a/cmake/link_vt.cmake +++ b/cmake/link_vt.cmake @@ -100,7 +100,7 @@ function(link_target_with_vt) 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 index 7051a35393..70260cbaff 100644 --- a/cmake/load_libunwind.cmake +++ b/cmake/load_libunwind.cmake @@ -1,5 +1,9 @@ set(vt_feature_cmake_libunwind "0") +if(NOT DEFINED libunwind_ROOT_DIR) + set(libunwind_ROOT_DIR "/usr") +endif() + find_package(libunwind) if(LIBUNWIND_FOUND) From f958f15fff42544aa1c643a8d85fbc8dea9e182a Mon Sep 17 00:00:00 2001 From: Caleb Schilly Date: Thu, 1 Aug 2024 16:56:47 -0400 Subject: [PATCH 06/10] #2320: fix spacing in build_cpp configuration --- ci/build_cpp.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/build_cpp.sh b/ci/build_cpp.sh index 40c2852de7..170fd365c1 100755 --- a/ci/build_cpp.sh +++ b/ci/build_cpp.sh @@ -151,7 +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}" \ - -D libunwind_ROOT_DIR="${LIBUNWIND_ROOT_DIR:-/usr}" \ + -Dlibunwind_ROOT_DIR="${LIBUNWIND_ROOT_DIR:-/usr}" \ -Dvt_no_color_enabled="${VT_NO_COLOR_ENABLED:-0}" \ -DCMAKE_CXX_STANDARD="${CMAKE_CXX_STANDARD:-17}" \ -DBUILD_SHARED_LIBS="${BUILD_SHARED_LIBS:-0}" \ From b227539dc6edeeb7631d1d8a8c3f886baae5ca16 Mon Sep 17 00:00:00 2001 From: Caleb Schilly Date: Fri, 2 Aug 2024 14:54:33 -0400 Subject: [PATCH 07/10] #2320: fix typos in Findlibunwind.cmake and add notice of modification --- cmake-modules/Findlibunwind.cmake | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cmake-modules/Findlibunwind.cmake b/cmake-modules/Findlibunwind.cmake index 209726052c..708330ae7c 100644 --- a/cmake-modules/Findlibunwind.cmake +++ b/cmake-modules/Findlibunwind.cmake @@ -1,10 +1,12 @@ -# This file downloaded from https://raw.githubusercontent.com/m-a-d-n-e-s-s/madness/master/cmake/modules/FindLibunwind.cmake +# This file was downloaded from https://raw.githubusercontent.com/m-a-d-n-e-s-s/madness/master/cmake/modules/FindLibunwind.cmake +# and modified on August 2 2024 # # - 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 @@ -15,7 +17,7 @@ include(FindPackageHandleStandardArgs) if(NOT DEFINED LIBUNWIND_FOUND) - # Set default sarch paths for libunwind + # Set default search 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") @@ -54,7 +56,7 @@ if(NOT DEFINED LIBUNWIND_FOUND) unset(_libunwind_version_header) endif() - # handle the QUIETLY and REQUIRED arguments and set LIBUNWIND_FOUND to TRUE + # 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 From ec3dc2ea4d4ed0705032c4da03371f643fedc393 Mon Sep 17 00:00:00 2001 From: Caleb Schilly Date: Mon, 5 Aug 2024 14:59:03 -0400 Subject: [PATCH 08/10] #2320: rework Findlibunwind.cmake --- ci/build_cpp.sh | 2 +- cmake-modules/Findlibunwind.cmake | 105 ++++++++++-------------------- cmake/load_libunwind.cmake | 4 +- 3 files changed, 37 insertions(+), 74 deletions(-) diff --git a/ci/build_cpp.sh b/ci/build_cpp.sh index 170fd365c1..1e4fae89ff 100755 --- a/ci/build_cpp.sh +++ b/ci/build_cpp.sh @@ -151,7 +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_DIR="${LIBUNWIND_ROOT_DIR:-/usr}" \ + -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 index 708330ae7c..0bc938d8bc 100644 --- a/cmake-modules/Findlibunwind.cmake +++ b/cmake-modules/Findlibunwind.cmake @@ -1,78 +1,41 @@ -# This file was downloaded from https://raw.githubusercontent.com/m-a-d-n-e-s-s/madness/master/cmake/modules/FindLibunwind.cmake -# and modified on August 2 2024 -# -# - 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 search 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() - - # First, try searching in libunwind_ROOT ("/usr" by default) - find_path(LIBUNWIND_INCLUDE_DIRS NAMES libunwind.h - HINTS ${LIBUNWIND_INCLUDE_DIR} - NO_DEFAULT_PATH) - find_library(LIBUNWIND_LIBRARIES unwind - HINTS ${LIBUNWIND_LIBRARY} - NO_DEFAULT_PATH) - # If that fails, use CMake's default path - find_path(LIBUNWIND_INCLUDE_DIRS NAMES libunwind.h) - find_library(LIBUNWIND_LIBRARIES unwind) - - # 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) +# Users can pass LIBUNWIND_ROOT, LIBUNWIND_INCLUDE_DIR, and LIBUNWIND_LIBRARY as CMake variables +# +# LIBUNWIND_FOUND, LIBUNWIND_INCLUDE_DIRS, and LIBUNWIND_LIBRARIES are outputs +if(LIBUNWIND_ROOT) + set(LIBUNWIND_INCLUDE_DIR ${LIBUNWIND_ROOT}/include CACHE PATH "The include directory for libunwind") + set(LIBUNWIND_LIBRARY ${LIBUNWIND_ROOT}/lib64;${LIBUNWIND_ROOT}/lib CACHE PATH "The library directory for libunwind") 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::LIBUNWIND) - add_library(LIBUNWIND::LIBUNWIND UNKNOWN IMPORTED) - set_target_properties(LIBUNWIND::LIBUNWIND PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${LIBUNWIND_INCLUDE_DIRS}" - IMPORTED_LOCATION "${LIBUNWIND_LIBRARIES}" ) + 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/load_libunwind.cmake b/cmake/load_libunwind.cmake index 70260cbaff..96814f9d51 100644 --- a/cmake/load_libunwind.cmake +++ b/cmake/load_libunwind.cmake @@ -1,7 +1,7 @@ set(vt_feature_cmake_libunwind "0") -if(NOT DEFINED libunwind_ROOT_DIR) - set(libunwind_ROOT_DIR "/usr") +if(NOT DEFINED LIBUNWIND_ROOT) + set(LIBUNWIND_ROOT "/usr") endif() find_package(libunwind) From 21e4c5e1401f03528afc9866bf6bcf07a3a15f49 Mon Sep 17 00:00:00 2001 From: Caleb Schilly Date: Tue, 6 Aug 2024 10:26:08 -0400 Subject: [PATCH 09/10] #2320: use both root and include/lib dirs as hints --- cmake-modules/Findlibunwind.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake-modules/Findlibunwind.cmake b/cmake-modules/Findlibunwind.cmake index 0bc938d8bc..bfd966bd2c 100644 --- a/cmake-modules/Findlibunwind.cmake +++ b/cmake-modules/Findlibunwind.cmake @@ -4,8 +4,8 @@ # LIBUNWIND_FOUND, LIBUNWIND_INCLUDE_DIRS, and LIBUNWIND_LIBRARIES are outputs if(LIBUNWIND_ROOT) - set(LIBUNWIND_INCLUDE_DIR ${LIBUNWIND_ROOT}/include CACHE PATH "The include directory for libunwind") - set(LIBUNWIND_LIBRARY ${LIBUNWIND_ROOT}/lib64;${LIBUNWIND_ROOT}/lib CACHE PATH "The library directory for libunwind") + 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 From c77ba38cda35f0c4019ef7b8eec591072edf4e24 Mon Sep 17 00:00:00 2001 From: Caleb Schilly Date: Tue, 6 Aug 2024 10:28:51 -0400 Subject: [PATCH 10/10] #2320: add clarifying comment --- cmake-modules/Findlibunwind.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmake-modules/Findlibunwind.cmake b/cmake-modules/Findlibunwind.cmake index bfd966bd2c..a82910d75e 100644 --- a/cmake-modules/Findlibunwind.cmake +++ b/cmake-modules/Findlibunwind.cmake @@ -1,5 +1,6 @@ -# Users can pass LIBUNWIND_ROOT, LIBUNWIND_INCLUDE_DIR, and LIBUNWIND_LIBRARY as CMake variables +# 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