forked from miker2/flexi_config_reader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
200 lines (175 loc) · 6.1 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
cmake_minimum_required(VERSION 3.28)
set(CFG_IS_MAIN_PROJECT OFF)
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(CFG_IS_MAIN_PROJECT ON)
endif()
project (flexi_cfg LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_EXTENSIONS OFF)
include(${CMAKE_SOURCE_DIR}/cmake/colours.cmake)
include(${CMAKE_SOURCE_DIR}/cmake/add_clang_format.cmake)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
include(FetchContent)
include(FindPackageHandleStandardArgs)
# Get taocpp::pegtl
FetchContent_Declare(
taocpp_pegtl
GIT_REPOSITORY https://github.com/taocpp/PEGTL.git
GIT_TAG 3.2.7
SYSTEM
EXCLUDE_FROM_ALL
)
FetchContent_MakeAvailable(taocpp_pegtl)
# magic_enum tag v0.8.1
option(CFG_MAGIC_ENUM_DIR "Specify the location of magic_enum headers" "")
find_path(MAGIC_ENUM_INCLUDE_DIR magic_enum.hpp HINTS ${CFG_MAGIC_ENUM_DIR})
find_package_handle_standard_args(magic_enum DEFAULT_MSG MAGIC_ENUM_INCLUDE_DIR)
if(magic_enum_FOUND)
message(STATUS "Found magic_enum.hpp at ${MAGIC_ENUM_INCLUDE_DIR}")
set(magic_enum_INCLUDE_DIR ${MAGIC_ENUM_INCLUDE_DIR})
MARK_AS_ADVANCED(MAGIC_ENUM_INCLUDE_DIR)
else(magic_enum_FOUND)
FetchContent_Declare(
magic_enum
GIT_REPOSITORY https://github.com/Neargye/magic_enum.git
GIT_TAG v0.9.3
SYSTEM
EXCLUDE_FROM_ALL
)
FetchContent_MakeAvailable(magic_enum)
set(magic_enum_INCLUDE_DIR "${magic_enum_SOURCE_DIR}/include")
endif(magic_enum_FOUND)
# FMT tag 10.1.1
set(FMT_VERSION_REQUIRED 10.1.1)
FetchContent_Declare(
fmt
GIT_REPOSITORY "https://github.com/fmtlib/fmt.git"
GIT_TAG ${FMT_VERSION_REQUIRED}
CMAKE_ARGS -DFMT_DOC=OFF -DFMT_TEST=OFF -DFMT_INSTALL=ON -DFMT_LIB_DIR=lib
SYSTEM
EXCLUDE_FROM_ALL
)
FetchContent_MakeAvailable(fmt)
set_target_properties(fmt PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
# range-v3
FetchContent_Declare(
range-v3
GIT_REPOSITORY "https://github.com/ericniebler/range-v3.git"
GIT_TAG 0.12.0
SYSTEM
EXCLUDE_FROM_ALL
)
FetchContent_MakeAvailable(range-v3)
option(ENABLE_CLANG_TIDY "Enable static analysis with clang-tidy" ON)
option(CFG_CLANG_TIDY_WARN_AS_ERROR "Enable warnings as errors for clang-tidy > 13" ON)
if(ENABLE_CLANG_TIDY)
if(NOT CMAKE_CROSSCOMPILING) # adds invalid paths
find_package(ClangTools QUIET)
if(CLANG_TIDY_FOUND)
if (COMPILER_VERSION_MAJOR GREATER 13 AND CFG_CLANG_TIDY_WARN_AS_ERROR)
message(STATUS "Clang-Tidy > 13 - warning as errors")
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_BIN}" --warnings-as-errors=*)
else()
message(STATUS "Clang-Tidy - warnings as warnings")
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_BIN}" --warnings-as-errors=)
endif()
else(CLANG_TIDY_FOUND)
message(STATUS "${Yellow}clang-tidy static analysis won't be done.${ColourReset}")
endif(CLANG_TIDY_FOUND)
if(NOT CLANG_FORMAT_FOUND)
message(STATUS "${Yellow}clang-format not found. Style checks won't be done.${ColourReset}")
endif(NOT CLANG_FORMAT_FOUND)
endif(NOT CMAKE_CROSSCOMPILING)
else(ENABLE_CLANG_TIDY)
set(CMAKE_CXX_CLANG_TIDY "")
endif(ENABLE_CLANG_TIDY)
option(CFG_ENABLE_DEBUG "Enable DEBUG logging." OFF)
option(CFG_ENABLE_PARSER_TRACE "Enable parser trace logging." OFF)
option(CFG_ENABLE_TEST "Enable unit tests." ON)
option(CFG_EXAMPLES "Build example applications." OFF)
option(CFG_PYTHON_BINDINGS "Build python bindings." OFF)
option(CFG_PYTHON_INSTALL_DIR "Installation directory of python bindings." "")
add_compile_definitions(-DEXAMPLE_DIR="${CMAKE_SOURCE_DIR}/examples")
if(CFG_ENABLE_DEBUG)
add_compile_definitions(VERBOSE_DEBUG_ACTIONS=1)
message(STATUS "Enabling VERBOSE_DEBUG_ACTIONS")
endif(CFG_ENABLE_DEBUG)
if(CFG_ENABLE_PARSER_TRACE)
add_compile_definitions(ENABLE_PARSER_TRACE=1)
message(STATUS "Enabling ENABLE_PARSER_TRACE")
endif(CFG_ENABLE_PARSER_TRACE)
set(PUBLIC_CFG_HEADERS include/flexi_cfg/reader.h include/flexi_cfg/parser.h)
set(CFG_HEADERS
${PUBLIC_CFG_HEADERS}
include/flexi_cfg/config/actions.h
include/flexi_cfg/config/classes.h
include/flexi_cfg/config/exceptions.h
include/flexi_cfg/config/grammar.h
include/flexi_cfg/config/helpers.h
include/flexi_cfg/config/parser-internal.h
include/flexi_cfg/config/selector.h
include/flexi_cfg/config/trace-internal.h
include/flexi_cfg/logger.h
include/flexi_cfg/math/actions.h
include/flexi_cfg/math/grammar.h
include/flexi_cfg/math/helpers.h
include/flexi_cfg/utils.h)
add_library(flexi_cfg
src/config_helpers.cpp
src/config_parser.cpp
src/config_reader.cpp
src/math_helpers.cpp
)
add_library(flexi_cfg::flexi_cfg ALIAS flexi_cfg)
target_include_directories(flexi_cfg PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include>
${magic_enum_INCLUDE_DIR})
target_compile_features(flexi_cfg INTERFACE cxx_std_20)
set_target_properties(flexi_cfg PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
target_link_libraries(flexi_cfg
taocpp::pegtl
fmt::fmt
range-v3::range-v3
)
add_clang_format(flexi_cfg)
install(TARGETS flexi_cfg
LIBRARY DESTINATION lib)
install(DIRECTORY "${CMAKE_SOURCE_DIR}/include/"
DESTINATION include
FILES_MATCHING
PATTERN "*.h")
add_subdirectory(src)
if (CFG_PYTHON_BINDINGS)
# Get pybind11
FetchContent_Declare(
pybind11
GIT_REPOSITORY https://github.com/pybind/pybind11.git
GIT_TAG v2.12.0
SYSTEM
EXCLUDE_FROM_ALL
)
FetchContent_MakeAvailable(pybind11)
message(STATUS "Building python bindings")
add_subdirectory(python)
endif()
if (CFG_ENABLE_TEST)
# Get gtest
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.14.0
SYSTEM
EXCLUDE_FROM_ALL
)
FetchContent_MakeAvailable(googletest)
# Silence clang-tidy warnings from googletest
message( STATUS "Silencing CLANG_TIDY for gtest and gmock")
# This doesn't seem to work for clang-13 :(
set_target_properties(gtest PROPERTIES CXX_CLANG_TIDY "")
set_target_properties(gtest_main PROPERTIES CXX_CLANG_TIDY "")
set_target_properties(gmock PROPERTIES CXX_CLANG_TIDY "")
set_target_properties(gmock_main PROPERTIES CXX_CLANG_TIDY "")
enable_testing()
add_subdirectory(tests)
endif()