-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
CMakeLists.txt
136 lines (110 loc) · 3.7 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# MIT License
#
# Copyright (c) 2020-2022 Basit Ayantunde
#
cmake_minimum_required(VERSION 3.13)
project(
Stx
VERSION 1.0.0
DESCRIPTION "A set of utility extensions to the C++ Standard Library"
HOMEPAGE_URL "https://github.com/lamarrr/STX"
LANGUAGES CXX)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(CheckCXXSourceCompiles)
include(add_project_library)
# ===============================================
#
# === Configuration Options
#
# ===============================================
option(STX_BUILD_TESTS "Build tests" OFF)
option(STX_BUILD_DOCS "Build documentation" OFF)
option(
STX_CUSTOM_PANIC_HANDLER
"Override the default panic behaviour by implementing a custom panic handler. The default behavior is to print the panic report and abort the program. (You can read the docs for more details)"
OFF)
option(STX_ENABLE_BACKTRACE "Enable stack backtraces" OFF)
# ===============================================
#
# === Configuration Options Logging
#
# ===============================================
message(STATUS "[STX] Build tests: " ${STX_BUILD_TESTS})
message(STATUS "[STX] Build documentation: " ${STX_BUILD_DOCS}) # not working
# yet
message(STATUS "[STX] Override panic handler: " ${STX_CUSTOM_PANIC_HANDLER})
# ===============================================
#
# === Dependencies
#
# ===============================================
find_package(Threads REQUIRED)
if(${STX_BUILD_TESTS})
find_package(GTest CONFIG REQUIRED)
endif()
if(${STX_ENABLE_BACKTRACE})
find_package(absl CONFIG REQUIRED)
endif()
# ===============================================
#
# === Configuration Definitions and Platform Support
#
# ===============================================
# some microcontroller platforms 'arm-gcc-none especially" may not have
# std::thread enabled if so, we remove the thread facilities, this will cause
# compilation errors otherwise, since the classes won't be available
find_library(ATOMIC_LIBRARY NAMES atomic atomic.so.1 libatomic.so.1 libatomic.so
libatomic.dylib libatomic.1.dylib libatomic.a)
check_cxx_source_compiles(
"
#include <thread>
int main(){
std::this_thread::get_id();
}
"
LIBSTX_HAS_STD_THREAD)
if(NOT LIBSTX_HAS_STD_THREAD)
list(APPEND STX_COMPILER_DEFS "STX_NO_STD_THREAD")
endif()
file(GLOB STX_SOURCE_FILES_LIST src/*.cc)
add_library(stx STATIC ${STX_SOURCE_FILES_LIST})
target_link_libraries(stx Threads::Threads)
if(${ATOMIC_LIBRARY})
target_link_libraries(stx ${ATOMIC_LIBRARY})
endif()
add_library(stx::stx ALIAS stx)
if(MSVC)
target_compile_options(stx PUBLIC "/permissive-")
endif()
if(${STX_ENABLE_BACKTRACE})
target_link_libraries(stx absl::stacktrace absl::symbolize)
target_compile_definitions(stx PRIVATE "STX_ENABLE_BACKTRACE")
endif()
set_target_properties(stx PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON)
target_include_directories(stx PUBLIC include)
target_include_directories(stx PRIVATE src)
# ===============================================
#
# === Install
#
# ===============================================
install(
TARGETS stx
EXPORT stx
LIBRARY DESTINATION lib)
install(DIRECTORY include/stx DESTINATION include)
# ===============================================
#
# === Tests
#
# ===============================================
file(GLOB STX_TESTS_SOURCE_FILES_LIST tests/*.cc)
if(${STX_BUILD_TESTS})
if(STX_TESTS_SOURCE_FILES_LIST)
add_executable(stx_tests ${STX_TESTS_SOURCE_FILES_LIST})
target_include_directories(stx_tests PRIVATE tests)
target_link_libraries(stx_tests GTest::gtest GTest::gtest_main stx::stx)
endif()
endif()