-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
121 lines (92 loc) · 4.2 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
cmake_minimum_required(VERSION 3.19)
set(MAX_CAPTURE_FRAMES "100")
set(CXX_STANDARD 11)
project(stacktrace VERSION 1.1 DESCRIPTION "stacktrace" LANGUAGES CXX)
add_library(stacktrace INTERFACE include/stacktrace_exception.h include/code_position_exception.h)
if (WIN32)
set(_OS_NAME "win")
elseif (UNIX)
set(_OS_NAME "linux")
elseif (APPLE)
set(_OS_NAME "mac")
endif()
# set defaults
set(IS_STACKTRACE_DEFAULT ON)
set(IS_DECODE_DEFAULT ON)
file(READ "compat-cfg.json" _COMPATIBILITY_TABLE_JSON)
if (WIN32)
set(STACKTRACE_BACKEND "winapi")
set(DECODE_BACKEND "winapi")
elseif (UNIX OR APPLE)
set(STACKTRACE_BACKEND "execinfo")
set(DECODE_BACKEND "libbacktrace")
endif()
if (DEFINED USE_STACKTRACE_BACKEND)
set(IS_STACKTRACE_DEFAULT OFF)
set(STACKTRACE_BACKEND ${USE_STACKTRACE_BACKEND})
endif()
if (DEFINED USE_DECODE_BACKEND)
set(IS_DECODE_DEFAULT OFF)
set(DECODE_BACKEND ${USE_DECODE_BACKEND})
endif()
string(JSON COMPAT_CHECK GET ${_COMPATIBILITY_TABLE_JSON} "stacktrace")
string(JSON COMPAT_CHECK GET ${COMPAT_CHECK} ${_OS_NAME})
string(JSON COMPAT_CHECK ERROR_VARIABLE _ERROR_CODE GET ${COMPAT_CHECK} ${STACKTRACE_BACKEND})
if(NOT _ERROR_CODE STREQUAL "NOTFOUND")
message(FATAL_ERROR "Nonexistent stacktrace generation backend '${STACKTRACE_BACKEND}'")
elseif(COMPAT_CHECK EQUAL OFF)
message(FATAL_ERROR "Backend '${STACKTRACE_BACKEND}' is incompatibile OS '${_OS_NAME}'")
endif()
if(IS_STACKTRACE_DEFAULT)
message(WARNING "Backend for stacktrace generation not supplied by user using default backend for '${_OS_NAME}'")
endif()
# check compat for decode
string(JSON COMPAT_CHECK GET ${_COMPATIBILITY_TABLE_JSON} "decode")
string(JSON COMPAT_CHECK GET ${COMPAT_CHECK} ${_OS_NAME})
string(JSON COMPAT_CHECK ERROR_VARIABLE _ERROR_CODE GET ${COMPAT_CHECK} ${DECODE_BACKEND})
if(NOT _ERROR_CODE STREQUAL "NOTFOUND")
message(FATAL_ERROR "Nonexistent stacktrace decode backend '${DECODE_BACKEND}'")
elseif(COMPAT_CHECK EQUAL OFF)
message(FATAL_ERROR "Backend '${DECODE_BACKEND}' is incompatibile OS '${_OS_NAME}'")
endif()
if(IS_DECODE_DEFAULT)
message(WARNING "Backend for stacktrace decode not supplied by user using default backend for '${_OS_NAME}'")
endif()
string(JSON COMPAT_CHECK GET ${_COMPATIBILITY_TABLE_JSON} "libs")
string(JSON COMPAT_CHECK ERROR_VARIABLE _ERROR_CODE GET ${COMPAT_CHECK} ${STACKTRACE_BACKEND})
if(_ERROR_CODE STREQUAL "NOTFOUND")
set(BACKEND_LINK_LIBS "${BACKEND_LINK_LIBS} ${COMPAT_CHECK}")
endif()
string(JSON COMPAT_CHECK GET ${_COMPATIBILITY_TABLE_JSON} "libs")
string(JSON COMPAT_CHECK ERROR_VARIABLE _ERROR_CODE GET ${COMPAT_CHECK} ${DECODE_BACKEND})
if(_ERROR_CODE STREQUAL "NOTFOUND")
set(BACKEND_LINK_LIBS "${BACKEND_LINK_LIBS} ${COMPAT_CHECK}")
endif()
separate_arguments(BACKEND_LINK_LIBS)
message("Using backends '${STACKTRACE_BACKEND}' for stack generation and '${DECODE_BACKEND}' for decode")
set(STACKTRACE_BACKEND "\"detail/stack/${STACKTRACE_BACKEND}.h\"")
set(DECODE_BACKEND "\"detail/decode/${DECODE_BACKEND}.h\"")
# check for ABI compat
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
message("CC: clang, using abi::__cxx_demangle!")
set(DEMANGLE_BACKEND "\"detail/demangle/cxxabi.h\"")
elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
message("CC: g++, using abi::__cxx_demangle!")
set(DEMANGLE_BACKEND "\"detail/demangle/cxxabi.h\"")
elseif (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
message("CC: msvc, using noop demangle!")
set(DEMANGLE_BACKEND "\"detail/demangle/noop.h\"")
endif()
configure_file(include/config.h.in config.h)
target_include_directories(stacktrace INTERFACE ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(stacktrace INTERFACE ${BACKEND_LINK_LIBS})
add_executable(stacktrace-test examples/main.cpp)
add_dependencies(stacktrace-test stacktrace)
add_executable(stacktrace-signal examples/signal.cpp)
add_dependencies(stacktrace-signal stacktrace)
target_include_directories(stacktrace-test PRIVATE include)
target_include_directories(stacktrace-signal PRIVATE include)
target_link_libraries(stacktrace-test stacktrace)
target_link_libraries(stacktrace-signal stacktrace)
set_target_properties(stacktrace-test PROPERTIES EXCLUDE_FROM_ALL TRUE)
set_target_properties(stacktrace-signal PROPERTIES EXCLUDE_FROM_ALL TRUE)