-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCMakeLists.txt
233 lines (205 loc) · 6.92 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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
cmake_minimum_required(VERSION 3.5.1)
project(log_surgeon
VERSION 0.0.1
DESCRIPTION "log-surgeon: A performant log parsing library"
HOMEPAGE_URL https://github.com/y-scope/log-surgeon
LANGUAGES CXX
)
if (POLICY CMP0077)
cmake_policy(SET CMP0077 NEW)
endif()
if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
find_package(Catch2 3 REQUIRED)
include(Catch)
include(CTest)
endif()
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
include(FetchContent)
find_package(Microsoft.GSL QUIET CONFIG)
if (NOT Microsoft.GSL_FOUND)
FetchContent_Declare(GSL
GIT_REPOSITORY "https://github.com/microsoft/GSL"
GIT_TAG "v4.0.0"
GIT_SHALLOW ON
)
endif()
# Use <fmt/*.h> as <format> is unsupported in gcc-10.
find_package(fmt 8.0.1 QUIET)
if (NOT fmt_FOUND)
FetchContent_Declare(fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt
GIT_TAG "8.0.1"
GIT_SHALLOW ON
)
endif()
# Declare the details of all fetched content before making them available.
if (NOT Microsoft.GSL_FOUND)
FetchContent_MakeAvailable(GSL)
endif()
if (NOT fmt_FOUND)
# Force fmt to generate install rules
set(FMT_INSTALL ON CACHE BOOL "Enable installation for fmt." FORCE)
FetchContent_MakeAvailable(fmt)
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(default_build_type "Release")
message(STATUS "No build type specified. Setting to '${default_build_type}'.")
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING "Choose the type of build." FORCE)
endif()
option(BUILD_SHARED_LIBS "Build using shared libraries" OFF)
set(SOURCE_FILES
src/log_surgeon/Buffer.hpp
src/log_surgeon/BufferParser.cpp
src/log_surgeon/BufferParser.hpp
src/log_surgeon/Constants.hpp
src/log_surgeon/FileReader.cpp
src/log_surgeon/FileReader.hpp
src/log_surgeon/Lalr1Parser.cpp
src/log_surgeon/Lalr1Parser.hpp
src/log_surgeon/Lalr1Parser.tpp
src/log_surgeon/Lexer.hpp
src/log_surgeon/Lexer.tpp
src/log_surgeon/LexicalRule.hpp
src/log_surgeon/LogEvent.cpp
src/log_surgeon/LogEvent.hpp
src/log_surgeon/LogParser.cpp
src/log_surgeon/LogParser.hpp
src/log_surgeon/LogParserOutputBuffer.cpp
src/log_surgeon/LogParserOutputBuffer.hpp
src/log_surgeon/Parser.tpp
src/log_surgeon/Parser.hpp
src/log_surgeon/ParserInputBuffer.cpp
src/log_surgeon/ParserInputBuffer.hpp
src/log_surgeon/Reader.hpp
src/log_surgeon/ReaderParser.cpp
src/log_surgeon/ReaderParser.hpp
src/log_surgeon/Schema.cpp
src/log_surgeon/Schema.hpp
src/log_surgeon/SchemaParser.cpp
src/log_surgeon/SchemaParser.hpp
src/log_surgeon/Token.cpp
src/log_surgeon/Token.hpp
src/log_surgeon/finite_automata/PrefixTree.cpp
src/log_surgeon/finite_automata/PrefixTree.hpp
src/log_surgeon/finite_automata/RegexAST.hpp
src/log_surgeon/finite_automata/Dfa.hpp
src/log_surgeon/finite_automata/DfaState.hpp
src/log_surgeon/finite_automata/DfaStatePair.hpp
src/log_surgeon/finite_automata/Nfa.hpp
src/log_surgeon/finite_automata/NfaState.hpp
src/log_surgeon/finite_automata/RegisterHandler.hpp
src/log_surgeon/finite_automata/StateType.hpp
src/log_surgeon/finite_automata/Tag.hpp
src/log_surgeon/finite_automata/TaggedTransition.hpp
src/log_surgeon/finite_automata/UnicodeIntervalTree.hpp
src/log_surgeon/finite_automata/UnicodeIntervalTree.tpp
)
set(LCHIP_INSTALL_CONFIG_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/log_surgeon)
set(LCHIP_INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR})
# Directory for installing third-party includes that the user doesn't have installed.
set(LCHIP_THIRD_PARTY_INCLUDE_DIR "${LCHIP_INSTALL_INCLUDE_DIR}/log_surgeon/third_party_include")
add_library(log_surgeon ${SOURCE_FILES})
add_library(log_surgeon::log_surgeon ALIAS log_surgeon)
if (Microsoft.GSL_FOUND)
target_link_libraries(log_surgeon
PUBLIC
Microsoft.GSL::GSL
)
else()
# Since the user doesn't have GSL installed, use the GSL headers directly.
# NOTE:
# - We can't link against the `Microsoft.GSL::GSL` target since that would require adding `GSL`
# to the `install` command and force the user to have GSL installed when using log-surgeon.
# - At install time, we'll copy GSL into log-surgeon's third-party includes directory.
target_include_directories(log_surgeon
PUBLIC
$<BUILD_INTERFACE:${GSL_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${LCHIP_THIRD_PARTY_INCLUDE_DIR}>
)
endif()
target_link_libraries(log_surgeon PUBLIC fmt::fmt)
target_include_directories(log_surgeon
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
)
target_compile_features(log_surgeon
PRIVATE cxx_std_20
)
target_compile_options(log_surgeon PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -Wpedantic -Werror>
)
# Macro providing the length of the absolute source directory path so we can
# create a relative (rather than absolute) __FILE__ macro
string(LENGTH "${CMAKE_SOURCE_DIR}/" SOURCE_PATH_SIZE)
target_compile_definitions(log_surgeon
PUBLIC
SOURCE_PATH_SIZE=${SOURCE_PATH_SIZE}
)
# Make off_t 64-bit
target_compile_definitions(log_surgeon
PRIVATE
_FILE_OFFSET_BITS=64
)
install(
TARGETS
log_surgeon
EXPORT
log_surgeon-targets
)
install(
EXPORT
log_surgeon-targets
NAMESPACE
log_surgeon::
DESTINATION
${LCHIP_INSTALL_CONFIG_DIR}
)
install(
DIRECTORY
"${PROJECT_SOURCE_DIR}/src/log_surgeon"
DESTINATION
"${LCHIP_INSTALL_INCLUDE_DIR}"
FILES_MATCHING
PATTERN "*.h"
PATTERN "*.hpp"
PATTERN "*.tpp"
)
if (NOT Microsoft.GSL_FOUND)
install(
DIRECTORY
# NOTE: We don't include a trailing slash so that the gsl directory is copied rather than
# its contents.
"${GSL_SOURCE_DIR}/include/gsl"
DESTINATION
"${LCHIP_THIRD_PARTY_INCLUDE_DIR}"
)
endif ()
configure_package_config_file(
${CMAKE_CURRENT_LIST_DIR}/cmake/log_surgeon-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/log_surgeon-config.cmake
INSTALL_DESTINATION
${LCHIP_INSTALL_CONFIG_DIR}
PATH_VARS
LCHIP_INSTALL_INCLUDE_DIR
)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/log_surgeon-config-version.cmake
COMPATIBILITY
SameMajorVersion
)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/log_surgeon-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/log_surgeon-config-version.cmake
DESTINATION
${LCHIP_INSTALL_CONFIG_DIR}
)
if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
add_subdirectory(tests)
endif()