blob: 15cf67fd2ead627e432c8bec68b421cd5ccd4e2c [file] [log] [blame]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001diff -uNr a/cmake/FindLibunwind.cmake b/cmake/FindLibunwind.cmake
2--- a/cmake/FindLibunwind.cmake 1970-01-01 01:00:00.000000000 +0100
3+++ b/cmake/FindLibunwind.cmake 2018-11-20 15:53:48.799078114 +0100
4@@ -0,0 +1,54 @@
5+# - Try to find libunwind
6+# Once done this will define
7+#
8+# Libunwind_FOUND - system has libunwind
9+# unwind - cmake target for libunwind
10+
11+find_library (UNWIND_LIBRARY NAMES unwind DOC "unwind library")
12+include (CheckIncludeFile)
13+check_include_file (libunwind.h HAVE_LIBUNWIND_H)
14+check_include_file (unwind.h HAVE_UNWIND_H)
15+
16+if (CMAKE_SYSTEM_PROCESSOR MATCHES "^arm")
17+ set(LIBUNWIND_ARCH "arm")
18+elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch64")
19+ set(LIBUNWIND_ARCH "aarch64")
20+elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR
21+ CMAKE_SYSTEM_PROCESSOR STREQUAL "amd64" OR
22+ CMAKE_SYSTEM_PROCESSOR STREQUAL "corei7-64")
23+ set(LIBUNWIND_ARCH "x86_64")
24+elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^i.86$")
25+ set(LIBUNWIND_ARCH "x86")
26+elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^ppc64")
27+ set(LIBUNWIND_ARCH "ppc64")
28+elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^ppc")
29+ set(LIBUNWIND_ARCH "ppc32")
30+elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^mips")
31+ set(LIBUNWIND_ARCH "mips")
32+elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^hppa")
33+ set(LIBUNWIND_ARCH "hppa")
34+elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^ia64")
35+ set(LIBUNWIND_ARCH "ia64")
36+endif()
37+
38+find_library (UNWIND_LIBRARY_PLATFORM NAMES "unwind-${LIBUNWIND_ARCH}" DOC "unwind library platform")
39+if (UNWIND_LIBRARY_PLATFORM)
40+ set(HAVE_LIB_UNWIND "1")
41+endif()
42+
43+include(FindPackageHandleStandardArgs)
44+# handle the QUIETLY and REQUIRED arguments and set Libunwind_FOUND to TRUE
45+# if all listed variables are TRUE
46+find_package_handle_standard_args(Libunwind DEFAULT_MSG
47+ UNWIND_LIBRARY HAVE_LIBUNWIND_H HAVE_UNWIND_H HAVE_LIB_UNWIND)
48+
49+mark_as_advanced (UNWIND_LIBRARY UNWIND_LIBRARY_PLATFORM)
50+
51+if (Libunwind_FOUND)
52+ add_library(unwind INTERFACE IMPORTED)
53+ set_target_properties(unwind PROPERTIES
54+ INTERFACE_LINK_LIBRARIES "${UNWIND_LIBRARY};${UNWIND_LIBRARY_PLATFORM}"
55+ )
56+else()
57+ message("Can't find libunwind library")
58+endif()
59diff -uNr a/CMakeLists.txt b/CMakeLists.txt
60--- a/CMakeLists.txt 2018-11-20 15:49:07.576278417 +0100
61+++ b/CMakeLists.txt 2018-11-20 15:49:32.106819928 +0100
62@@ -58,7 +58,6 @@
63 check_include_file (execinfo.h HAVE_EXECINFO_H)
64 check_include_file (glob.h HAVE_GLOB_H)
65 check_include_file (inttypes.h HAVE_INTTYPES_H)
66-check_include_file (libunwind.h HAVE_LIBUNWIND_H)
67 check_include_file (memory.h HAVE_MEMORY_H)
68 check_include_file (pwd.h HAVE_PWD_H)
69 check_include_file (stdint.h HAVE_STDINT_H)
70@@ -74,7 +73,6 @@
71 check_include_file (syslog.h HAVE_SYSLOG_H)
72 check_include_file (ucontext.h HAVE_UCONTEXT_H)
73 check_include_file (unistd.h HAVE_UNISTD_H)
74-check_include_file (unwind.h HAVE_UNWIND_H)
75
76 check_include_file_cxx ("ext/hash_map" HAVE_EXT_HASH_MAP)
77 check_include_file_cxx ("ext/hash_set" HAVE_EXT_HASH_SET)
78@@ -109,10 +107,7 @@
79 # snprintf as an inline function
80 check_symbol_exists (snprintf stdio.h HAVE_SNPRINTF)
81
82-check_library_exists (unwind get_static_proc_name "" HAVE_LIB_UNWIND)
83-
84-find_library (UNWIND_LIBRARY NAMES unwind DOC "unwind library")
85-mark_as_advanced (UNWIND_LIBRARY)
86+find_package(Libunwind)
87
88 check_c_source_compiles ("
89 #include <stdlib.h>
90@@ -376,9 +371,9 @@
91
92 set_target_properties (glog PROPERTIES POSITION_INDEPENDENT_CODE ON)
93
94-if (UNWIND_LIBRARY)
95- target_link_libraries (glog PUBLIC ${UNWIND_LIBRARY})
96-endif (UNWIND_LIBRARY)
97+if (Libunwind_FOUND)
98+ target_link_libraries (glog PUBLIC unwind)
99+endif (Libunwind_FOUND)
100
101 if (HAVE_PTHREAD)
102 target_link_libraries (glog PUBLIC ${CMAKE_THREAD_LIBS_INIT})
103@@ -571,6 +566,7 @@
104 install (FILES
105 ${CMAKE_CURRENT_BINARY_DIR}/glog-config.cmake
106 ${CMAKE_CURRENT_BINARY_DIR}/glog-config-version.cmake
107+ ${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindLibunwind.cmake
108 DESTINATION lib/cmake/glog)
109
110 install (EXPORT glog-targets NAMESPACE glog:: DESTINATION lib/cmake/glog)
111diff -uNr a/glog-config.cmake.in b/glog-config.cmake.in
112--- a/glog-config.cmake.in 2018-11-20 15:49:07.576278417 +0100
113+++ b/glog-config.cmake.in 2018-11-20 15:52:32.330418489 +0100
114@@ -4,4 +4,6 @@
115
116 @gflags_DEPENDENCY@
117
118+find_dependency (Libunwind)
119+
120 include ("${CMAKE_CURRENT_LIST_DIR}/glog-targets.cmake")