-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
449 lines (388 loc) · 13.2 KB
/
Copy pathCMakeLists.txt
File metadata and controls
449 lines (388 loc) · 13.2 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
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
# @file CMakeLists.txt
# @author Softadastra
#
# Copyright 2026, Softadastra. All rights reserved.
# https://github.com/softadastra/kordex-cli
# Use of this source code is governed by a MIT license
# that can be found in the LICENSE file.
#
# ====================================================================
# Kordex CLI
# ====================================================================
cmake_minimum_required(VERSION 3.20)
project(kordex_cli
VERSION 0.1.0
DESCRIPTION "Official command line interface for Kordex."
LANGUAGES CXX)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/KordexCliOptions.cmake")
# --------------------------------------------------------------------
# Global settings
# --------------------------------------------------------------------
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# --------------------------------------------------------------------
# Export set selection
# --------------------------------------------------------------------
if(DEFINED KORDEX_UMBRELLA_BUILD AND KORDEX_UMBRELLA_BUILD)
set(KORDEX_CLI_EXPORT_SET KordexTargets)
else()
set(KORDEX_CLI_EXPORT_SET kordex_cliTargets)
endif()
# --------------------------------------------------------------------
# Helpers
# --------------------------------------------------------------------
function(kordex_cli_require_target target_name package_name sibling_dir fetch_option repository tag)
if(TARGET ${target_name})
return()
endif()
if(DEFINED KORDEX_UMBRELLA_BUILD AND KORDEX_UMBRELLA_BUILD)
message(FATAL_ERROR
"[cli] Umbrella build requires target '${target_name}' to be provided by the root project.")
endif()
set(local_kordex_dep
"${CMAKE_CURRENT_LIST_DIR}/../${sibling_dir}")
set(local_vix_dep
"${CMAKE_CURRENT_LIST_DIR}/../../deps/vix/${sibling_dir}")
if(EXISTS "${local_kordex_dep}/CMakeLists.txt")
message(STATUS "[cli] Adding ${target_name} from Kordex sibling: ${local_kordex_dep}")
add_subdirectory(
"${local_kordex_dep}"
"${CMAKE_CURRENT_BINARY_DIR}/_deps/${sibling_dir}")
elseif(EXISTS "${local_vix_dep}/CMakeLists.txt")
message(STATUS "[cli] Adding ${target_name} from umbrella Vix dependency: ${local_vix_dep}")
add_subdirectory(
"${local_vix_dep}"
"${CMAKE_CURRENT_BINARY_DIR}/_deps/vix_${sibling_dir}")
else()
find_package(${package_name} CONFIG QUIET)
endif()
if(TARGET ${target_name})
return()
endif()
if(${fetch_option})
include(FetchContent)
message(STATUS "[cli] Fetching ${target_name}")
FetchContent_Declare(
${package_name}
GIT_REPOSITORY ${repository}
GIT_TAG ${tag}
GIT_SHALLOW TRUE)
FetchContent_MakeAvailable(${package_name})
endif()
if(NOT TARGET ${target_name})
message(FATAL_ERROR
"[cli] Required dependency target '${target_name}' was not found.\n"
"Install package '${package_name}', provide sibling '../${sibling_dir}', "
"provide umbrella dependency '../../deps/vix/${sibling_dir}', "
"or enable ${fetch_option}.")
endif()
endfunction()
# --------------------------------------------------------------------
# Dependencies
# --------------------------------------------------------------------
kordex_cli_require_target(
kordex::runtime
kordex_runtime
runtime
KORDEX_CLI_FETCH_RUNTIME
https://github.com/kordexjs/runtime.git
${KORDEX_RUNTIME_GIT_TAG})
kordex_cli_require_target(
kordex::bindings
kordex_bindings
bindings
KORDEX_CLI_FETCH_BINDINGS
https://github.com/kordexjs/bindings.git
${KORDEX_BINDINGS_GIT_TAG})
kordex_cli_require_target(
kordex::std
kordex_std
std
KORDEX_CLI_FETCH_STD
https://github.com/kordexjs/std.git
${KORDEX_STD_GIT_TAG})
kordex_cli_require_target(
vix::error
vix_error
error
KORDEX_CLI_FETCH_ERROR
https://github.com/vixcpp/error.git
${KORDEX_VIX_GIT_TAG})
kordex_cli_require_target(
vix::log
vix_log
log
KORDEX_CLI_FETCH_LOG
https://github.com/vixcpp/log.git
${KORDEX_VIX_GIT_TAG})
kordex_cli_require_target(
vix::json
vix_json
json
KORDEX_CLI_FETCH_JSON
https://github.com/vixcpp/json.git
${KORDEX_VIX_GIT_TAG})
kordex_cli_require_target(
vix::fs
vix_fs
fs
KORDEX_CLI_FETCH_FS
https://github.com/vixcpp/fs.git
${KORDEX_VIX_GIT_TAG})
kordex_cli_require_target(
vix::path
vix_path
path
KORDEX_CLI_FETCH_PATH
https://github.com/vixcpp/path.git
${KORDEX_VIX_GIT_TAG})
kordex_cli_require_target(
vix::env
vix_env
env
KORDEX_CLI_FETCH_ENV
https://github.com/vixcpp/env.git
${KORDEX_VIX_GIT_TAG})
kordex_cli_require_target(
vix::process
vix_process
process
KORDEX_CLI_FETCH_PROCESS
https://github.com/vixcpp/process.git
${KORDEX_VIX_GIT_TAG})
kordex_cli_require_target(
vix::time
vix_time
time
KORDEX_CLI_FETCH_TIME
https://github.com/vixcpp/time.git
${KORDEX_VIX_GIT_TAG})
set(KORDEX_CLI_DEPENDENCIES
kordex::runtime
kordex::bindings
kordex::std
vix::error
vix::log
vix::json
vix::fs
vix::path
vix::env
vix::process
vix::time)
# --------------------------------------------------------------------
# Sources
# --------------------------------------------------------------------
set(KORDEX_CLI_HEADERS
include/kordex/cli/Version.hpp
include/kordex/cli/Error.hpp
include/kordex/cli/Result.hpp
include/kordex/cli/CliOptions.hpp
include/kordex/cli/CliConfig.hpp
include/kordex/cli/CliResult.hpp
include/kordex/cli/Command.hpp
include/kordex/cli/CommandRegistry.hpp
include/kordex/cli/ArgumentParser.hpp
include/kordex/cli/HelpFormatter.hpp
include/kordex/cli/Output.hpp
include/kordex/cli/Commands.hpp
include/kordex/cli/ProjectDiscovery.hpp
include/kordex/cli/InstallCommand.hpp
include/kordex/cli/UpdateCommand.hpp
include/kordex/cli/PermissionBridge.hpp
include/kordex/cli/PluginCommandRegistry.hpp
include/kordex/cli/InitCommand.hpp
include/kordex/cli/RunCommand.hpp
include/kordex/cli/CheckCommand.hpp
include/kordex/cli/BuildCommand.hpp
include/kordex/cli/ReplCommand.hpp
include/kordex/cli/VersionCommand.hpp
include/kordex/cli/Cli.hpp)
set(KORDEX_CLI_SOURCES
src/Version.cpp
src/Error.cpp
src/CliOptions.cpp
src/CliConfig.cpp
src/CliResult.cpp
src/Command.cpp
src/CommandRegistry.cpp
src/ArgumentParser.cpp
src/HelpFormatter.cpp
src/Output.cpp
src/Commands.cpp
src/ProjectDiscovery.cpp
src/InstallCommand.cpp
src/UpdateCommand.cpp
src/PermissionBridge.cpp
src/PluginCommandRegistry.cpp
src/InitCommand.cpp
src/RunCommand.cpp
src/CheckCommand.cpp
src/BuildCommand.cpp
src/ReplCommand.cpp
src/VersionCommand.cpp
src/Cli.cpp)
# --------------------------------------------------------------------
# Library
# --------------------------------------------------------------------
add_library(kordex_cli STATIC
${KORDEX_CLI_HEADERS}
${KORDEX_CLI_SOURCES})
add_library(kordex::cli ALIAS kordex_cli)
target_compile_features(kordex_cli
PUBLIC
cxx_std_20)
target_include_directories(kordex_cli
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
target_link_libraries(kordex_cli
PUBLIC
${KORDEX_CLI_DEPENDENCIES})
target_compile_definitions(kordex_cli
PUBLIC
KORDEX_CLI_VERSION_STRING="${PROJECT_VERSION}"
KORDEX_CLI_ENABLE_INIT_COMMAND=$<BOOL:${KORDEX_CLI_ENABLE_INIT_COMMAND}>
KORDEX_CLI_ENABLE_RUN_COMMAND=$<BOOL:${KORDEX_CLI_ENABLE_RUN_COMMAND}>
KORDEX_CLI_ENABLE_CHECK_COMMAND=$<BOOL:${KORDEX_CLI_ENABLE_CHECK_COMMAND}>
KORDEX_CLI_ENABLE_BUILD_COMMAND=$<BOOL:${KORDEX_CLI_ENABLE_BUILD_COMMAND}>
KORDEX_CLI_ENABLE_REPL_COMMAND=$<BOOL:${KORDEX_CLI_ENABLE_REPL_COMMAND}>
KORDEX_CLI_ENABLE_VERSION_COMMAND=$<BOOL:${KORDEX_CLI_ENABLE_VERSION_COMMAND}>)
if(KORDEX_CLI_ENABLE_WARNINGS)
target_compile_options(kordex_cli
PRIVATE
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wall -Wextra -Wpedantic>
$<$<CXX_COMPILER_ID:MSVC>:/W4>)
endif()
if(KORDEX_CLI_ENABLE_SANITIZERS)
if(MSVC)
message(WARNING "[cli] Sanitizers are not enabled for MSVC in this CMake configuration.")
else()
target_compile_options(kordex_cli
PRIVATE
-fno-omit-frame-pointer
-fsanitize=address,undefined)
target_link_options(kordex_cli
PRIVATE
-fsanitize=address,undefined)
endif()
endif()
set_target_properties(kordex_cli PROPERTIES
OUTPUT_NAME kordex_cli
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
EXPORT_NAME cli)
# --------------------------------------------------------------------
# App
# --------------------------------------------------------------------
if(KORDEX_CLI_BUILD_APP)
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/app/main.cpp")
message(FATAL_ERROR "[cli] app/main.cpp is required when KORDEX_CLI_BUILD_APP=ON")
endif()
add_executable(kordex
app/main.cpp)
target_link_libraries(kordex
PRIVATE
kordex::cli)
target_compile_features(kordex
PRIVATE
cxx_std_20)
if(KORDEX_CLI_ENABLE_INSTALL)
install(
TARGETS kordex
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
endif()
# --------------------------------------------------------------------
# Tests dependency
# --------------------------------------------------------------------
if(KORDEX_CLI_BUILD_TESTS)
kordex_cli_require_target(
vix::tests
vix_tests
tests
KORDEX_CLI_FETCH_TESTS
https://github.com/vixcpp/tests.git
${KORDEX_VIX_GIT_TAG})
endif()
# --------------------------------------------------------------------
# Tests
# --------------------------------------------------------------------
if(KORDEX_CLI_BUILD_TESTS)
include(CTest)
enable_testing()
add_subdirectory(tests)
endif()
# --------------------------------------------------------------------
# Examples
# --------------------------------------------------------------------
if(KORDEX_CLI_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
# --------------------------------------------------------------------
# Install
# --------------------------------------------------------------------
if(KORDEX_CLI_ENABLE_INSTALL
AND NOT (DEFINED KORDEX_UMBRELLA_BUILD AND KORDEX_UMBRELLA_BUILD))
install(
TARGETS kordex_cli
EXPORT kordex_cliTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(
DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING
PATTERN "*.hpp"
PATTERN "*.h")
# --------------------------------------------------------------------
# Standalone package config/export
# --------------------------------------------------------------------
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/KordexCliConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/kordex_cliConfig.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/kordex_cli")
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/kordex_cliConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/kordex_cliConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/kordex_cliConfigVersion.cmake"
DESTINATION
"${CMAKE_INSTALL_LIBDIR}/cmake/kordex_cli")
install(
EXPORT kordex_cliTargets
FILE kordex_cliTargets.cmake
NAMESPACE kordex::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/kordex_cli")
endif()
# --------------------------------------------------------------------
# Summary
# --------------------------------------------------------------------
message(STATUS "")
message(STATUS "Kordex CLI")
message(STATUS " version : ${PROJECT_VERSION}")
message(STATUS " target : kordex::cli")
message(STATUS " export : ${KORDEX_CLI_EXPORT_SET}")
message(STATUS " compiler : ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}")
message(STATUS " build : ${CMAKE_BUILD_TYPE}")
message(STATUS " app : ${KORDEX_CLI_BUILD_APP}")
message(STATUS " tests : ${KORDEX_CLI_BUILD_TESTS}")
message(STATUS " examples : ${KORDEX_CLI_BUILD_EXAMPLES}")
message(STATUS " warnings : ${KORDEX_CLI_ENABLE_WARNINGS}")
message(STATUS " sanitizers : ${KORDEX_CLI_ENABLE_SANITIZERS}")
message(STATUS " install : ${KORDEX_CLI_ENABLE_INSTALL}")
message(STATUS " init command : ${KORDEX_CLI_ENABLE_INIT_COMMAND}")
message(STATUS " run command : ${KORDEX_CLI_ENABLE_RUN_COMMAND}")
message(STATUS " check command : ${KORDEX_CLI_ENABLE_CHECK_COMMAND}")
message(STATUS " build command : ${KORDEX_CLI_ENABLE_BUILD_COMMAND}")
message(STATUS " repl command : ${KORDEX_CLI_ENABLE_REPL_COMMAND}")
message(STATUS " version command: ${KORDEX_CLI_ENABLE_VERSION_COMMAND}")
message(STATUS "")