blob: a7a976bfd0529180725d5852f45b9ad9259fdf6b [file] [log] [blame]
James Kuszmaulba0ac1a2022-08-12 16:29:30 -07001# - Try to find libunwind
2# Once done this will define
3#
4# Unwind_FOUND - system has libunwind
5# unwind::unwind - cmake target for libunwind
6
7include (FindPackageHandleStandardArgs)
8
9find_path (Unwind_INCLUDE_DIR NAMES unwind.h libunwind.h DOC "unwind include directory")
10find_library (Unwind_LIBRARY NAMES unwind DOC "unwind library")
11
12mark_as_advanced (Unwind_INCLUDE_DIR Unwind_LIBRARY)
13
14# Extract version information
15if (Unwind_LIBRARY)
16 set (_Unwind_VERSION_HEADER ${Unwind_INCLUDE_DIR}/libunwind-common.h)
17
18 if (EXISTS ${_Unwind_VERSION_HEADER})
19 file (READ ${_Unwind_VERSION_HEADER} _Unwind_VERSION_CONTENTS)
20
21 string (REGEX REPLACE ".*#define UNW_VERSION_MAJOR[ \t]+([0-9]+).*" "\\1"
22 Unwind_VERSION_MAJOR "${_Unwind_VERSION_CONTENTS}")
23 string (REGEX REPLACE ".*#define UNW_VERSION_MINOR[ \t]+([0-9]+).*" "\\1"
24 Unwind_VERSION_MINOR "${_Unwind_VERSION_CONTENTS}")
25 string (REGEX REPLACE ".*#define UNW_VERSION_EXTRA[ \t]+([0-9]+).*" "\\1"
26 Unwind_VERSION_PATCH "${_Unwind_VERSION_CONTENTS}")
27
28 set (Unwind_VERSION ${Unwind_VERSION_MAJOR}.${Unwind_VERSION_MINOR})
29
30 if (CMAKE_MATCH_0)
31 # Third version component may be empty
32 set (Unwind_VERSION ${Unwind_VERSION}.${Unwind_VERSION_PATCH})
33 set (Unwind_VERSION_COMPONENTS 3)
34 else (CMAKE_MATCH_0)
35 set (Unwind_VERSION_COMPONENTS 2)
36 endif (CMAKE_MATCH_0)
37 endif (EXISTS ${_Unwind_VERSION_HEADER})
38endif (Unwind_LIBRARY)
39
40# handle the QUIETLY and REQUIRED arguments and set Unwind_FOUND to TRUE
41# if all listed variables are TRUE
42find_package_handle_standard_args (Unwind
43 REQUIRED_VARS Unwind_INCLUDE_DIR Unwind_LIBRARY
44 VERSION_VAR Unwind_VERSION
45)
46
47if (Unwind_FOUND)
48 if (NOT TARGET unwind::unwind)
49 add_library (unwind::unwind INTERFACE IMPORTED)
50
51 set_property (TARGET unwind::unwind PROPERTY
52 INTERFACE_INCLUDE_DIRECTORIES ${Unwind_INCLUDE_DIR}
53 )
54 set_property (TARGET unwind::unwind PROPERTY
55 INTERFACE_LINK_LIBRARIES ${Unwind_LIBRARY}
56 )
57 set_property (TARGET unwind::unwind PROPERTY
58 IMPORTED_CONFIGURATIONS RELEASE
59 )
60 endif (NOT TARGET unwind::unwind)
61endif (Unwind_FOUND)