-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
executable file
·269 lines (230 loc) · 8.65 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
cmake_minimum_required(VERSION 3.18)
cmake_policy(SET CMP0048 NEW)
# Add include path for cmake modules
# ------ PROJECT EXTRA CMAKE ------
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/")
if(USE_QT)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
endif()
# ------ PROJECT INFO ------
# Options
set(PROJECT_NAME "RestService" CACHE STRING "Project Name")
set(PROJECT_TARGET ${PROJECT_NAME} CACHE STRING "Target Name")
set(PROJECT_VERSION_MAJOR 0)
set(PROJECT_VERSION_MINOR 5)
set(PROJECT_VERSION_PATCH 432)
# ---- Project settings ----
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)
endif()
set(PROJECT_CREATOR "Kambiz Asadzadeh")
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
execute_process(
COMMAND git rev-parse --short HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE PROJECT_VERSION_TAG
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()
if(NOT PROJECT_VERSION_TAG)
set(PROJECT_VERSION_TAG 00000000)
endif()
set(PROJECT_VERSION_TAG_HEX 0x${PROJECT_VERSION_TAG})
set(PROJECT_VERSION_TYPE "pre-alpha")
set(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH} CACHE STRING "Version of ${PROJECT_NAME}")
project(
${PROJECT_NAME}
LANGUAGES CXX
DESCRIPTION "Description of your project."
HOMEPAGE_URL "https://kambizasadzadeh.com"
VERSION ${PROJECT_VERSION}
)
# ------ CROSS-COMPILE CONFIG ------
include(cross-compile)
if(cross-compile)
return()
endif()
set(cross-compile ON)
# ------ PROJECT CONFIG ------
include(color-message)
if(color-message)
return()
endif()
set(color-message ON)
# ------ COMPILER CONFIG ------
include(compiler-options)
if(compiler-options)
return()
endif()
set(compiler-options ON)
# ------ PACKAGES CONFIG ------
include(packages)
if(packages)
return()
endif()
set(packages ON)
SET (PROJECT_LICENSE "MIT")
set(SUFFIX_EXTRA *.in)
set(SUFFIX_HPPHEADER *.hpp)
set(SUFFIX_SOURCE *.cpp)
set(SUFFIX_CONFIG *.json)
if(HAS_USER_INTERFACE)
set(SUFFIX_QML *.qml)
set(SUFFIX_QRC *.qrc)
endif()
file(GLOB PRECOMPILED precompiled/pch.hpp)
file(GLOB HEADERS source/${SUFFIX_HPPHEADER})
file(GLOB SOURCES source/${SUFFIX_SOURCE})
file(GLOB EXAMPLES
source/examples/${SUFFIX_HPPHEADER}
source/examples/${SUFFIX_SOURCE}
)
file(GLOB UTILS
utilities/${SUFFIX_HPPHEADER}
utilities/${SUFFIX_SOURCE}
)
if(HAS_USER_INTERFACE)
file(GLOB UI_SOURCE ui/${SUFFIX_QRC})
endif()
file(GLOB CONFIGFILE config/${SUFFIX_CONFIG})
if(HAS_USER_INTERFACE)
file(GLOB SOURCESFILE
#---C++---
${HEADERS}
${SOURCES}
${UI_SOURCE}
${UTILS}
${CONFIGFILE}
${PRECOMPILED}
${EXAMPLES}
)
source_group("PrecompiledHeaders" FILES ${PRECOMPILED})
source_group("Utilities" FILES ${UTILS})
source_group("Base" FILES ${HEADERS} ${SOURCES})
source_group("UI" FILES ${UI_SOURCE})
source_group("Config" FILES ${CONFIGFILE})
source_group("Examples" FILES ${EXAMPLES})
else()
file(GLOB SOURCESFILE
#---C++---
${HEADERS}
${SOURCES}
${UTILS}
${CONFIGFILE}
${PRECOMPILED}
${EXAMPLES}
)
source_group("PrecompiledHeaders" FILES ${PRECOMPILED})
source_group("Utilities" FILES ${UTILS})
source_group("Base" FILES ${HEADERS} ${SOURCES})
source_group("Config" FILES ${CONFIGFILE})
source_group("Examples" FILES ${EXAMPLES})
endif()
# ------ PROJECT DIRECTORIES ------
set(dir ${CMAKE_CURRENT_SOURCE_DIR}/build/)
set(EXECUTABLE_OUTPUT_PATH ${dir} CACHE PATH "Build directory" FORCE)
set(LIBRARY_OUTPUT_PATH ${dir} CACHE PATH "Build directory" FORCE)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${dir})
set(CMAKE_BUILD_FILES_DIRECTORY ${dir})
set(CMAKE_BUILD_DIRECTORY ${dir})
set(CMAKE_BINARY_DIR ${dir})
SET(EXECUTABLE_OUTPUT_PATH ${dir})
SET(LIBRARY_OUTPUT_PATH ${dir}lib)
SET(CMAKE_CACHEFILE_DIR ${dir})
message("CMAKE_BUILD_FILES_DIRECTORY: " ${CMAKE_BUILD_FILES_DIRECTORY})
# ------ OUTPUTS CONFIG ------
message(STATUS "${BoldRed}------ ${PROJECT_TARGET} Tools Configuration ------${ColourReset}")
message(STATUS "${Bold}Language Standard${ColourReset} : C++[${CMAKE_CXX_STANDARD}]")
message(STATUS "${Bold}Compiler${ColourReset} : ${CMAKE_CXX_COMPILER_ID}")
message(STATUS "${Bold}Compiler Version${ColourReset} : ${CMAKE_CXX_COMPILER_VERSION}")
message(STATUS "${Bold}OS Target${ColourReset} : ${CMAKE_HOST_SYSTEM}")
message(STATUS "${Bold}OS Version${ColourReset} : ${CMAKE_OSX_DEPLOYMENT_TARGET}")
message(STATUS "${Bold}System Architecture${ColourReset} : ${CMAKE_SYSTEM_PROCESSOR}")
message(STATUS "${Bold}Project License${ColourReset} : ${PROJECT_LICENSE}")
message(STATUS "${BoldBlue}------ ${PROJECT_TARGET} Framework Info ------${ColourReset}")
message(STATUS "${Bold}Name${ColourReset} : ${CMAKE_PROJECT_NAME}")
message(STATUS "${Bold}Description${ColourReset} : ${CMAKE_PROJECT_DESCRIPTION}")
message(STATUS "${Bold}Version${ColourReset} : ${CMAKE_PROJECT_VERSION_VERSION}")
message(STATUS "${BoldBlue}------ ${PROJECT_TARGET} Project Configuration ------${ColourReset}")
message(STATUS "${Bold}DEVELOPER${ColourReset} : ${PROJECT_DEVELOPER}")
message(STATUS "${Bold}PROJECT_PROJECT${ColourReset} : ${PROJECT_PROJECT}")
message(STATUS "${Bold}PROJECT_TARGET${ColourReset} : ${PROJECT_TARGET}")
message(STATUS "${Bold}PROJECT_VERSION${ColourReset} : ${PROJECT_VERSION}")
message(STATUS "${Bold}PROJECT_VERSION_TYPE${ColourReset} : ${Underscore}${PROJECT_VERSION_TYPE}${ColourReset}")
message(STATUS "${BoldBlue}------ ${PROJECT_TARGET} Building Configuration ------${ColourReset}")
message(STATUS "${Bold}PROJECT_BUILD_SHARED${ColourReset} : ${PROJECT_BUILD_SHARED}")
message(STATUS "${Bold}PROJECT_VERSION_TAG_HEX${ColourReset} : ${PROJECT_VERSION_TAG_HEX}")
message(STATUS "${Bold}PROJECT_FOLDER_SUFFIX${ColourReset} : ${PROJECT_FOLDER_SUFFIX}")
message(STATUS "${Bold}LIBRARY_OUTPUT_PATH${ColourReset} : ${LIBRARY_OUTPUT_PATH}")
message(STATUS "${Bold}CMAKE_CURRENT_SOURCE_DIR${ColourReset} : ${CMAKE_CURRENT_SOURCE_DIR}")
message(STATUS "${BoldBlue}------ ${PROJECT_TARGET} End Configuration ------${ColourReset}")
if(USE_QT)
#Add an executable to the project using the specified source files.
add_library(${PROJECT_NAME} STATIC ${SOURCESFILE} ${UI_SOURCE})
else()
#Add an executable to the project using the specified source files.
add_library(${PROJECT_NAME} STATIC ${SOURCESFILE})
endif()
if(USE_BOOST)
set(Boost_USE_STATIC_LIBS ON) # only find static libs.
set(Boost_USE_DEBUG_LIBS OFF) # ignore debug libs and.
set(Boost_USE_RELEASE_LIBS ON) # only find release libs.
set(Boost_USE_MULTITHREADED ON) # use multithread mode.
set(Boost_USE_STATIC_RUNTIME OFF) # use static mode at runtime.
target_link_libraries(${PROJECT_NAME} PRIVATE ${Boost_LIBRARIES})
endif()
if(USE_NONE_STL_JSON)
target_link_libraries(${PROJECT_NAME} PRIVATE nlohmann_json::nlohmann_json)
endif()
if(USE_CATCH2)
target_link_libraries(${PROJECT_NAME} PRIVATE Catch2::Catch2)
endif()
if(USE_GOOGLE_TEST)
target_link_libraries(${PROJECT_NAME} PRIVATE gtest)
endif()
if(USE_DOC_TEST)
target_link_libraries(${PROJECT_NAME} PRIVATE doctest)
endif()
if(USE_CURL)
target_link_libraries(${PROJECT_NAME} PRIVATE curl)
endif()
if(USE_OPENSSL)
target_link_libraries(${PROJECT_NAME} PRIVATE crypto ssl)
endif()
if(USE_ZLIB)
target_link_libraries(${PROJECT_NAME} PRIVATE zlib)
endif()
if(USE_BOOST)
target_link_libraries(${PROJECT_NAME} PRIVATE ${Boost_LIBRARIES})
endif()
target_link_libraries(${PROJECT_NAME}
PRIVATE
-lc++
)
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/source PRIVATE source)
target_link_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/source)
if(USE_QT)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core Quick REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Quick REQUIRED)
target_link_libraries(${PROJECT_NAME}
PRIVATE Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Quick
)
if(QT_VERSION_MAJOR EQUAL 6)
qt_import_qml_plugins(${PROJECT_NAME})
qt_finalize_executable(${PROJECT_NAME})
endif()
endif()
#This command generates installation rules for a project.
#Install rules specified by calls to the install() command within a source directory. are executed in order during installation.
install(TARGETS ${PROJECT_NAME} DESTINATION build/bin)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/config/system-config.json DESTINATION ${CMAKE_BINARY_DIR}/config/)
#Ignore unused files.
list(APPEND CPACK_SOURCE_IGNORE_FILES /.git/ /build/ .gitignore .DS_Store)