22# @file CMakeLists.txt
33# @author Gaspard Kirira
44#
5- # Copyright 2025 , Gaspard Kirira. All rights reserved.
5+ # Copyright 2026 , Gaspard Kirira. All rights reserved.
66# https://github.com/vixcpp/vix
77# Use of this source code is governed by a MIT license
88# that can be found in the License file.
1111# Vix.cpp - Net Module
1212# ====================================================================
1313# Purpose:
14- # Low-level networking primitives for Vix (connectivity probing,
15- # reachability checks, lightweight network utilities). Builds as
16- # STATIC when sources exist, otherwise as a header-only INTERFACE target.
14+ # Low-level networking primitives for Vix.
15+ # Provides connectivity probing and outbound HTTP client abstractions.
1716#
1817# Public Targets:
19- # - vix_net : The actual library target (STATIC or INTERFACE)
18+ # - vix_net : The actual library target
2019# - vix::net : Namespaced alias for consumers
2120#
2221# Public Dependencies:
23- # - None
22+ # - vix::error
23+ # - vix::process
2424#
2525# Installation/Export:
2626# - Umbrella build exports into: VixTargets
@@ -41,14 +41,23 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
4141set (CMAKE_POSITION_INDEPENDENT_CODE ON )
4242
4343# --------------------------------------------------------------------
44- # Export set selection ✅ CRUCIAL
44+ # Export set selection
4545# --------------------------------------------------------------------
4646if (DEFINED VIX_UMBRELLA_BUILD AND VIX_UMBRELLA_BUILD)
4747 set (VIX_NET_EXPORT_SET VixTargets)
4848else ()
4949 set (VIX_NET_EXPORT_SET vix_netTargets)
5050endif ()
5151
52+ # --------------------------------------------------------------------
53+ # Umbrella build policy
54+ # --------------------------------------------------------------------
55+ if (DEFINED VIX_UMBRELLA_BUILD AND VIX_UMBRELLA_BUILD)
56+ set (VIX_NET_FETCH_ERROR OFF CACHE BOOL "Auto-fetch vix::error if missing" FORCE )
57+ set (VIX_NET_FETCH_PROCESS OFF CACHE BOOL "Auto-fetch vix::process if missing" FORCE )
58+ set (VIX_NET_FETCH_TESTS OFF CACHE BOOL "Auto-fetch vix::tests if missing" FORCE )
59+ endif ()
60+
5261# --------------------------------------------------------------------
5362# Sources discovery
5463# --------------------------------------------------------------------
@@ -57,7 +66,81 @@ file(GLOB_RECURSE NET_SOURCES CONFIGURE_DEPENDS
5766)
5867
5968# --------------------------------------------------------------------
60- # Library mode
69+ # Dependencies
70+ # --------------------------------------------------------------------
71+ option (VIX_NET_FETCH_ERROR "Auto-fetch vix::error if missing" ON )
72+ option (VIX_NET_FETCH_PROCESS "Auto-fetch vix::process if missing" ON )
73+ option (VIX_NET_FETCH_TESTS "Auto-fetch vix::tests if missing" ON )
74+
75+ # error
76+ if (DEFINED VIX_UMBRELLA_BUILD AND VIX_UMBRELLA_BUILD)
77+ if (NOT TARGET vix::error)
78+ message (FATAL_ERROR "[net] Umbrella build: vix::error must be provided by umbrella before net." )
79+ endif ()
80+ else ()
81+ if (NOT TARGET vix::error)
82+ if (EXISTS "${CMAKE_CURRENT_LIST_DIR } /../error/CMakeLists.txt" )
83+ message (STATUS "[net] Adding error from sibling: ../error" )
84+ add_subdirectory ("${CMAKE_CURRENT_LIST_DIR } /../error" "error" )
85+ else ()
86+ find_package (vix_error CONFIG QUIET )
87+ endif ()
88+
89+ if (NOT TARGET vix::error)
90+ if (VIX_NET_FETCH_ERROR)
91+ include (FetchContent )
92+ message (STATUS "[net] Fetching vix::error via FetchContent" )
93+ FetchContent_Declare (vix_error
94+ GIT_REPOSITORY https://github.com/vixcpp/error.git
95+ GIT_TAG v0.1.0
96+ )
97+ FetchContent_MakeAvailable (vix_error)
98+ else ()
99+ message (FATAL_ERROR
100+ "vix::error not found. Enable VIX_NET_FETCH_ERROR=ON, install vix_error, or provide the target before net."
101+ )
102+ endif ()
103+ endif ()
104+ endif ()
105+ endif ()
106+
107+ # process
108+ if (DEFINED VIX_UMBRELLA_BUILD AND VIX_UMBRELLA_BUILD)
109+ if (NOT TARGET vix::process)
110+ message (FATAL_ERROR "[net] Umbrella build: vix::process must be provided by umbrella before net." )
111+ endif ()
112+ else ()
113+ if (NOT TARGET vix::process)
114+ if (EXISTS "${CMAKE_CURRENT_LIST_DIR } /../process/CMakeLists.txt" )
115+ message (STATUS "[net] Adding process from sibling: ../process" )
116+ add_subdirectory ("${CMAKE_CURRENT_LIST_DIR } /../process" "process" )
117+ else ()
118+ find_package (vix_process CONFIG QUIET )
119+ endif ()
120+
121+ if (NOT TARGET vix::process)
122+ if (VIX_NET_FETCH_PROCESS)
123+ include (FetchContent )
124+ message (STATUS "[net] Fetching vix::process via FetchContent" )
125+ FetchContent_Declare (vix_process
126+ GIT_REPOSITORY https://github.com/vixcpp/process.git
127+ GIT_TAG v0.1.0
128+ )
129+ FetchContent_MakeAvailable (vix_process)
130+ else ()
131+ message (FATAL_ERROR
132+ "vix::process not found. Enable VIX_NET_FETCH_PROCESS=ON, install vix_process, or provide the target before net."
133+ )
134+ endif ()
135+ endif ()
136+ endif ()
137+ endif ()
138+
139+ set (VIX_ERROR_TARGET vix::error)
140+ set (VIX_PROCESS_TARGET vix::process)
141+
142+ # --------------------------------------------------------------------
143+ # Library target
61144# --------------------------------------------------------------------
62145if (NET_SOURCES)
63146 message (STATUS "[net] Building STATIC library with detected sources." )
@@ -73,16 +156,27 @@ if (NET_SOURCES)
73156 $<INSTALL_INTERFACE :${CMAKE_INSTALL_INCLUDEDIR} >
74157 )
75158
76- # Build-only helpers (ne doivent pas être exportés)
77- if (TARGET vix_warnings)
78- target_link_libraries (vix_net PRIVATE
79- $<BUILD_INTERFACE :vix_warnings >
159+ target_link_libraries (vix_net
160+ PUBLIC
161+ ${VIX_ERROR_TARGET}
162+ ${VIX_PROCESS_TARGET}
163+ )
164+
165+ if (NOT MSVC )
166+ target_compile_options (vix_net PRIVATE
167+ -Wall
168+ -Wextra
169+ -Wpedantic
80170 )
81171 endif ()
82172
83- if (VIX_ENABLE_SANITIZERS AND TARGET vix_sanitizers)
84- target_link_libraries (vix_net PRIVATE
85- $<BUILD_INTERFACE :vix_sanitizers >
173+ if (VIX_ENABLE_SANITIZERS AND NOT MSVC )
174+ target_compile_options (vix_net PRIVATE
175+ -fno-omit-frame-pointer
176+ -fsanitize=address,undefined
177+ )
178+ target_link_options (vix_net PRIVATE
179+ -fsanitize=address,undefined
86180 )
87181 endif ()
88182
@@ -101,11 +195,8 @@ if (NET_SOURCES)
101195 INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
102196 )
103197
104- # --------------------------------------------------------------------
105- # Header-only mode
106- # --------------------------------------------------------------------
107198else ()
108- message (STATUS "[net] Building HEADER-ONLY library (no sources) ." )
199+ message (STATUS "[net] Building HEADER-ONLY library." )
109200
110201 add_library (vix_net INTERFACE )
111202 add_library (vix::net ALIAS vix_net )
@@ -117,6 +208,12 @@ else()
117208 $<INSTALL_INTERFACE :${CMAKE_INSTALL_INCLUDEDIR} >
118209 )
119210
211+ target_link_libraries (vix_net
212+ INTERFACE
213+ ${VIX_ERROR_TARGET}
214+ ${VIX_PROCESS_TARGET}
215+ )
216+
120217 set_target_properties (vix_net PROPERTIES
121218 EXPORT_NAME net
122219 )
@@ -128,19 +225,19 @@ else()
128225endif ()
129226
130227# --------------------------------------------------------------------
131- # Install headers (standalone only)
228+ # Install headers
132229# --------------------------------------------------------------------
133230if (NOT (DEFINED VIX_UMBRELLA_BUILD AND VIX_UMBRELLA_BUILD))
134- install (
135- DIRECTORY include/
231+ install (DIRECTORY include/
136232 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
137- FILES_MATCHING PATTERN "*.hpp" PATTERN "*.h"
233+ FILES_MATCHING
234+ PATTERN "*.hpp"
235+ PATTERN "*.h"
138236 )
139237endif ()
140238
141239# --------------------------------------------------------------------
142240# Standalone package config/export
143- # IMPORTANT: uniquement hors umbrella
144241# --------------------------------------------------------------------
145242if (NOT (DEFINED VIX_UMBRELLA_BUILD AND VIX_UMBRELLA_BUILD))
146243
@@ -171,15 +268,47 @@ if (NOT (DEFINED VIX_UMBRELLA_BUILD AND VIX_UMBRELLA_BUILD))
171268endif ()
172269
173270# --------------------------------------------------------------------
174- # Tests
271+ # Tests dependency
175272# --------------------------------------------------------------------
176273option (VIX_NET_BUILD_TESTS "Build net module tests" OFF )
177274
178275if (VIX_NET_BUILD_TESTS)
276+ if (DEFINED VIX_UMBRELLA_BUILD AND VIX_UMBRELLA_BUILD)
277+ if (NOT TARGET vix::tests)
278+ message (FATAL_ERROR "[net] Umbrella build: vix::tests must be provided before net tests." )
279+ endif ()
280+ else ()
281+ if (NOT TARGET vix::tests)
282+ if (EXISTS "${CMAKE_CURRENT_LIST_DIR } /../tests/CMakeLists.txt" )
283+ message (STATUS "[net] Adding tests from sibling: ../tests" )
284+ add_subdirectory ("${CMAKE_CURRENT_LIST_DIR } /../tests" "tests" )
285+ else ()
286+ find_package (vix_tests CONFIG QUIET )
287+ endif ()
288+
289+ if (NOT TARGET vix::tests)
290+ if (VIX_NET_FETCH_TESTS)
291+ include (FetchContent )
292+ message (STATUS "[net] Fetching vix::tests via FetchContent" )
293+ FetchContent_Declare (vix_tests
294+ GIT_REPOSITORY https://github.com/vixcpp/tests.git
295+ GIT_TAG v0.1.0
296+ )
297+ FetchContent_MakeAvailable (vix_tests)
298+ else ()
299+ message (FATAL_ERROR "vix::tests not found." )
300+ endif ()
301+ endif ()
302+ endif ()
303+ endif ()
304+
305+ include (CTest )
306+ enable_testing ()
307+
179308 if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR } /tests/CMakeLists.txt" )
180- include (CTest )
181- enable_testing ()
182309 add_subdirectory (tests )
310+ elseif (EXISTS "${CMAKE_CURRENT_SOURCE_DIR } /test/CMakeLists.txt" )
311+ add_subdirectory (test )
183312 endif ()
184313endif ()
185314
@@ -193,8 +322,9 @@ if (NET_SOURCES)
193322else ()
194323 message (STATUS "Mode: HEADER-ONLY / no sources" )
195324endif ()
196- message (STATUS "Export set: ${VIX_NET_EXPORT_SET} " )
197- message (STATUS "Include dir: ${CMAKE_CURRENT_SOURCE_DIR } /include (for <vix/...>)" )
198- message (STATUS "Sanitizers: ${VIX_ENABLE_SANITIZERS} " )
199- message (STATUS "Build type: ${CMAKE_BUILD_TYPE } " )
325+ message (STATUS "Export set: ${VIX_NET_EXPORT_SET} " )
326+ message (STATUS "Error target: ${VIX_ERROR_TARGET} " )
327+ message (STATUS "Process target: ${VIX_PROCESS_TARGET} " )
328+ message (STATUS "Include dir: ${CMAKE_CURRENT_SOURCE_DIR } /include (for <vix/net/...>)" )
329+ message (STATUS "Build type: ${CMAKE_BUILD_TYPE } " )
200330message (STATUS "------------------------------------------------------" )
0 commit comments