-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
306 lines (260 loc) · 8.89 KB
/
CMakeLists.txt
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
# Policies <= CMP0180 default to NEW
cmake_minimum_required(VERSION 3.23...3.31 FATAL_ERROR)
list(APPEND CMAKE_MODULE_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/CommonModules"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
)
# Initialize Project Version
# ---
include(TinyHelpers)
include(TinyInitDefaultVariables)
# Initialize Tiny variables, early init.
tiny_init_tiny_variables_pre()
tiny_read_version(TINY_VERSION
TINY_VERSION_MAJOR TINY_VERSION_MINOR TINY_VERSION_PATCH TINY_VERSION_TWEAK
VERSION_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/src/version.hpp"
PREFIX TINYPLAY
HEADER_FOR "${TinyOrmPlayground_ns}"
)
# Basic project and CMake build setup
# ---
project(${TinyOrmPlayground_ns}
DESCRIPTION "Playground for TinyOrm user-friendly ORM"
HOMEPAGE_URL "https://github.com/silverqx/TinyOrmPlayground"
LANGUAGES CXX
VERSION ${TINY_VERSION}
)
# Specify the C++ standard
if(MSVC)
# Make available <format> on MSVC
set(CMAKE_CXX_STANDARD 23)
else()
set(CMAKE_CXX_STANDARD 20)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS OFF)
# Set the AUTOMOC property explicitly only when needed
set(CMAKE_AUTOMOC ON)
# Version requirements
# ---
# Older versions may work, but you are on your own
# Req - requirement, throws error
# Rec - recommended, shows info message
# Compilers
# 16.10/16.11 (1929) to support pragma system_header
set(minReqMsvcVersion 19.29)
set(minRecGCCVersion 10.2)
set(minRecClangVersion 12)
set(minReqClangClVersion 14.0.3)
# Packages
set(minQtVersion 6.2)
# As the range-v3 uses exact version policy in the package config file so passing version
# makes real problems on CI pipelines where different OS images can have installed
# different versions of range-v3 (doesn't matter if it's vcpkg or some package manager)
#set(minRangeV3Version 0.12.0)
set(minNlohmannJsonVersion 3.9.1)
set(minTinyOrmVersion 0.37.3)
# tabulate doesn't provide Package Version File
#set(minTabulateVersion 1.5.0)
# Make minimum toolchain version a requirement
include(TinyToolchainRequirement)
tiny_toolchain_requirement(
MSVC ${minReqMsvcVersion}
CLANG_CL ${minReqClangClVersion}
GCC ${minRecGCCVersion}
CLANG ${minRecClangVersion}
QT ${minReqQtVersion}
)
# TinyORM build options
# ---
include(FeatureSummary)
include(TinyFeatureOptions)
feature_option(BUILD_SHARED_LIBS
"Build using shared libraries" ON
)
feature_option_dependent(MSVC_RUNTIME_DYNAMIC
"Use MSVC dynamic runtime library (-MD) instead of static (-MT), also considers \
a Debug configuration (-MTd, -MDd)" ON
"MSVC AND NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY" MSVC_RUNTIME_DYNAMIC-NOTFOUND
)
feature_option(VERBOSE_CONFIGURE
"Show information about PACKAGES_FOUND and PACKAGES_NOT_FOUND in the configure \
output" OFF
)
# MSVC_PARALLEL option
include(TinyMsvcParallel)
tiny_msvc_parallel("\
Enables /MP flag for parallel builds using MSVC. Specify an \
integer value to control the number of threads used (Only \
works on some older versions of Visual Studio). Setting to \
ON lets the toolchain decide how many threads to use. Set to \
OFF to disable /MP completely.")
# Initialize Tiny and default CMake variables
tiny_init_cmake_variables()
tiny_init_tiny_variables()
# Throw a fatal error for unsupported environments
tiny_check_unsupported_build()
# TinyOrmPlayground executable header and source files
# ---
include(TinySources)
tiny_sources(${TinyOrmPlayground_target}_headers ${TinyOrmPlayground_target}_sources)
add_executable(${TinyOrmPlayground_target}
${${TinyOrmPlayground_target}_headers}
${${TinyOrmPlayground_target}_sources}
)
add_executable(${TinyOrmPlayground_ns}::${TinyOrmPlayground_target}
ALIAS ${TinyOrmPlayground_target}
)
# Use Precompiled headers (PCH)
# ---
target_precompile_headers(${TinyOrmPlayground_target}
PRIVATE $<$<COMPILE_LANGUAGE:CXX>:"pch.h">
)
if(NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)
target_compile_definitions(${TinyOrmPlayground_target} PRIVATE TINYPLAY_USING_PCH)
endif()
# TinyOrmPlayground specific configuration
# ---
set_target_properties(${TinyOrmPlayground_target}
PROPERTIES
C_VISIBILITY_PRESET "hidden"
CXX_VISIBILITY_PRESET "hidden"
VISIBILITY_INLINES_HIDDEN YES
VERSION ${PROJECT_VERSION}
# Append a major version number after the executable
OUTPUT_NAME "${TinyOrmPlayground_target}${PROJECT_VERSION_MAJOR}"
DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}
)
target_include_directories(${TinyOrmPlayground_target} PRIVATE
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>"
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/models>"
)
# TinyOrmPlayground compiler options
# ---
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_compile_options(${TinyOrmPlayground_target} PRIVATE /bigobj)
endif()
if(MINGW)
target_compile_options(${TinyOrmPlayground_target}
PRIVATE
$<$<CONFIG:DEBUG>:-Wa,-mbig-obj>
# Avoid a string table overflow
$<$<CONFIG:DEBUG>:-O1>
)
endif()
# TinyOrmPlayground defines
# ---
target_compile_definitions(${TinyOrmPlayground_target}
PRIVATE
PROJECT_TINYORMPLAYGROUND
# Release build
$<$<NOT:$<CONFIG:Debug>>:QT_NO_DEBUG_OUTPUT>
$<$<NOT:$<CONFIG:Debug>>:TINYPLAY_NO_DEBUG>
# Debug build
$<$<CONFIG:Debug>:TINYPLAY_DEBUG>
)
# TinyORM defines
# ---
if(BUILD_SHARED_LIBS)
target_compile_definitions(${TinyOrmPlayground_target}
PRIVATE TINYORM_LINKING_SHARED
)
endif()
# Windows resource and manifest files
# ---
# Find Windows manifest file
if(MINGW)
tiny_set_rc_flags("-I \"${CMAKE_CURRENT_SOURCE_DIR}/resources\"")
endif()
include(TinyResourceAndManifest)
tiny_resource_and_manifest(${TinyOrmPlayground_target}
OUTPUT_DIR "${TINY_BUILD_GENDIR}/tmp/"
)
# Resolve and link dependencies
# ---
# Unconditional dependencies
find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core #[[Network]] Sql)
tiny_find_package(Qt${QT_VERSION_MAJOR} ${minQtVersion} CONFIG
REQUIRED COMPONENTS Core #[[Network]] Sql
)
tiny_find_package(range-v3 CONFIG REQUIRED)
tiny_find_package(nlohmann_json ${minNlohmannJsonVersion} CONFIG REQUIRED)
tiny_find_package(TinyOrm ${minTinyOrmVersion} CONFIG REQUIRED)
target_link_libraries(${TinyOrmPlayground_target}
PRIVATE
Qt${QT_VERSION_MAJOR}::Core
# Qt${QT_VERSION_MAJOR}::Network
Qt${QT_VERSION_MAJOR}::Sql
range-v3::range-v3
nlohmann_json::nlohmann_json
TinyOrm::TinyOrm
)
# Default rules for deployment
# ---
# Some info output
# ---
tiny_print_linking_against(TinyOrm::TinyOrm)
set_package_properties(QT
PROPERTIES
URL "https://doc.qt.io/qt-${QT_VERSION_MAJOR}/"
DESCRIPTION "Qt is a full development framework"
TYPE REQUIRED
PURPOSE "Provides SQL database layer by the QtSql module, QVariant, and QString"
)
set_package_properties(Qt${QT_VERSION_MAJOR}
PROPERTIES
URL "https://doc.qt.io/qt-${QT_VERSION_MAJOR}/"
DESCRIPTION "Qt is a full development framework"
TYPE REQUIRED
PURPOSE "Provides SQL database layer by the QtSql module, QVariant, and QString"
)
set_package_properties(Qt${QT_VERSION_MAJOR}Core
PROPERTIES
URL "https://doc.qt.io/qt-${QT_VERSION_MAJOR}/qtcore-index.html"
DESCRIPTION "Core non-graphical classes used by other modules"
TYPE REQUIRED
PURPOSE "Provides QVariant, QString, and Qt containers"
)
#set_package_properties(Qt${QT_VERSION_MAJOR}Network
# PROPERTIES
# URL "https://doc.qt.io/qt-${QT_VERSION_MAJOR}/qtnetwork-index.html"
# DESCRIPTION "Classes to make network programming easier and more portable"
# TYPE REQUIRED
# PURPOSE "Provides QHostInfo (for now unused)"
#)
set_package_properties(Qt${QT_VERSION_MAJOR}Sql
PROPERTIES
URL "https://doc.qt.io/qt-${QT_VERSION_MAJOR}/qtsql-index.html"
DESCRIPTION "Classes for database integration using SQL"
TYPE REQUIRED
PURPOSE "Provides SQL database layer"
)
set_package_properties(range-v3
PROPERTIES
URL "https://ericniebler.github.io/range-v3/"
DESCRIPTION "Range algorithms, views, and actions for STL"
TYPE REQUIRED
PURPOSE "Used to have a nice and clear code"
)
set_package_properties(nlohmann_json
PROPERTIES
URL "https://json.nlohmann.me/"
DESCRIPTION "JSON for Modern C++"
TYPE REQUIRED
PURPOSE "In fact, it is not used, only tried in some example code"
)
set_package_properties(TinyOrm
PROPERTIES
URL "https://silverqx.github.io/TinyORM/"
DESCRIPTION "c++ ORM library for Qt framework"
TYPE REQUIRED
PURPOSE "An ORM framework for which is this playground for"
)
if(VERBOSE_CONFIGURE)
if(NOT TINY_IS_MULTI_CONFIG AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
message(STATUS "Disabled debug output and asserts")
endif()
feature_summary(WHAT ALL)
else()
feature_summary(WHAT ENABLED_FEATURES DISABLED_FEATURES)
endif()