-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
192 lines (132 loc) · 4.66 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
cmake_minimum_required(VERSION 3.2.1)
# set(CMAKE_C_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_EXTENSIONS OFF)
# set(CMAKE_C_COMPILER g++-11)
set(CMAKE_CXX_COMPILER g++-11)
# set(CMAKE_VERBOSE_MAKEFILE ON)
# Set the output folder where your program will be created
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/Debug/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/Debug/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/Debug/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/Release/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/Release/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/Release/bin)
# set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_BUILD_TYPE Release)
# Set custom optimization flags
set(CMAKE_CXX_FLAGS_RELEASE "-O3") # Use -O2 optimization for release builds
set(CMAKE_CXX_FLAGS_DEBUG "-g -Og") # Use -Og optimization for debug builds
add_compile_options(-Wall -Wextra)
# set(DEBUG TRUE)
# set(DEBUG FALSE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${DEBUG_OPT} -fopenmp -march=native")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${DEBUG_OPT} -fopenmp -march=native")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(INSTALL_GTEST OFF)
project(VertexSurge VERSION 1.0)
install(
FILES "${CMAKE_BINARY_DIR}/compile_commands.json"
DESTINATION "${CMAKE_SOURCE_DIR}"
)
# if (DEBUG)
# message(STATUS "Debug mode")
# set(DEBUG_OPT "-g")
# else()
# message(STATUS "Release mode")
# set (DEBUG_OPT "-O3")
# endif()
set(SRC_INCLUDE ${PROJECT_SOURCE_DIR}/src/include)
set(COMMON_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/objects/vql ${SRC_INCLUDE} ${SRC_INCLUDE}/common ${SRC_INCLUDE}/utils)
# header only json
include_directories(third_party)
include_directories(/usr/local/include/antlr4-runtime)
include_directories(${COMMON_INCLUDE_DIRS})
include(FetchContent)
find_package(TBB REQUIRED)
# fmtlib
find_package(fmt 9.1.0 QUIET)
if(NOT fmt_FOUND)
message(STATUS "fmt not found, using FetchContent")
FetchContent_Declare(
fmtlib
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG 9.1.0 # specify the exact version
)
FetchContent_MakeAvailable(fmtlib)
include_directories(${fmt_SOURCE_DIR}/include)
endif()
# spdlog
find_package(spdlog 1.11.0 QUIET)
if(NOT spdlog_FOUND)
message(STATUS "spdlog not found, using FetchContent")
FetchContent_Declare(
spdlog
GIT_REPOSITORY https://github.com/gabime/spdlog.git
GIT_TAG v1.11.0 # specify the version you want
)
FetchContent_MakeAvailable(spdlog)
include_directories(${spdlog_SOURCE_DIR}/include)
endif()
find_package(xxHash QUIET)
if(NOT xxHash_FOUNG)
message(STATUS "xxHash not found, using FetchContent")
FetchContent_Declare(
xxHash
GIT_REPOSITORY https://github.com/Cyan4973/xxHash.git
GIT_TAG v0.8.0
)
FetchContent_MakeAvailable(xxHash)
include_directories(${xxHash_SOURCE_DIR})
# message(STATUS "xxHash_SOURCE_DIR: ${xxHash_SOURCE_DIR}")
endif()
include(FetchContent)
FetchContent_Declare(
googletest
URL https://codeload.github.com/google/googletest/zip/refs/tags/v1.14.0
)
FetchContent_MakeAvailable(googletest)
include_directories(${googletest_SOURCE_DIR}/include)
enable_testing()
include(GoogleTest)
add_subdirectory(src/objects)
add_subdirectory(src/test)
set(INSTALL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/bin)
message(STATUS "INSTALL_DIR: ${INSTALL_DIR}")
# Collect all currently added targets in all subdirectories
#
# Parameters:
# - _result the list containing all found targets
# - _dir root directory to start looking from
function(get_all_targets _result _dir)
get_property(_subdirs DIRECTORY "${_dir}" PROPERTY SUBDIRECTORIES)
foreach(_subdir IN LISTS _subdirs)
get_all_targets(${_result} "${_subdir}")
endforeach()
get_directory_property(_sub_targets DIRECTORY "${_dir}" BUILDSYSTEM_TARGETS)
set(${_result} ${${_result}} ${_sub_targets} PARENT_SCOPE)
endfunction()
get_all_targets(ALL_TARGETS ${CMAKE_CURRENT_LIST_DIR})
set(SPECIFIC_TARGETS_TO_REMOVE
"base"
"gtest"
"gtest_main"
"gmock"
"gmock_main"
"vql"
)
list(REMOVE_ITEM ALL_TARGETS ${SPECIFIC_TARGETS_TO_REMOVE})
message(STATUS "ALL_TARGETS: ${ALL_TARGETS}")
# Install all executable targets
install(TARGETS ${ALL_TARGETS}
RUNTIME DESTINATION ${INSTALL_DIR})
file(GLOB_RECURSE SOURCE_FILES
${CMAKE_SOURCE_DIR}/src/*.cpp
${CMAKE_SOURCE_DIR}/src/*.hh
${CMAKE_SOURCE_DIR}/src/*.h)
add_custom_target(
format
COMMAND clang-format -i -style=file ${SOURCE_FILES}
COMMENT "Running clang-format on source files"
)