-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCMakeLists.txt
163 lines (136 loc) · 4.37 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
cmake_minimum_required(VERSION 3.6)
project(rtlog VERSION 1.0.0)
option(RTLOG_USE_FMTLIB "Use fmtlib for formatting" OFF)
option(RTLOG_FULL_WARNINGS "Enable full warnings" OFF)
option(RTLOG_BUILD_TESTS "Build tests" OFF)
option(RTLOG_BUILD_EXAMPLES "Build examples" OFF)
set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-fsanitize=realtime" COMPILER_SUPPORTS_RTSAN)
unset(CMAKE_TRY_COMPILE_TARGET_TYPE)
if(COMPILER_SUPPORTS_RTSAN)
message(STATUS "Compiler supports -fsanitize=realtime, allowing RTLOG_USE_RTSAN option.")
option(RTLOG_USE_RTSAN "Use -fsanitize=realtime" OFF)
endif()
# Add library header files
set(HEADERS
include/rtlog/rtlog.h
)
# Create library target
add_library(rtlog INTERFACE)
add_library(rtlog::rtlog ALIAS rtlog)
if (CMAKE_CXX_STANDARD LESS 17)
message(WARNING "C++17 or higher is required for rtlog. Setting C++17 for the target..")
endif()
target_compile_features(rtlog INTERFACE cxx_std_17)
# Set include directories for library
target_include_directories(rtlog INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
# Set project include directories
target_include_directories(${PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
if (NOT TARGET farbot)
include(FetchContent)
FetchContent_Declare(farbot
GIT_REPOSITORY https://github.com/hogliux/farbot
GIT_TAG 0416705394720c12f0d02e55c144e4f69bb06912
)
# Note we do not "MakeAvailable" here, because farbot does not fully work via FetchContent
if(NOT farbot_POPULATED)
FetchContent_Populate(farbot)
endif()
add_library(farbot INTERFACE)
add_library(farbot::farbot ALIAS farbot)
target_include_directories(farbot INTERFACE
$<BUILD_INTERFACE:${farbot_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
endif()
if(NOT RTSAN_USE_FMTLIB AND NOT TARGET stb::stb)
# Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24:
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
endif()
include(FetchContent)
FetchContent_Declare(stb
GIT_REPOSITORY https://github.com/nothings/stb
)
# Note we do not "MakeAvailable" here, because stb is not cmake, just populate
if(NOT stb_POPULATED)
FetchContent_Populate(stb)
endif()
add_library(stb INTERFACE)
add_library(stb::stb ALIAS stb)
target_include_directories(stb INTERFACE
$<BUILD_INTERFACE:${stb_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>
)
endif()
if (RTLOG_USE_FMTLIB AND NOT TARGET fmt::fmt)
include(FetchContent)
FetchContent_Declare(fmtlib
GIT_REPOSITORY https://github.com/fmtlib/fmt
GIT_TAG 11.0.2
)
FetchContent_MakeAvailable(fmtlib)
endif()
target_link_libraries(rtlog
INTERFACE
farbot::farbot
stb::stb
$<$<BOOL:${RTLOG_USE_FMTLIB}>:fmt::fmt>
)
target_compile_definitions(rtlog
INTERFACE
STB_SPRINTF_IMPLEMENTATION
$<$<BOOL:${RTLOG_USE_FMTLIB}>:RTLOG_USE_FMTLIB>
$<$<NOT:$<BOOL:${RTLOG_USE_FMTLIB}>>:RTLOG_USE_STB>
$<$<CONFIG:Debug>:DEBUG>
$<$<CONFIG:Release>:NDEBUG>
)
set(RTLOG_ALL_WARNINGS)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(RTLOG_ALL_WARNINGS "-Wall;-Werror;-Wformat;-Wextra;-Wformat-security;-Wno-unused-function")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(RTLOG_ALL_WARNINGS "/W4;/WX;/wd4505")
endif()
target_compile_options(rtlog
INTERFACE
$<$<BOOL:${RTLOG_FULL_WARNINGS}>:${RTLOG_ALL_WARNINGS}>
$<$<BOOL:${RTLOG_USE_RTSAN}>:-fsanitize=realtime>
)
target_link_options(rtlog
INTERFACE
$<$<BOOL:${RTLOG_USE_RTSAN}>:-fsanitize=realtime>
)
if(RTLOG_BUILD_TESTS)
include(CTest)
set_property(GLOBAL PROPERTY CTEST_TARGETS_ADDED 1)
enable_testing()
add_subdirectory(test)
endif()
if(RTLOG_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
# TODO: figure out installing
# Install library
#install(TARGETS rtlog
# EXPORT rtlogTargets
# INCLUDES DESTINATION include
#)
#
## Install library header files
#install(DIRECTORY include/rtlog
# DESTINATION include
#)
#
## Install CMake config files
#install(EXPORT rtlogTargets
# FILE rtlogConfig.cmake
# NAMESPACE rtlog::
# DESTINATION lib/cmake/rtlog
#)