Skip to content

Commit 4e8201b

Browse files
committed
build(websocket): remove Boost dependency and clean includes
1 parent 9ced801 commit 4e8201b

File tree

1 file changed

+55
-80
lines changed

1 file changed

+55
-80
lines changed

CMakeLists.txt

Lines changed: 55 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,26 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
4444
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
4545

4646
# Sources discovery
47-
file(GLOB_RECURSE WEBSOCKET_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")
47+
file(GLOB_RECURSE WEBSOCKET_SOURCES CONFIGURE_DEPENDS
48+
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp"
49+
)
4850

4951
# Core dependency
5052
option(VIX_WEBSOCKET_FETCH_CORE "Auto-fetch vix::core if missing" ON)
5153
option(VIX_WEBSOCKET_FETCH_UTILS "Auto-fetch vix::utils if missing" ON)
5254

53-
if (NOT TARGET vix::core)
55+
if (NOT TARGET vix::core AND NOT TARGET vix_core)
5456
if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/../core/CMakeLists.txt")
5557
message(STATUS "[websocket] Adding core from umbrella: ../core")
56-
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/../core" "core")
58+
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/../core" "${CMAKE_CURRENT_BINARY_DIR}/core")
5759
elseif (VIX_WEBSOCKET_FETCH_CORE)
5860
include(FetchContent)
5961
message(STATUS "[websocket] Fetching vix::core via FetchContent")
60-
FetchContent_Declare(vix_core
62+
FetchContent_Declare(vix_core_ext
6163
GIT_REPOSITORY https://github.com/vixcpp/core.git
6264
GIT_TAG dev
6365
)
64-
FetchContent_MakeAvailable(vix_core)
66+
FetchContent_MakeAvailable(vix_core_ext)
6567
else()
6668
message(FATAL_ERROR
6769
"vix::core not found. Provide vix::core before websocket "
@@ -70,27 +72,40 @@ if (NOT TARGET vix::core)
7072
endif()
7173

7274
# Utils dependency
73-
if (NOT TARGET vix::utils)
75+
if (NOT TARGET vix::utils AND NOT TARGET vix_utils)
7476
if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/../utils/CMakeLists.txt")
7577
message(STATUS "[websocket] Adding utils from umbrella: ../utils")
76-
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/../utils" "utils")
78+
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/../utils" "${CMAKE_CURRENT_BINARY_DIR}/utils")
7779
elseif (VIX_WEBSOCKET_FETCH_UTILS)
7880
include(FetchContent)
7981
message(STATUS "[websocket] Fetching vix::utils via FetchContent")
80-
FetchContent_Declare(vix_utils
82+
FetchContent_Declare(vix_utils_ext
8183
GIT_REPOSITORY https://github.com/vixcpp/utils.git
8284
GIT_TAG dev
8385
)
84-
FetchContent_MakeAvailable(vix_utils)
86+
FetchContent_MakeAvailable(vix_utils_ext)
8587
else()
8688
message(FATAL_ERROR
8789
"vix::utils not found. Provide vix::utils before websocket "
8890
"or enable VIX_WEBSOCKET_FETCH_UTILS=ON.")
8991
endif()
9092
endif()
9193

92-
set(VIX_CORE_TARGET vix::core)
93-
set(VIX_UTILS_TARGET vix::utils)
94+
if (TARGET vix::core)
95+
set(VIX_CORE_TARGET vix::core)
96+
elseif (TARGET vix_core)
97+
set(VIX_CORE_TARGET vix_core)
98+
else()
99+
message(FATAL_ERROR "[websocket] Core dependency resolution finished but no usable core target was found.")
100+
endif()
101+
102+
if (TARGET vix::utils)
103+
set(VIX_UTILS_TARGET vix::utils)
104+
elseif (TARGET vix_utils)
105+
set(VIX_UTILS_TARGET vix_utils)
106+
else()
107+
message(FATAL_ERROR "[websocket] Utils dependency resolution finished but no usable utils target was found.")
108+
endif()
94109

95110
# JSON linkage policy
96111
set(VIX_WEBSOCKET_WITH_JSON "AUTO" CACHE STRING "Link JSON backend (AUTO|ON|OFF)")
@@ -126,54 +141,20 @@ function(vix_websocket_try_link_json onto link_scope)
126141
endif()
127142
endfunction()
128143

129-
# Boost (public headers use Boost.Beast via core; make sure includes are SYSTEM to avoid 3rd-party warnings)
130-
set(VIX_WEBSOCKET_WITH_BOOST "ON" CACHE STRING "Use Boost (ON|OFF)")
131-
set_property(CACHE VIX_WEBSOCKET_WITH_BOOST PROPERTY STRINGS ON OFF)
132-
133-
set(_vix_boost_includes "")
134-
135-
if (VIX_WEBSOCKET_WITH_BOOST STREQUAL "ON")
136-
set(Boost_NO_WARN_NEW_VERSIONS ON)
137-
138-
find_package(Boost CONFIG QUIET)
139-
if (Boost_FOUND)
140-
message(STATUS "[websocket] Boost found (CONFIG)")
141-
else()
142-
message(STATUS "[websocket] Boost not found via CONFIG, using FindBoost")
143-
find_package(Boost REQUIRED COMPONENTS system)
144-
endif()
144+
# STATIC
145+
if (WEBSOCKET_SOURCES)
146+
message(STATUS "[websocket] Building STATIC library with detected sources.")
145147

146-
# Normalize headers target across toolchains
147-
if (TARGET Boost::headers AND NOT TARGET Boost::boost)
148-
add_library(Boost::boost ALIAS Boost::headers)
149-
endif()
148+
add_library(vix_websocket STATIC ${WEBSOCKET_SOURCES})
150149

151-
# FindBoost path
152-
if (Boost_INCLUDE_DIRS)
153-
list(APPEND _vix_boost_includes ${Boost_INCLUDE_DIRS})
150+
if (NOT TARGET vix::websocket)
151+
add_library(vix::websocket ALIAS vix_websocket)
154152
endif()
155153

156-
# CONFIG target path
157-
if (TARGET Boost::boost)
158-
get_target_property(_boost_target_includes Boost::boost INTERFACE_INCLUDE_DIRECTORIES)
159-
if (_boost_target_includes)
160-
list(APPEND _vix_boost_includes ${_boost_target_includes})
161-
endif()
154+
if (NOT TARGET vix::ws)
155+
add_library(vix::ws ALIAS vix_websocket)
162156
endif()
163157

164-
list(REMOVE_DUPLICATES _vix_boost_includes)
165-
else()
166-
message(FATAL_ERROR "[websocket] Boost is required. Set VIX_WEBSOCKET_WITH_BOOST=ON.")
167-
endif()
168-
169-
170-
# STATIC
171-
if (WEBSOCKET_SOURCES)
172-
message(STATUS "[websocket] Building STATIC library with detected sources.")
173-
174-
add_library(vix_websocket STATIC ${WEBSOCKET_SOURCES})
175-
add_library(vix::websocket ALIAS vix_websocket)
176-
add_library(vix::ws ALIAS vix_websocket)
177158
target_compile_features(vix_websocket PUBLIC cxx_std_20)
178159

179160
# SQLite (required for websocket storage)
@@ -189,14 +170,17 @@ if (WEBSOCKET_SOURCES)
189170
find_package(SQLite3 QUIET)
190171

191172
if (SQLite3_FOUND)
192-
# Normalize to SQLite::SQLite3 everywhere
193173
if (TARGET SQLite::SQLite3)
194174
set(_vix_sqlite_target SQLite::SQLite3)
195175
elseif (TARGET SQLite3::SQLite3)
196-
add_library(SQLite::SQLite3 ALIAS SQLite3::SQLite3)
176+
if (NOT TARGET SQLite::SQLite3)
177+
add_library(SQLite::SQLite3 ALIAS SQLite3::SQLite3)
178+
endif()
197179
set(_vix_sqlite_target SQLite::SQLite3)
198180
elseif (TARGET sqlite3)
199-
add_library(SQLite::SQLite3 ALIAS sqlite3)
181+
if (NOT TARGET SQLite::SQLite3)
182+
add_library(SQLite::SQLite3 ALIAS sqlite3)
183+
endif()
200184
set(_vix_sqlite_target SQLite::SQLite3)
201185
endif()
202186

@@ -211,24 +195,12 @@ if (WEBSOCKET_SOURCES)
211195
"hint: or provide SQLite3_INCLUDE_DIR / SQLite3_LIBRARY.\n")
212196
endif()
213197

214-
# includes
215198
target_include_directories(vix_websocket
216199
PUBLIC
217200
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
218201
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
219202
)
220203

221-
# Treat Boost headers as SYSTEM (avoid third-party warnings)
222-
if (_vix_boost_includes)
223-
target_include_directories(vix_websocket SYSTEM PUBLIC ${_vix_boost_includes})
224-
endif()
225-
226-
# Ensure Boost::boost exists/linked if available
227-
if (TARGET Boost::boost)
228-
target_link_libraries(vix_websocket PUBLIC Boost::boost)
229-
endif()
230-
231-
# link deps
232204
target_link_libraries(vix_websocket
233205
PUBLIC
234206
${VIX_CORE_TARGET}
@@ -267,13 +239,21 @@ if (WEBSOCKET_SOURCES)
267239
PATTERN "*.h"
268240
PATTERN "*.inc"
269241
)
242+
270243
# HEADER-ONLY
271244
else()
272245
message(STATUS "[websocket] Building HEADER-ONLY library (no sources).")
273246

274247
add_library(vix_websocket INTERFACE)
275-
add_library(vix::websocket ALIAS vix_websocket)
276-
add_library(vix::ws ALIAS vix_websocket)
248+
249+
if (NOT TARGET vix::websocket)
250+
add_library(vix::websocket ALIAS vix_websocket)
251+
endif()
252+
253+
if (NOT TARGET vix::ws)
254+
add_library(vix::ws ALIAS vix_websocket)
255+
endif()
256+
277257
target_compile_features(vix_websocket INTERFACE cxx_std_20)
278258

279259
if (TARGET vix_warnings)
@@ -289,15 +269,6 @@ else()
289269
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
290270
)
291271

292-
# Treat Boost headers as SYSTEM (avoid third-party warnings)
293-
if (_vix_boost_includes)
294-
target_include_directories(vix_websocket SYSTEM INTERFACE ${_vix_boost_includes})
295-
endif()
296-
297-
if (TARGET Boost::boost)
298-
target_link_libraries(vix_websocket INTERFACE Boost::boost)
299-
endif()
300-
301272
target_link_libraries(vix_websocket INTERFACE
302273
${VIX_CORE_TARGET}
303274
${VIX_UTILS_TARGET}
@@ -309,8 +280,12 @@ else()
309280
EXPORT VixTargets
310281
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
311282
)
283+
312284
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
313-
FILES_MATCHING PATTERN "*.hpp" PATTERN "*.h")
285+
FILES_MATCHING
286+
PATTERN "*.hpp"
287+
PATTERN "*.h"
288+
)
314289
endif()
315290

316291
# Examples (optional)

0 commit comments

Comments
 (0)