-
Notifications
You must be signed in to change notification settings - Fork 119
/
user.cmake
295 lines (262 loc) · 14.8 KB
/
user.cmake
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
# ###########################################################################
# User specific settings
# Copyright 2022-2023 Aregtech
# ###########################################################################
# ---------------------------------------------------------------------------
# This CMake file allows configuration of various AREG Framework build options.
# You can pass these options via the command line, or the system will use default values.
#
# Available Options:
# 1. AREG_COMPILER_FAMILY -- A quick way to set the C++ and C compilers (CMAKE_CXX_COMPILER and CMAKE_C_COMPILER).
# 2. AREG_COMPILER -- Sets a specific compiler for both C++ and C projects.
# 3. AREG_PROCESSOR -- The processor architect. Ignore if need to use system default.
# 4. AREG_BINARY -- Specifies the library type for the AREG Framework ('shared' or 'static'). Defaults to 'shared'.
# 5. AREG_LOGGER_LIB -- Specifies the type of the Log Observer API library ('shared' or 'static'). Defaults to 'shared'.
# 6. AREG_BUILD_TYPE -- Specifies the build configuration ('Debug' or 'Release').
# 7. AREG_BUILD_TESTS -- Enables or disables building unit tests for the AREG Framework.
# 8. AREG_BUILD_EXAMPLES -- Enables or disables building examples for the AREG Framework.
# 9. AREG_EXTENDED -- Enables or disables extended AREG Framework features. May require additional dependencies.
# 10. AREG_LOGS -- Enables or disables logging during compilation. Defaults to 'enabled'.
# 11. AREG_USE_PACKAGES -- Enables or disables using installed packages. Controls other package options like SQLite and GTest.
# 12. AREG_SQLITE_PACKAGE -- Determines if the system's SQLite3 package should be used or compiled from source.
# 13. AREG_GTEST_PACKAGE -- Determines if the system's GTest package should be used or compiled from source.
# 14. AREG_ENABLE_OUTPUTS -- If disabled, output directories will match the CMake binary directory.
# 15. AREG_BUILD_ROOT -- Specifies the root directory for build files. Defaults to './product' within the AREG SDK root.
# 16. AREG_OUTPUT_DIR -- Directory where build outputs are placed.
# 17. AREG_OUTPUT_BIN -- Directory for output binaries (executables and shared libraries).
# 18. AREG_OUTPUT_LIB -- Directory for output static libraries.
# 19. AREG_PACKAGES -- Location for fetching third-party packages such as GTest.
# 20. AREG_INSTALL -- Enables or disables installation of AREG SDK binaries, headers and dependencies like 'sqlite3' and 'ncurses'.
# 21. AREG_INSTALL_PATH -- Location where AREG SDK binaries, headers, and tools are installed. Defaults to the user's home directory.
#
# Default Values:
# 1. AREG_COMPILER_FAMILY = <default> (possible values: gnu, cygwin, llvm, msvc)
# 2. AREG_COMPILER = <default> (possible values: g++, gcc, c++, cc, clang++, clang, clang-cl, cl)
# 3. AREG_PROCESSOR = System (possible values: x86, x64 (x86_64, amd64), arm (arm32), aarch64 (arm64))
# 4. AREG_BINARY = shared (possible values: shared, static)
# 5. AREG_LOGGER_LIB = shared (possible values: shared, static)
# 6. AREG_BUILD_TYPE = Release (possible values: Release, Debug)
# 7. AREG_BUILD_TESTS = ON (possible values: ON, OFF)
# 8. AREG_BUILD_EXAMPLES = ON (possible values: ON, OFF)
# 9. AREG_EXTENDED = OFF (possible values: ON, OFF)
# 10. AREG_LOGS = ON (possible values: ON, OFF)
# 11. AREG_USE_PACKAGES = ON (possible values: ON, OFF)
# 12. AREG_SQLITE_PACKAGE = ON (possible values: ON, OFF)
# 13. AREG_GTEST_PACKAGE = ON (possible values: ON, OFF)
# 14. AREG_ENABLE_OUTPUTS = ON (possible values: ON, OFF)
# 15. AREG_BUILD_ROOT = '<areg-sdk>/product' (path for output and generated files)
# 16. AREG_OUTPUT_DIR = '<areg-sdk>/product/build/<default-compiler family-name>/<os>-<bitness>-<cpu>-release-<areg-lib>'
# 17. AREG_OUTPUT_BIN = '<areg-sdk>/product/build/<default-compiler family-name>/<os>-<bitness>-<cpu>-release-<areg-lib>/bin'
# 18. AREG_OUTPUT_LIB = '<areg-sdk>/product/build/<default-compiler family-name>/<os>-<bitness>-<cpu>-release-<areg-lib>/lib'
# 19. AREG_PACKAGES = '${AREG_BUILD_ROOT}/packages'
# 20. AREG_INSTALL = ON (possible values: ON, OFF)
# 21. AREG_INSTALL_PATH = '${HOME}/areg-sdk' (or '${USERPROFILE}' on Windows, defaults to current directory if unset)
#
# Hints:
# - AREG_COMPILER_FAMILY is an easy way to set compilers:
# - 'gnu' sets g++ and gcc for C++ and C.
# - 'cygwin' sets g++ and gcc for C++ and C under Cygwin.
# - 'llvm' sets clang++, clang, and clang-cl (on Windows) for C++ and C.
# - 'msvc' sets Microsoft Visual C++ (cl) for C++ and C.
#
# Example Command:
# $ cmake -B ./build -DCMAKE_BUILD_TYPE=Debug -DAREG_COMPILER_FAMILY=llvm -DAREG_BUILD_TESTS=ON -DAREG_BUILD_EXAMPLES=ON
#
# Notes:
# - To integrate manually build binaries of AREG SDK into another project, you can simply set `AREG_BUILD_ROOT` to the project's root directory.
#
# Example Command with AREG_BUILD_ROOT to output binaries in custom directory:
# $ cmake -B ./build -DAREG_BUILD_ROOT="/home/developer/projects/my_project/product"
#
# Integration:
# - Visit https://github.com/aregtech/areg-sdk-demo repository to see various ways of AREG Framework integration.
# ---------------------------------------------------------------------------
# Set variables for C++ and C compilers and their short name
set(AREG_CXX_COMPILER)
set(AREG_C_COMPILER)
set(AREG_COMPILER_SHORT)
# Specify CPU platform here, the system CPU platform is detected in 'commmon.cmake'
if (DEFINED AREG_PROCESSOR)
if (AREG_PROCESSOR STREQUAL "x86")
set(CMAKE_SYSTEM_PROCESSOR x86)
set(AREG_BITNESS 32)
elseif(AREG_PROCESSOR STREQUAL "x64" OR AREG_PROCESSOR STREQUAL "x86_64" OR AREG_PROCESSOR STREQUAL "amd64")
set(CMAKE_SYSTEM_PROCESSOR x86_64)
set(AREG_PROCESSOR x64)
set(AREG_BITNESS 64)
elseif (AREG_PROCESSOR STREQUAL "arm" OR AREG_PROCESSOR STREQUAL "arm32")
set(CMAKE_SYSTEM_PROCESSOR ARM)
set(AREG_PROCESSOR arm)
set(AREG_BITNESS 32)
elseif (AREG_PROCESSOR STREQUAL "aarch64" OR AREG_PROCESSOR STREQUAL "arm64")
set(CMAKE_SYSTEM_PROCESSOR AARCH64)
set(AREG_PROCESSOR aarch64)
set(AREG_BITNESS 64)
else()
set(CMAKE_SYSTEM_PROCESSOR ${AREG_PROCESSOR})
if (NOT DEFINED AREG_BITNESS)
macro_system_bitness(AREG_BITNESS)
endif()
endif()
elseif(NOT DEFINED AREG_BITNESS)
macro_system_bitness(AREG_BITNESS)
endif()
# If CMake compilers are specified, use them
if ((DEFINED CMAKE_CXX_COMPILER OR DEFINED CMAKE_C_COMPILER) AND (NOT "${CMAKE_CXX_COMPILER}" STREQUAL "" OR NOT "${CMAKE_C_COMPILER}" STREQUAL ""))
# Determine the system compiler based on the available CMake variables
if (DEFINED CMAKE_CXX_COMPILER AND NOT "${CMAKE_CXX_COMPILER}" STREQUAL "")
set(_sys_compiler "${CMAKE_CXX_COMPILER}")
else()
set(_sys_compiler "${CMAKE_C_COMPILER}")
endif()
message(STATUS "AREG: >>> Using CMake specified C++ compiler '${_sys_compiler}'")
# Setup compiler details based on the identified system compiler
macro_setup_compilers_data("${_sys_compiler}" _compiler_family _compiler_short _cxx_compiler _c_compiler _sys_process _sys_bitness _compiler_found)
if (_compiler_found)
# Check for existing compiler family or specific compiler and issue warnings if necessary
if (DEFINED AREG_COMPILER_FAMILY AND NOT "${AREG_COMPILER_FAMILY}" STREQUAL "" AND NOT "${AREG_COMPILER_FAMILY}" STREQUAL "${_compiler_family}")
message(WARNING "AREG: Selected compiler family '${AREG_COMPILER_FAMILY}' is ignored; using '${_compiler_family}'")
endif()
# Only if AREG_COMPILER is defined, compare the short compiler name to the full path
if (DEFINED AREG_COMPILER AND NOT "${AREG_COMPILER}" STREQUAL "")
string(FIND "${AREG_COMPILER}" "${_compiler_short}" _found_pos)
if (_found_pos LESS 0)
message(WARNING "AREG: Selected compiler '${AREG_COMPILER}' is ignored; using '${_compiler_short}'")
endif()
endif()
# Set the relevant variables for the compiler
set(AREG_COMPILER_FAMILY "${_compiler_family}")
set(AREG_COMPILER "${_sys_compiler}")
set(AREG_COMPILER_SHORT "${_compiler_short}")
set(AREG_CXX_COMPILER "${_sys_compiler}")
set(AREG_C_COMPILER "${_c_compiler}")
if (NOT "${_sys_process}" STREQUAL "")
set(AREG_PROCESSOR ${_sys_process})
set(AREG_BITNESS ${_sys_bitness})
set(CMAKE_SYSTEM_PROCESSOR ${AREG_PROCESSOR})
endif()
else()
message(WARNING "AREG: Unknown C++ compiler '${_sys_compiler}'; results may be unpredictable")
endif()
unset(_sys_compiler)
unset(_sys_process)
unset(_sys_bitness)
# If a specific compiler family is set, use that to determine compilers
elseif (DEFINED AREG_COMPILER_FAMILY AND NOT "${AREG_COMPILER_FAMILY}" STREQUAL "")
message(STATUS "AREG: >>> Using user-specified C/C++ compiler family '${AREG_COMPILER_FAMILY}'")
macro_setup_compilers_data_by_family("${AREG_COMPILER_FAMILY}" _compiler_short _cxx_compiler _c_compiler _compiler_found)
if (_compiler_found)
# Set the relevant variables for the chosen compiler family
set(AREG_COMPILER "${_cxx_compiler}")
set(AREG_COMPILER_SHORT "${_compiler_short}")
set(AREG_CXX_COMPILER "${_cxx_compiler}")
set(AREG_C_COMPILER "${_c_compiler}")
else()
message(WARNING "AREG: Unknown compiler family '${AREG_COMPILER_FAMILY}'; results may be unpredictable")
endif()
# If a specific compiler is set, use that to determine compilers
elseif (DEFINED AREG_COMPILER AND NOT "${AREG_COMPILER}" STREQUAL "")
message(STATUS "AREG: >>> Using user-specified C/C++ compiler '${AREG_COMPILER}'")
# Set both C and C++ compilers based on AREG_COMPILER
macro_setup_compilers_data("${AREG_COMPILER}" _compiler_family _compiler_short _cxx_compiler _c_compiler _sys_process _sys_bitness _compiler_found)
if (_compiler_found)
# Set the relevant variables for the chosen compiler
set(AREG_COMPILER_FAMILY "${_compiler_family}")
set(AREG_COMPILER_SHORT "${_compiler_short}")
set(AREG_CXX_COMPILER "${_cxx_compiler}")
set(AREG_C_COMPILER "${_c_compiler}")
if (NOT "${_sys_process}" STREQUAL "")
set(AREG_PROCESSOR ${_sys_process})
set(AREG_BITNESS ${_sys_bitness})
set(CMAKE_SYSTEM_PROCESSOR ${AREG_PROCESSOR})
endif()
else()
message(WARNING "AREG: Unknown compiler '${AREG_COMPILER}'; results may be unpredictable")
endif()
unset(_sys_compiler)
unset(_sys_process)
unset(_sys_bitness)
# If no specific compiler or family is set, use the system default
else()
message(STATUS "AREG: >>> No compiler specified; using system default compilers.")
endif()
# Set build configuration. Set "Debug" for debug build, and "Release" for release build.
if (NOT DEFINED AREG_BUILD_TYPE OR "${AREG_BUILD_TYPE}" STREQUAL "")
if (NOT DEFINED CMAKE_BUILD_TYPE OR "${CMAKE_BUILD_TYPE}" STREQUAL "")
set(AREG_BUILD_TYPE "Release")
else()
set(AREG_BUILD_TYPE "${CMAKE_BUILD_TYPE}")
endif()
endif()
# Set the AREG binary library type to compile. Set "shared" if not "static"
if (NOT DEFINED AREG_BINARY)
if (DEFINED VCPKG_LIBRARY_LINKAGE AND "${VCPKG_LIBRARY_LINKAGE}" STREQUAL "static")
set(AREG_BINARY "static")
else()
set(AREG_BINARY "shared")
endif()
elseif (NOT "${AREG_BINARY}" STREQUAL "static")
set(AREG_BINARY "shared")
endif()
# Set the areg log observer API library type.
if (NOT DEFINED AREG_LOGGER_LIB)
if (DEFINED VCPKG_LIBRARY_LINKAGE AND "${VCPKG_LIBRARY_LINKAGE}" STREQUAL "static")
set(AREG_LOGGER_LIB "static")
else()
set(AREG_LOGGER_LIB "shared")
endif()
elseif (NOT "${AREG_LOGGER_LIB}" STREQUAL "static")
set(AREG_LOGGER_LIB "shared")
endif()
# Build tests. By default it is disabled. To enable, set ON
macro_create_option(AREG_BUILD_TESTS ON "Build unit tests")
# Build examples. By default it is disabled. To enable, set ON
macro_create_option(AREG_BUILD_EXAMPLES ON "Build examples")
# Set AREG extended features enable or disable flag to compiler additional optional features. By default, it is disabled.
macro_create_option(AREG_EXTENDED OFF "Enable extended feature")
# Modify 'AREG_LOGS' to enable or disable compilation with logs. By default, compile with logs
macro_create_option(AREG_LOGS ON "Compile with logs")
# Modify 'AREG_INSTALL' to enable or disable installation of AREG SDK
macro_create_option(AREG_INSTALL ON "Enable installation")
# Check the request of using installed packages
if (NOT DEFINED AREG_USE_PACKAGES)
# Set default values
macro_create_option(AREG_USE_PACKAGES ON "Enable using installed packages")
macro_create_option(AREG_SQLITE_PACKAGE ON "Use SQLite3 installed package")
macro_create_option(AREG_GTEST_PACKAGE ON "Use GTest installed package")
elseif(AREG_USE_PACKAGES)
# Using packages is enabled by default, set values
macro_create_option(AREG_USE_PACKAGES ON "Enable using installed packages")
macro_create_option(AREG_SQLITE_PACKAGE ON "Use SQLite3 installed package")
macro_create_option(AREG_GTEST_PACKAGE ON "Use GTest installed package")
else()
# Using packages is disabled by default, set values
macro_create_option(AREG_USE_PACKAGES OFF "Enable using installed packages")
macro_create_option(AREG_SQLITE_PACKAGE OFF "Use SQLite3 installed package")
macro_create_option(AREG_GTEST_PACKAGE OFF "Use GTest installed package")
macro_create_option(AREG_INSTALL OFF "Enable installation")
endif()
# CPP standard for the projects
set(AREG_CXX_STANDARD 17)
if (NOT DEFINED AREG_ENABLE_OUTPUTS OR AREG_ENABLE_OUTPUTS)
option(AREG_ENABLE_OUTPUTS "Enable changing output directories" TRUE)
# Set the areg-sdk build root folder to output files.
if (NOT DEFINED AREG_BUILD_ROOT OR "${AREG_BUILD_ROOT}" STREQUAL "")
set(AREG_BUILD_ROOT "${AREG_SDK_ROOT}/product")
endif()
if (NOT DEFINED AREG_PACKAGES OR "${AREG_PACKAGES}" STREQUAL "")
set(AREG_PACKAGES "${AREG_BUILD_ROOT}/packages")
endif()
else()
option(AREG_ENABLE_OUTPUTS "Enable changing output directories" FALSE)
if (NOT DEFINED AREG_BUILD_ROOT OR "${AREG_BUILD_ROOT}" STREQUAL "")
set(AREG_BUILD_ROOT "${CMAKE_BINARY_DIR}")
endif()
endif()
# The relative path for generated files
if ("${AREG_GENERATE}" STREQUAL "")
set(AREG_GENERATE "generate")
endif()
if ("${AREG_GENERATE_DIR}" STREQUAL "")
set(AREG_GENERATE_DIR "${AREG_BUILD_ROOT}/${AREG_GENERATE}")
endif()