Repository navigation
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
158 lines (140 loc) · 4.27 KB
/
Copy pathCMakeLists.txt
File metadata and controls
158 lines (140 loc) · 4.27 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
cmake_minimum_required(VERSION 3.20)
# Honor MSVC_RUNTIME_LIBRARY /MT for portable Windows binaries.
if(POLICY CMP0091)
cmake_policy(SET CMP0091 NEW)
endif()
project(WebSearchFree VERSION 0.5.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Must be set before any targets so wsf_core and executables share the same CRT.
if(MSVC)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
option(WSF_BUILD_CLI "Build wsf CLI" ON)
option(WSF_BUILD_SERVER "Build optional HTTP server into CLI" ON)
option(WSF_BUILD_TESTS "Build unit tests" ON)
option(WSF_BUILD_PYTHON "Build Python bindings" OFF)
include(FetchContent)
FetchContent_Declare(
nlohmann_json
GIT_REPOSITORY https://github.com/nlohmann/json.git
GIT_TAG v3.11.3
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(nlohmann_json)
FetchContent_Declare(
httplib
GIT_REPOSITORY https://github.com/yhirose/cpp-httplib.git
GIT_TAG v0.18.3
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(httplib)
add_library(wsf_core
src/http_client.cpp
src/html_utils.cpp
src/extract.cpp
src/extract_cache.cpp
src/rank.cpp
src/search.cpp
src/search_cache.cpp
src/robots.cpp
src/sha256.cpp
src/paths.cpp
src/update.cpp
src/sanitize.cpp
src/goggles.cpp
src/engine_health.cpp
src/engines/ddg.cpp
src/engines/brave.cpp
src/engines/wikipedia.cpp
src/engines/searx.cpp
src/engines/ddg_news.cpp
src/engines/factory.cpp
)
add_library(wsf::core ALIAS wsf_core)
target_include_directories(wsf_core
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
)
target_link_libraries(wsf_core
PUBLIC nlohmann_json::nlohmann_json
)
if(WIN32)
target_link_libraries(wsf_core PRIVATE winhttp)
target_compile_definitions(wsf_core PRIVATE WSF_USE_WINHTTP=1)
else()
find_package(CURL REQUIRED)
target_link_libraries(wsf_core PRIVATE CURL::libcurl)
target_compile_definitions(wsf_core PRIVATE WSF_USE_CURL=1)
endif()
# Ship self-contained MinGW executables (avoid libstdc++-6.dll / libgcc_s_seh-1.dll / libwinpthread-1.dll PATH issues).
function(wsf_static_mingw_runtime target)
if(MINGW)
# Prefer full -static so the g++ driver does not re-add a dynamic -lpthread at the end.
target_link_options(${target} PRIVATE -static)
endif()
endfunction()
function(wsf_static_msvc_runtime target)
if(MSVC)
set_property(TARGET ${target} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
endfunction()
if(MSVC)
target_compile_options(wsf_core PRIVATE /W4 /permissive-)
target_compile_definitions(wsf_core PRIVATE _CRT_SECURE_NO_WARNINGS)
else()
target_compile_options(wsf_core PRIVATE -Wall -Wextra -Wpedantic)
endif()
wsf_static_msvc_runtime(wsf_core)
if(WSF_BUILD_CLI)
add_executable(wsf apps/wsf_cli/main.cpp apps/wsf_cli/mcp.cpp)
target_link_libraries(wsf PRIVATE wsf::core)
target_include_directories(wsf PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
if(WSF_BUILD_SERVER)
target_compile_definitions(wsf PRIVATE WSF_HAS_SERVER=1)
target_include_directories(wsf PRIVATE ${httplib_SOURCE_DIR})
endif()
if(WIN32)
target_link_libraries(wsf PRIVATE ws2_32)
endif()
wsf_static_mingw_runtime(wsf)
wsf_static_msvc_runtime(wsf)
endif()
if(WSF_BUILD_TESTS)
enable_testing()
add_executable(wsf_tests
tests/test_ddg.cpp
tests/test_html_utils.cpp
tests/test_rank.cpp
tests/test_extract.cpp
tests/test_brave.cpp
tests/test_searx.cpp
tests/test_update.cpp
tests/test_v05.cpp
)
target_link_libraries(wsf_tests PRIVATE wsf::core)
target_include_directories(wsf_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
target_compile_definitions(wsf_tests PRIVATE
WSF_FIXTURES_DIR="${CMAKE_CURRENT_SOURCE_DIR}/tests/fixtures"
)
wsf_static_mingw_runtime(wsf_tests)
wsf_static_msvc_runtime(wsf_tests)
add_test(NAME wsf_tests COMMAND wsf_tests)
endif()
if(WSF_BUILD_PYTHON)
add_subdirectory(bindings/python)
endif()
install(TARGETS wsf_core
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
install(DIRECTORY include/wsf DESTINATION include)
if(WSF_BUILD_CLI)
install(TARGETS wsf RUNTIME DESTINATION bin)
endif()