-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
415 lines (368 loc) · 13.6 KB
/
CMakeLists.txt
File metadata and controls
415 lines (368 loc) · 13.6 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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
# @file CMakeLists.txt
# @author Gaspard Kirira
#
# Copyright 2025, Gaspard Kirira. All rights reserved.
# https://github.com/vixcpp/vix
# Use of this source code is governed by a MIT license
# that can be found in the License file.
#
# ====================================================================
# Vix.cpp - Process Module
# ====================================================================
# Purpose:
# Portable process management utilities for Vix.
# Provides process spawning, waiting, termination, exit status,
# environment overrides, working directory control, and stdio policies.
#
# Builds as STATIC when sources exist, otherwise as a header-only
# INTERFACE target.
#
# Public Targets:
# - vix_process : The actual library target (STATIC or INTERFACE)
# - vix::process : Namespaced alias for consumers
#
# Public Dependencies:
# - vix::error
# - vix::env
# - vix::path
#
# Installation/Export:
# - Umbrella build exports into: VixTargets
# - Standalone build exports into: vix_processTargets
# ====================================================================
cmake_minimum_required(VERSION 3.20)
project(vix_process VERSION 0.1.0 LANGUAGES CXX)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
# --------------------------------------------------------------------
# Global settings
# --------------------------------------------------------------------
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# --------------------------------------------------------------------
# Export set selection
# --------------------------------------------------------------------
if (DEFINED VIX_UMBRELLA_BUILD AND VIX_UMBRELLA_BUILD)
set(VIX_PROCESS_EXPORT_SET VixTargets)
else()
set(VIX_PROCESS_EXPORT_SET vix_processTargets)
endif()
# --------------------------------------------------------------------
# Umbrella build policy:
# When building inside the Vix umbrella, dependencies are managed by the
# umbrella (add_subdirectory order + options). Process must not FetchContent
# nor add sibling subdirectories in umbrella mode.
# --------------------------------------------------------------------
if (DEFINED VIX_UMBRELLA_BUILD AND VIX_UMBRELLA_BUILD)
set(VIX_PROCESS_FETCH_ERROR OFF CACHE BOOL "Auto-fetch vix::error if missing" FORCE)
set(VIX_PROCESS_FETCH_ENV OFF CACHE BOOL "Auto-fetch vix::env if missing" FORCE)
set(VIX_PROCESS_FETCH_PATH OFF CACHE BOOL "Auto-fetch vix::path if missing" FORCE)
endif()
# --------------------------------------------------------------------
# Sources discovery
# --------------------------------------------------------------------
file(GLOB_RECURSE PROCESS_SOURCES CONFIGURE_DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp"
)
# --------------------------------------------------------------------
# Dependencies
# --------------------------------------------------------------------
option(VIX_PROCESS_FETCH_ERROR "Auto-fetch vix::error if missing" ON)
option(VIX_PROCESS_FETCH_ENV "Auto-fetch vix::env if missing" ON)
option(VIX_PROCESS_FETCH_PATH "Auto-fetch vix::path if missing" ON)
option(VIX_PROCESS_FETCH_TESTS "Auto-fetch vix::tests if missing" ON)
option(VIX_PROCESS_FETCH_ASYNC "Auto-fetch vix::async if missing" ON)
# error
if (DEFINED VIX_UMBRELLA_BUILD AND VIX_UMBRELLA_BUILD)
if (NOT TARGET vix::error)
message(FATAL_ERROR "[process] Umbrella build: vix::error must be provided by umbrella before process.")
endif()
else()
if (NOT TARGET vix::error)
if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/../error/CMakeLists.txt")
message(STATUS "[process] Adding error from sibling: ../error")
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/../error" "error")
else()
find_package(vix_error CONFIG QUIET)
endif()
if (NOT TARGET vix::error)
if (VIX_PROCESS_FETCH_ERROR)
include(FetchContent)
message(STATUS "[process] Fetching vix::error via FetchContent")
FetchContent_Declare(vix_error
GIT_REPOSITORY https://github.com/vixcpp/error.git
GIT_TAG v0.1.0
)
FetchContent_MakeAvailable(vix_error)
else()
message(FATAL_ERROR
"vix::error not found. Enable VIX_PROCESS_FETCH_ERROR=ON, install vix_error, or provide the target before process."
)
endif()
endif()
endif()
endif()
# env
if (DEFINED VIX_UMBRELLA_BUILD AND VIX_UMBRELLA_BUILD)
if (NOT TARGET vix::env)
message(FATAL_ERROR "[process] Umbrella build: vix::env must be provided by umbrella before process.")
endif()
else()
if (NOT TARGET vix::env)
if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/../env/CMakeLists.txt")
message(STATUS "[process] Adding env from sibling: ../env")
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/../env" "env")
else()
find_package(vix_env CONFIG QUIET)
endif()
if (NOT TARGET vix::env)
if (VIX_PROCESS_FETCH_ENV)
include(FetchContent)
message(STATUS "[process] Fetching vix::env via FetchContent")
FetchContent_Declare(vix_env
GIT_REPOSITORY https://github.com/vixcpp/env.git
GIT_TAG v0.1.0
)
FetchContent_MakeAvailable(vix_env)
else()
message(FATAL_ERROR
"vix::env not found. Enable VIX_PROCESS_FETCH_ENV=ON, install vix_env, or provide the target before process."
)
endif()
endif()
endif()
endif()
# path
if (DEFINED VIX_UMBRELLA_BUILD AND VIX_UMBRELLA_BUILD)
if (NOT TARGET vix::path)
message(FATAL_ERROR "[process] Umbrella build: vix::path must be provided by umbrella before process.")
endif()
else()
if (NOT TARGET vix::path)
if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/../path/CMakeLists.txt")
message(STATUS "[process] Adding path from sibling: ../path")
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/../path" "path")
else()
find_package(vix_path CONFIG QUIET)
endif()
if (NOT TARGET vix::path)
if (VIX_PROCESS_FETCH_PATH)
include(FetchContent)
message(STATUS "[process] Fetching vix::path via FetchContent")
FetchContent_Declare(vix_path
GIT_REPOSITORY https://github.com/vixcpp/path.git
GIT_TAG v0.1.0
)
FetchContent_MakeAvailable(vix_path)
else()
message(FATAL_ERROR
"vix::path not found. Enable VIX_PROCESS_FETCH_PATH=ON, install vix_path, or provide the target before process."
)
endif()
endif()
endif()
endif()
# async
if (DEFINED VIX_UMBRELLA_BUILD AND VIX_UMBRELLA_BUILD)
if (NOT TARGET vix::async)
message(FATAL_ERROR "[process] Umbrella build: vix::async must be provided by umbrella before process.")
endif()
else()
if (NOT TARGET vix::async)
if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/../async/CMakeLists.txt")
message(STATUS "[process] Adding async from sibling: ../async")
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/../async" "async")
else()
find_package(async CONFIG QUIET)
endif()
if (NOT TARGET vix::async)
message(FATAL_ERROR
"vix::async not found. Install async, provide the target before process, or add sibling module."
)
endif()
endif()
endif()
set(VIX_ERROR_TARGET vix::error)
set(VIX_ENV_TARGET vix::env)
set(VIX_PATH_TARGET vix::path)
set(VIX_ASYNC_TARGET vix::async)
# --------------------------------------------------------------------
# Library target
# --------------------------------------------------------------------
if (PROCESS_SOURCES)
message(STATUS "[process] Building STATIC library with detected sources.")
add_library(vix_process STATIC ${PROCESS_SOURCES})
add_library(vix::process ALIAS vix_process)
target_compile_features(vix_process PUBLIC cxx_std_20)
target_include_directories(vix_process
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_link_libraries(vix_process
PUBLIC
${VIX_ERROR_TARGET}
${VIX_ENV_TARGET}
${VIX_PATH_TARGET}
${VIX_ASYNC_TARGET}
)
if (WIN32)
target_link_libraries(vix_process PRIVATE
kernel32
)
endif()
# Build-only helpers must not leak into exported interfaces.
if (NOT MSVC)
target_compile_options(vix_process PRIVATE
-Wall
-Wextra
-Wpedantic
)
endif()
if (VIX_ENABLE_SANITIZERS AND NOT MSVC)
target_compile_options(vix_process PRIVATE
-fno-omit-frame-pointer
-fsanitize=address,undefined
)
target_link_options(vix_process PRIVATE
-fsanitize=address,undefined
)
endif()
set_target_properties(vix_process PROPERTIES
OUTPUT_NAME vix_process
VERSION ${PROJECT_VERSION}
SOVERSION 0
EXPORT_NAME process
)
install(TARGETS vix_process
EXPORT ${VIX_PROCESS_EXPORT_SET}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
else()
message(STATUS "[process] Building HEADER-ONLY library (no sources).")
add_library(vix_process INTERFACE)
add_library(vix::process ALIAS vix_process)
target_compile_features(vix_process INTERFACE cxx_std_20)
target_include_directories(vix_process INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_link_libraries(vix_process
PUBLIC
${VIX_ERROR_TARGET}
${VIX_ENV_TARGET}
${VIX_PATH_TARGET}
${VIX_ASYNC_TARGET}
)
install(TARGETS vix_process
EXPORT ${VIX_PROCESS_EXPORT_SET}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
endif()
# --------------------------------------------------------------------
# Install headers
# --------------------------------------------------------------------
if (NOT (DEFINED VIX_UMBRELLA_BUILD AND VIX_UMBRELLA_BUILD))
install(DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING
PATTERN "*.hpp"
PATTERN "*.h"
)
endif()
# --------------------------------------------------------------------
# Standalone package config/export
# Only for non-umbrella builds
# --------------------------------------------------------------------
if (NOT (DEFINED VIX_UMBRELLA_BUILD AND VIX_UMBRELLA_BUILD))
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/vix_processConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/vix_processConfig.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/vix_process"
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/vix_processConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/vix_processConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/vix_processConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/vix_process"
)
install(EXPORT vix_processTargets
FILE vix_processTargets.cmake
NAMESPACE vix::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/vix_process"
)
endif()
# --------------------------------------------------------------------
# Tests dependency (vix::tests)
# --------------------------------------------------------------------
option(VIX_PROCESS_FETCH_TESTS "Auto-fetch vix::tests if missing" ON)
if (VIX_PROCESS_BUILD_TESTS)
if (DEFINED VIX_UMBRELLA_BUILD AND VIX_UMBRELLA_BUILD)
if (NOT TARGET vix::tests)
message(FATAL_ERROR "[process] Umbrella build: vix::tests must be provided before process tests.")
endif()
else()
if (NOT TARGET vix::tests)
if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/../tests/CMakeLists.txt")
message(STATUS "[process] Adding tests from sibling: ../tests")
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/../tests" "tests")
else()
find_package(vix_tests CONFIG QUIET)
endif()
if (NOT TARGET vix::tests)
if (VIX_PROCESS_FETCH_TESTS)
include(FetchContent)
message(STATUS "[process] Fetching vix::tests via FetchContent")
FetchContent_Declare(vix_tests
GIT_REPOSITORY https://github.com/vixcpp/tests.git
GIT_TAG v0.1.0
)
FetchContent_MakeAvailable(vix_tests)
else()
message(FATAL_ERROR "vix::tests not found.")
endif()
endif()
endif()
endif()
endif()
# --------------------------------------------------------------------
# Tests
# --------------------------------------------------------------------
option(VIX_PROCESS_BUILD_TESTS "Build process module tests" OFF)
if (VIX_PROCESS_BUILD_TESTS)
include(CTest)
enable_testing()
add_subdirectory(test)
endif()
# --------------------------------------------------------------------
# Examples
# --------------------------------------------------------------------
option(VIX_PROCESS_BUILD_EXAMPLES "Build process module examples" OFF)
if (VIX_PROCESS_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
# --------------------------------------------------------------------
# Summary
# --------------------------------------------------------------------
message(STATUS "------------------------------------------------------")
message(STATUS "vix::process configured (${PROJECT_VERSION})")
if (PROCESS_SOURCES)
message(STATUS "Mode: STATIC / sources found")
else()
message(STATUS "Mode: HEADER-ONLY / no sources")
endif()
message(STATUS "Export set: ${VIX_PROCESS_EXPORT_SET}")
message(STATUS "Error target: ${VIX_ERROR_TARGET}")
message(STATUS "Env target: ${VIX_ENV_TARGET}")
message(STATUS "Path target: ${VIX_PATH_TARGET}")
message(STATUS "Include dir: ${CMAKE_CURRENT_SOURCE_DIR}/include (for <vix/process/...>)")
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS "------------------------------------------------------")