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