Skip to content

Commit 3b6ce34

Browse files
committed
CMake - introduce dependency on libunwind
1 parent 59f3aa9 commit 3b6ce34

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

cmake/dependencies.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ find_package(PkgConfig REQUIRED)
33

44
find_package(Threads REQUIRED)
55
find_package(Atomic REQUIRED)
6+
find_package(Unwind REQUIRED)

cmake/modules/FindUnwind.cmake

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Find unwind library
2+
# Once done this will define
3+
#
4+
# UNWIND_FOUND - system has libunwind
5+
# unwind::unwind - cmake target
6+
7+
find_package(PkgConfig QUIET)
8+
if (PKG_CONFIG_FOUND)
9+
pkg_check_modules(PC_UNWIND QUIET libunwind)
10+
endif()
11+
12+
find_path (UNWIND_INCLUDE_DIR
13+
NAMES unwind.h libunwind.h
14+
HINTS ${UNWIND_ROOT} ${PC_UNWIND_INCLUDEDIR} ${PC_UNWIND_INCLUDE_DIRS}
15+
PATH_SUFFIXES ${CMAKE_INSTALL_LIBDIR}
16+
)
17+
18+
find_library (UNWIND_LIBRARY
19+
NAMES unwind
20+
HINTS ${UNWIND_ROOT} ${PC_UNWIND_LIBDIR} ${PC_UNWIND_LIBRARY_DIRS}
21+
PATH_SUFFIXES ${CMAKE_INSTALL_LIBDIR}
22+
)
23+
24+
mark_as_advanced (UNWIND_INCLUDE_DIR UNWIND_LIBRARY)
25+
26+
include (FindPackageHandleStandardArgs)
27+
# handle the QUIETLY and REQUIRED arguments and set Unwind_FOUND to TRUE
28+
# if all listed variables are TRUE
29+
find_package_handle_standard_args (Unwind
30+
REQUIRED_VARS UNWIND_INCLUDE_DIR UNWIND_LIBRARY
31+
)
32+
33+
if (UNWIND_FOUND AND NOT TARGET unwind::unwind)
34+
add_library(unwind::unwind STATIC IMPORTED)
35+
set_target_properties(unwind::unwind PROPERTIES
36+
IMPORTED_LOCATION "${UNWIND_LIBRARY}"
37+
INTERFACE_INCLUDE_DIRECTORIES "${UNWIND_INCLUDE_DIR}")
38+
target_compile_definitions(unwind::unwind INTERFACE UNWIND_FOUND)
39+
else()
40+
message(WARNING "Notice: UNWIND not found, no unwind support")
41+
add_library(unwind::unwind INTERFACE IMPORTED)
42+
endif()
43+
44+
unset(UNWIND_INCLUDE_DIR)
45+
unset(UNWIND_LIBRARY)

0 commit comments

Comments
 (0)