-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
245 lines (210 loc) · 7.62 KB
/
CMakeLists.txt
File metadata and controls
245 lines (210 loc) · 7.62 KB
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
234
235
236
237
238
239
240
241
242
243
244
245
cmake_minimum_required(VERSION 3.10)
project(search_engine)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Disable uWebSockets header
add_definitions(-DUWS_HTTPRESPONSE_NO_WRITEMARK)
# Add MongoDB specific paths
include_directories(/usr/local/include/mongocxx/v_noabi /usr/local/include/bsoncxx/v_noabi)
# Use newer MongoDB libraries
set(CMAKE_PREFIX_PATH "/usr/local/lib/cmake/mongocxx-4.1.2;/usr/local/lib/cmake/bsoncxx-4.1.2;/usr/local/lib/cmake/bson-2.1.1;/usr/local/lib/cmake/mongoc-2.1.1")
# Find required packages
find_package(mongocxx REQUIRED CONFIG)
find_package(bsoncxx REQUIRED CONFIG)
find_package(OpenSSL REQUIRED)
find_package(CURL REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(GUMBO REQUIRED gumbo)
find_package(Threads REQUIRED)
# Find WebSocket++ and nlohmann/json
find_path(WEBSOCKETPP_INCLUDE_DIR NAMES websocketpp/endpoint.hpp PATHS /usr/include /usr/local/include)
find_path(NLOHMANN_JSON_INCLUDE_DIR NAMES nlohmann/json.hpp PATHS /usr/include /usr/local/include)
# Add Inja template engine (header-only)
find_path(INJA_INCLUDE_DIR NAMES inja/inja.hpp PATHS ${CMAKE_SOURCE_DIR}/include /usr/include /usr/local/include)
if(INJA_INCLUDE_DIR)
set(INJA_AVAILABLE TRUE)
message(STATUS "Inja found at: ${INJA_INCLUDE_DIR}")
else()
message(FATAL_ERROR "Inja header file not found. Please run: mkdir -p include/inja && curl -L https://github.com/pantor/inja/releases/download/v3.4.0/inja.hpp -o include/inja/inja.hpp")
endif()
# Remove WebSocket++ and nlohmann/json checks for browserless
# Always build BrowserlessClient if referenced
# Redis and redis-plus-plus detection
find_path(HIREDIS_INCLUDE_DIR NAMES hiredis/hiredis.h PATHS /usr/include /usr/local/include)
find_library(HIREDIS_LIBRARY NAMES hiredis PATHS /usr/lib /usr/local/lib)
find_path(REDIS_PLUS_PLUS_INCLUDE_DIR NAMES sw/redis++/redis++.h PATHS /usr/include /usr/local/include)
find_library(REDIS_PLUS_PLUS_LIBRARY NAMES redis++ PATHS /usr/lib /usr/local/lib)
if(HIREDIS_INCLUDE_DIR AND HIREDIS_LIBRARY AND REDIS_PLUS_PLUS_INCLUDE_DIR AND REDIS_PLUS_PLUS_LIBRARY)
set(REDIS_AVAILABLE TRUE)
set(REDIS_LIBRARIES ${HIREDIS_LIBRARY} ${REDIS_PLUS_PLUS_LIBRARY})
set(REDIS_INCLUDE_DIRS ${HIREDIS_INCLUDE_DIR} ${REDIS_PLUS_PLUS_INCLUDE_DIR})
message(STATUS "Redis and redis-plus-plus found - RedisSearchStorage will be available")
message(STATUS " hiredis: ${HIREDIS_LIBRARY}")
message(STATUS " redis++: ${REDIS_PLUS_PLUS_LIBRARY}")
else()
set(REDIS_AVAILABLE FALSE)
message(STATUS "Redis dependencies not found - RedisSearchStorage will be excluded")
if(NOT HIREDIS_INCLUDE_DIR OR NOT HIREDIS_LIBRARY)
message(STATUS " Missing hiredis")
endif()
if(NOT REDIS_PLUS_PLUS_INCLUDE_DIR OR NOT REDIS_PLUS_PLUS_LIBRARY)
message(STATUS " Missing redis-plus-plus")
endif()
endif()
# Add include directories
include_directories(
${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/public
/usr/local/include/uwebsockets
/usr/local/include/usockets
${GUMBO_INCLUDE_DIRS}
)
# Add WebSocket include directories if available
# Always include BrowserlessClient if referenced
include_directories(${WEBSOCKETPP_INCLUDE_DIR} ${NLOHMANN_JSON_INCLUDE_DIR})
# Add Inja include directories if available
if(INJA_AVAILABLE AND INJA_INCLUDE_DIR)
include_directories(${INJA_INCLUDE_DIR})
endif()
# Add Redis include directories if available
if(REDIS_AVAILABLE)
include_directories(${REDIS_INCLUDE_DIRS})
endif()
# Create a common library for shared code
add_library(common STATIC
src/common/Logger.cpp
src/common/JsMinifierClient.cpp
src/common/UrlSanitizer.cpp
src/common/UrlCanonicalizer.cpp
src/common/SlugGenerator.cpp
src/common/SlugCache.cpp
)
target_include_directories(common
PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(common
PUBLIC
${CURL_LIBRARIES}
CURL::libcurl
)
# Install common library
install(TARGETS common
EXPORT CommonTargets
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
# Add subdirectories for libraries
add_subdirectory(src/crawler)
add_subdirectory(src/storage)
add_subdirectory(src/scoring)
add_subdirectory(src/search_core)
# Add source files recursively to include subdirectories like src/common/
# file(GLOB_RECURSE SOURCES "src/*.cpp")
# # Remove test sources from SOURCES if they were picked up by GLOB_RECURSE
# list(FILTER SOURCES EXCLUDE REGEX ".*test.*\\.cpp$")
# file(GLOB_RECURSE HEADERS "include/*.h" "include/*.hpp")
file(GLOB_RECURSE MAIN_SOURCES "src/*.cpp" "src/main.cpp")
# Remove crawler sources, storage sources, test sources, and common sources from MAIN_SOURCES
list(FILTER MAIN_SOURCES EXCLUDE REGEX ".*crawler/.*\\.cpp$")
list(FILTER MAIN_SOURCES EXCLUDE REGEX ".*storage/.*\\.cpp$")
list(FILTER MAIN_SOURCES EXCLUDE REGEX ".*test.*\\.cpp$")
list(FILTER MAIN_SOURCES EXCLUDE REGEX ".*common/.*\\.cpp$")
list(FILTER MAIN_SOURCES EXCLUDE REGEX ".*scoring/.*\\.cpp$")
list(FILTER MAIN_SOURCES EXCLUDE REGEX ".*search_core/.*\\.cpp$")
list(FILTER MAIN_SOURCES EXCLUDE REGEX ".*kafka/.*\\.cpp$")
file(GLOB_RECURSE HEADERS "include/*.h" "include/*.hpp")
# Create MongoDB instance library for shared use
add_library(mongodb_instance STATIC src/mongodb.cpp)
target_include_directories(mongodb_instance
PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(mongodb_instance
PUBLIC
mongo::bsoncxx_shared
mongo::mongocxx_shared
)
target_compile_definitions(mongodb_instance PRIVATE
BSONCXX_STATIC
MONGOCXX_STATIC
)
# Filter out mongodb.cpp from MAIN_SOURCES since it's now in a separate library
list(FILTER MAIN_SOURCES EXCLUDE REGEX ".*mongodb\\.cpp$")
# Create SEO library
add_library(seo STATIC
src/seo/SEOGenerator.cpp
src/seo/SitemapGenerator.cpp
src/seo/SchemaValidator.cpp
)
target_include_directories(seo
PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(seo
PUBLIC
common
mongo::bsoncxx_shared
mongo::mongocxx_shared
)
# Filter out SEO sources from MAIN_SOURCES
list(FILTER MAIN_SOURCES EXCLUDE REGEX ".*seo/.*\\.cpp$")
# Create executable
add_executable(server ${MAIN_SOURCES} ${HEADERS})
# Link libraries
target_link_libraries(server
PRIVATE
common
storage
SponsorStorage
ProfileStorage
crawler
search_core
scoring
seo
mongodb_instance
/usr/local/lib/libmongocxx.so
/usr/local/lib/libbsoncxx.so
OpenSSL::SSL
OpenSSL::Crypto
pthread
z
${CURL_LIBRARIES}
CURL::libcurl
${GUMBO_LIBRARIES}
Threads::Threads
)
# Link Inja if available (header-only library, no linking required)
# Link Redis libraries if available
if(REDIS_AVAILABLE)
target_link_libraries(server PRIVATE ${REDIS_LIBRARIES})
target_compile_definitions(server PRIVATE REDIS_AVAILABLE)
endif()
# Link uSockets library
target_link_libraries(server
PRIVATE
/usr/local/lib/libuSockets.a
)
# Install mongodb_instance target
install(TARGETS mongodb_instance
EXPORT MongoDBInstanceTargets
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
# Export mongodb_instance configuration
install(EXPORT MongoDBInstanceTargets
FILE MongoDBInstanceTargets.cmake
NAMESPACE SearchEngine::
DESTINATION lib/cmake/SearchEngine
)
# Enable testing and add tests
option(BUILD_TESTS "Build tests" OFF)
if(BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()