Skip to content

Commit

Permalink
#2320: prioritize HINTS over CMake's default search path
Browse files Browse the repository at this point in the history
  • Loading branch information
cwschilly authored and cz4rs committed Sep 20, 2024
1 parent eb34cc3 commit eac4674
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
1 change: 1 addition & 0 deletions ci/build_cpp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}" \
Expand Down
22 changes: 14 additions & 8 deletions cmake-modules/Findlibunwind.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion cmake/link_vt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions cmake/load_libunwind.cmake
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit eac4674

Please sign in to comment.