-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
184 lines (158 loc) · 6.17 KB
/
CMakeLists.txt
File metadata and controls
184 lines (158 loc) · 6.17 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
# @file CMakeLists.cpp
# @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 — CLI Module
# ====================================================================
cmake_minimum_required(VERSION 3.20)
# ----------------------------------------------------
# Standalone vs Umbrella
# - If this module is built alone: define a project()
# - If built from umbrella: DO NOT call project() here
# ----------------------------------------------------
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
project(vix_cli VERSION 1.16.5 LANGUAGES CXX)
endif()
include(GNUInstallDirs)
include(CheckCXXCompilerFlag)
# Prevent accidental ORM auto-pulls in some setups
set(CMAKE_DISABLE_FIND_PACKAGE_VixOrm ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
file(GLOB_RECURSE CLI_SOURCES
CONFIGURE_DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp"
)
add_executable(vix_cli ${CLI_SOURCES})
add_executable(vix::cli ALIAS vix_cli)
target_include_directories(vix_cli PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
function(vix_add_flag_if_supported tgt flag)
string(REGEX REPLACE "[^A-Za-z0-9]" "_" flag_var "${flag}")
set(test_var "HAVE_${flag_var}")
check_cxx_compiler_flag("${flag}" ${test_var})
if(${test_var})
target_compile_options(${tgt} PRIVATE "${flag}")
endif()
endfunction()
if (MSVC)
vix_add_flag_if_supported(vix_cli /W4)
vix_add_flag_if_supported(vix_cli /permissive-)
else()
vix_add_flag_if_supported(vix_cli -Wall)
vix_add_flag_if_supported(vix_cli -Wextra)
vix_add_flag_if_supported(vix_cli -Wshadow)
vix_add_flag_if_supported(vix_cli -Wconversion)
vix_add_flag_if_supported(vix_cli -Wformat=2)
vix_add_flag_if_supported(vix_cli -Wpedantic)
endif()
# ----------------------------------------------------
# Link dependencies
# ----------------------------------------------------
if (TARGET vix::vix)
message(STATUS "[cli] Using umbrella target vix::vix")
target_link_libraries(vix_cli PRIVATE vix::vix)
elseif (TARGET vix::core)
message(STATUS "[cli] Using umbrella target vix::core")
target_link_libraries(vix_cli PRIVATE vix::core)
else()
# Standalone or external build using installed package
get_filename_component(_VIX_MODULES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/.." ABSOLUTE)
set(_VIX_CORE_DIR "${_VIX_MODULES_DIR}/core")
set(_VIX_UTILS_DIR "${_VIX_MODULES_DIR}/utils")
if (EXISTS "${_VIX_CORE_DIR}/CMakeLists.txt" AND EXISTS "${_VIX_UTILS_DIR}/CMakeLists.txt")
message(STATUS "[cli] Building inside Vix repo → adding local modules/core & modules/utils")
add_subdirectory("${_VIX_UTILS_DIR}" "${CMAKE_BINARY_DIR}/_vix_utils")
add_subdirectory("${_VIX_CORE_DIR}" "${CMAKE_BINARY_DIR}/_vix_core")
target_link_libraries(vix_cli PRIVATE vix::core)
else()
find_package(Vix CONFIG REQUIRED)
if (TARGET vix::vix)
message(STATUS "[cli] Using system Vix package (vix::vix)")
target_link_libraries(vix_cli PRIVATE vix::vix)
elseif (TARGET vix::core)
message(STATUS "[cli] Using system Vix package (vix::core)")
target_link_libraries(vix_cli PRIVATE vix::core)
else()
message(FATAL_ERROR
"Missing dependencies for vix_cli.\n"
"Expected vix::vix or vix::core from the installed Vix package."
)
endif()
endif()
endif()
if (TARGET vix_warnings)
target_link_libraries(vix_cli PRIVATE vix_warnings)
endif()
if (VIX_ENABLE_SANITIZERS AND TARGET vix_sanitizers)
target_link_libraries(vix_cli PRIVATE vix_sanitizers)
endif()
# ----------------------------------------------------
# Version string
# ----------------------------------------------------
set(_VIX_CLI_VERSION "dev")
if (DEFINED VIX_CLI_VERSION AND NOT "${VIX_CLI_VERSION}" STREQUAL "")
set(_VIX_CLI_VERSION "${VIX_CLI_VERSION}")
elseif (DEFINED ENV{VIX_CLI_VERSION} AND NOT "$ENV{VIX_CLI_VERSION}" STREQUAL "")
set(_VIX_CLI_VERSION "$ENV{VIX_CLI_VERSION}")
elseif (DEFINED VIX_UMBRELLA_VERSION AND NOT "${VIX_UMBRELLA_VERSION}" STREQUAL "")
set(_VIX_CLI_VERSION "${VIX_UMBRELLA_VERSION}")
else()
find_package(Git QUIET)
if (Git_FOUND)
execute_process(
COMMAND "${GIT_EXECUTABLE}" describe --tags --always
WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}"
OUTPUT_VARIABLE _GIT_DESCRIBE
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
if (_GIT_DESCRIBE)
set(_VIX_CLI_VERSION "${_GIT_DESCRIBE}")
endif()
endif()
if ("${_VIX_CLI_VERSION}" STREQUAL "dev" AND DEFINED PROJECT_VERSION AND NOT "${PROJECT_VERSION}" STREQUAL "")
set(_VIX_CLI_VERSION "v${PROJECT_VERSION}")
endif()
endif()
message(STATUS "Vix CLI version: ${_VIX_CLI_VERSION}")
target_compile_definitions(vix_cli PRIVATE VIX_CLI_VERSION="${_VIX_CLI_VERSION}")
# ----------------------------------------------------
# LTO (Release only)
# ----------------------------------------------------
if (VIX_ENABLE_LTO AND CMAKE_BUILD_TYPE STREQUAL "Release")
include(CheckIPOSupported)
check_ipo_supported(RESULT _ipo_ok OUTPUT _ipo_msg)
if (_ipo_ok)
set_property(TARGET vix_cli PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(WARNING "[cli] IPO/LTO not supported: ${_ipo_msg}")
endif()
endif()
# ----------------------------------------------------
# Output name + stable output directory for CI packaging
# ----------------------------------------------------
set_target_properties(vix_cli PROPERTIES
OUTPUT_NAME vix
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}"
RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_BINARY_DIR}"
RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}"
)
# ----------------------------------------------------
# Install (standalone only)
# - Umbrella handles install itself
# ----------------------------------------------------
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
install(TARGETS vix_cli
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
endif()
message(STATUS "CLI module configured.")
message(STATUS "Executable will be: ${CMAKE_BINARY_DIR}/vix")