forked from cjappl/rtlog-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
124 lines (105 loc) · 3.17 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
cmake_minimum_required(VERSION 3.0)
project(rtlog VERSION 1.0.0)
# Set C++ standard
set(CMAKE_CXX_STANDARD 17) # TODO: we only use 17 for CTAD type things, can we get away with 11 ?
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Add library header files
set(HEADERS
include/rtlog/Logger.h
include/rtlog/LogProcessingThread.h
)
# Create library target
add_library(rtlog INTERFACE ${HEADERS})
add_library(rtlog::rtlog ALIAS rtlog)
# Set include directories for library
target_include_directories(rtlog INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
# Find Boost lockfree
find_package(Boost REQUIRED)
target_include_directories(${PROJECT_NAME} INTERFACE ${Boost_INCLUDE_DIRS})
#target_link_libraries(${PROJECT_NAME} INTERFACE Boost::boost)
# Try to find the package ReaderWriterQueue, if not found fetch with FetchContent
find_package(ReaderWriterQueue QUIET)
if(NOT TARGET readerwriterqueue)
include(FetchContent)
FetchContent_Declare(ReaderWriterQueue
GIT_REPOSITORY https://github.com/cameron314/readerwriterqueue
)
FetchContent_MakeAvailable(ReaderWriterQueue)
endif()
if(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()
# TODO: document RTLOG_USE_FMTLIB
if (RTLOG_USE_FMTLIB AND NOT TARGET fmt::fmt)
include(FetchContent)
FetchContent_Declare(fmtlib
GIT_REPOSITORY https://github.com/fmtlib/fmt
)
FetchContent_MakeAvailable(fmtlib)
endif()
target_link_libraries(rtlog
INTERFACE
readerwriterqueue
stb::stb
$<$<BOOL:${RTLOG_USE_FMTLIB}>:fmt::fmt>
)
target_compile_definitions(rtlog
INTERFACE
STB_SPRINTF_IMPLEMENTATION
$<$<BOOL:${RTLOG_USE_FMTLIB}>:RTLOG_USE_FMTLIB>
$<$<CONFIG:Debug>:DEBUG>
$<$<CONFIG:Release>:NDEBUG>
)
target_compile_options(rtlog
INTERFACE
$<$<BOOL:${RTLOG_FULL_WARNINGS}>:-Wall -Werror -Wformat -Wextra -Wformat-security>
)
option(RTLOG_BUILD_TESTS "Build tests" ON)
if(RTLOG_BUILD_TESTS)
include(CTest)
set_property(GLOBAL PROPERTY CTEST_TARGETS_ADDED 1)
enable_testing()
add_subdirectory(test)
endif()
option(RTLOG_BUILD_EXAMPLES "Build examples" ON)
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
#)