forked from Project-LemonLime/Project_LemonLime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
313 lines (254 loc) · 10.5 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
307
308
309
310
311
312
313
cmake_minimum_required(VERSION 3.16.0)
project(lemon LANGUAGES CXX)
## Add paths to check for cmake modules:
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
# ==================================================================================
# CMake Macros
# ==================================================================================
include(FeatureSummary)
macro(LEMONLOG MSG)
set(LEMON_BUILD_STATS "${LEMON_BUILD_STATS}${MSG}: ${${MSG}}\r\n")
endmacro()
option(EMBED_TRANSLATIONS "Embed translations" ON)
LEMONLOG(EMBED_TRANSLATIONS)
option(EMBED_DOCS "Embed documents" ON)
LEMONLOG(EMBED_DOCS)
option(ENABLE_XLS_EXPORT "XLS Result Export Support (Windows Only)" OFF)
LEMONLOG(ENABLE_XLS_EXPORT)
option(BUILD_DEB "Build deb format package" OFF)
LEMONLOG(BUILD_DEB)
option(BUILD_RPM "Build rpm format package" OFF)
LEMONLOG(BUILD_RPM)
option(ENABLE_LTO "Link-Time Optimization" ON)
LEMONLOG(ENABLE_LTO)
option(ENABLE_CCACHE "Ccache speed up compile (Only support Makefile and Ninja now)" OFF)
LEMONLOG(ENABLE_CCACHE)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC_SEARCH_PATHS ${CMAKE_SOURCE_DIR}/src/forms)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
option(LEMON_QT6 "Use Qt6 for Debugging" OFF)
LEMONLOG(LEMON_QT6)
if(LEMON_QT6)
cmake_policy(SET CMP0072 NEW)
set(LEMON_QT_MAJOR_VERSION 6)
set(LEMON_QT_MINOR_VERSION 0)
set(LEMON_QT_LIBNAME Qt6)
set(QT_MAJOR_VERSION 6)
set(QT_DEFAULT_MAJOR_VERSION 6)
set(Qt_DIR ${Qt6_DIR})
add_definitions(-DLEMON_QT6)
else()
set(LEMON_QT_MAJOR_VERSION 5)
set(LEMON_QT_MINOR_VERSION 15)
set(LEMON_QT_LIBNAME Qt5)
set(QT_MAJOR_VERSION 5)
set(Qt_DIR ${Qt5_DIR})
endif()
add_definitions(-DQT_NO_FOREACH)
find_package(${LEMON_QT_LIBNAME} ${LEMON_QT_MAJOR_VERSION}.${LEMON_QT_MINOR_VERSION} COMPONENTS Core Gui Widgets REQUIRED)
list(APPEND LEMON_QT_LIBS ${LEMON_QT_LIBNAME}::Core ${LEMON_QT_LIBNAME}::Gui ${LEMON_QT_LIBNAME}::Widgets)
set(SINGLEAPPLICATION_DIR ${CMAKE_SOURCE_DIR}/3rdparty/SingleApplication)
set(QAPPLICATION_CLASS QApplication CACHE STRING "Inheritance class for SingleApplication")
add_subdirectory(3rdparty/SingleApplication)
if(WIN32)
add_compile_options("/std:c++17")
add_compile_definitions(UNICODE _UNICODE)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
set(GUI_TYPE WIN32)
endif()
if(UNIX AND NOT APPLE)
find_program(LSB_RELEASE_EXEC lsb_release)
execute_process(COMMAND ${LSB_RELEASE_EXEC} -is
OUTPUT_VARIABLE LSB_RELEASE_ID_SHORT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()
LEMONLOG(LSB_RELEASE_ID_SHORT)
if(ENABLE_CCACHE)
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM AND UNIX)
set(C_LAUNCHER "${CCACHE_PROGRAM}")
set(CXX_LAUNCHER "${CCACHE_PROGRAM}")
if(CMAKE_GENERATOR STREQUAL "Xcode")
message(STATUS "Ccache not supported by XCode, disabled")
endif()
endif()
endif()
# ==================================================================================
# Lemon Build Info
# ==================================================================================
file(STRINGS "${CMAKE_SOURCE_DIR}/makespec/VERSION" VERSION)
file(STRINGS "${CMAKE_SOURCE_DIR}/makespec/BUILDVERSION" BUILD_VERSION)
file(STRINGS "${CMAKE_SOURCE_DIR}/makespec/VERSIONSUFFIX" VERSION_SUFFIX)
set(VERSION_STRING "${VERSION}${VERSION_SUFFIX}")
set(VERSION_LIST ${VERSION})
string(REPLACE "." ";" VERSION_LIST ${VERSION_LIST})
separate_arguments(VERSION_LIST)
list(GET VERSION_LIST 0 CMAKE_PROJECT_VERSION_MAJOR)
list(GET VERSION_LIST 1 CMAKE_PROJECT_VERSION_MINOR)
list(GET VERSION_LIST 2 CPACK_PACKAGE_VERSION_PATCH)
add_definitions(-DLEMON_VERSION_MAJOR=${CMAKE_PROJECT_VERSION_MAJOR})
add_definitions(-DLEMON_VERSION_MINOR=${CMAKE_PROJECT_VERSION_MINOR})
add_definitions(-DLEMON_VERSION_BUGFIX=${CPACK_PACKAGE_VERSION_PATCH})
add_definitions(-DLEMON_VERSION_BUILD=${BUILD_VERSION})
add_definitions(-DLEMON_VERSION_STRING="${VERSION_STRING}")
message(" ")
message("LemonLime Version: ${VERSION_STRING}")
message("LemonLime Build Version: ${BUILD_VERSION}")
message("LemonLime Build Type: ${CMAKE_BUILD_TYPE}")
message("|----------------------------------------------------------------|")
message("| LemonLime, |")
message("| A tiny judging environment for OI contest. |")
message("| Based on C++ & Qt. |")
message("| Licenced under GPLv3 |")
message("| |")
message("|----------------------------------------------------------------|")
message("| GitHub: https://github.com/Project-LemonLime/Project_LemonLime |")
message("| Welcome to contribute! |")
message("|----------------------------------------------------------------|")
message(" ")
if(LEMON_BUILD_INFO)
set(_LEMON_BUILD_INFO_STR_ "${LEMON_BUILD_INFO}")
elseif(DEFINED ENV{_LEMON_BUILD_INFO_})
set(_LEMON_BUILD_INFO_STR_ "$ENV{_LEMON_BUILD_INFO_}")
else()
set(_LEMON_BUILD_INFO_STR_ "LemonLime from manual build")
endif()
if(LEMON_BUILD_EXTRA_INFO)
set(_LEMON_BUILD_EXTRA_INFO_STR_ "${LEMON_BUILD_EXTRA_INFO}")
elseif(DEFINED ENV{_LEMON_BUILD_EXTRA_INFO_})
set(_LEMON_BUILD_EXTRA_INFO_STR_ "$ENV{_LEMON_BUILD_EXTRA_INFO_}")
else()
set(_LEMON_BUILD_EXTRA_INFO_STR_ "LemonLime ${VERSION_STRING}:${BUILD_VERSION}")
endif()
set(LEMON_BUILD_INFO ${_LEMON_BUILD_INFO_STR_})
set(LEMON_BUILD_EXTRA_INFO ${_LEMON_BUILD_EXTRA_INFO_STR_})
add_definitions(-DLEMON_BUILD_INFO_STR="${_LEMON_BUILD_INFO_STR_}")
add_definitions(-DLEMON_BUILD_EXTRA_INFO_STR="${_LEMON_BUILD_EXTRA_INFO_STR_}")
message("LemonLime build info: ${_LEMON_BUILD_INFO_STR_}")
message("LemonLime build info extra: ${_LEMON_BUILD_EXTRA_INFO_STR_}")
if(LEMON_CONFIG_DIR)
add_definitions(-DLEMON_CONFIG_DIR="${LEMON_CONFIG_DIR}")
LEMONLOG(LEMON_CONFIG_DIR)
endif()
# ==================================================================================
# Lemon Base && Core
# ==================================================================================
include(cmake/lemon-base.cmake)
include(cmake/lemon-core.cmake)
# ==================================================================================
# Lemon Documents
# ==================================================================================
include(cmake/LemonDocs.cmake)
# ==================================================================================
# Lemon UI
# ==================================================================================
include(cmake/lemon-ui.cmake)
# ==================================================================================
# Lemon Translations
# ==================================================================================
include(cmake/LemonTranslations.cmake)
if(EMBED_TRANSLATIONS)
add_definitions(-DLEMON_EMBED_TRANSLATIONS)
configure_file(translations/translations.qrc ${CMAKE_BINARY_DIR} COPYONLY)
set(LEMON_EMBED_TRANSLATION_QRC ${CMAKE_BINARY_DIR}/translations.qrc)
endif()
# Qt language translations
add_custom_target(lupdate
COMMAND ${Qt_DIR}/../../../bin/lupdate
${LEMON_BASE_SOURCES}
${LEMON_CORE_SOURCES}
${LEMON_UI_SOURCES}
${LEMON_UI_FORMS}
${SINGLEAPPLICATION_SOURCES} -ts ${TRANSLATIONS_TS} -locations none -noobsolete
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
set_target_properties(lupdate PROPERTIES EXCLUDE_FROM_ALL TRUE)
# ==================================================================================
# Lemon Build
# ==================================================================================
set(QRC_RESOURCES
resource.qrc
${LEMON_EMBED_DOC_QRC}
)
set(LEMON_FULL_SOURCES
${LEMON_BASE_SOURCES}
${LEMON_CORE_SOURCES}
${LEMON_UI_SOURCES}
assets/lemon.rc
${LEMON_UI_FORMS}
${LEMON_UI_RESOURCES}
${SINGLEAPPLICATION_SOURCES}
${LEMON_EMBED_TRANSLATION_QRC}
${QRC_RESOURCES}
${QM_FILES}
)
# Set Apple MacOS Specific settings
if(APPLE)
set(GUI_TYPE MACOSX_BUNDLE)
endif()
if(WIN32)
add_executable(lemon ${GUI_TYPE} ${LEMON_FULL_SOURCES})
else()
if(APPLE)
add_executable(watcher_unix unix/watcher_macos.cpp)
else()
add_executable(watcher_unix unix/watcher_linux.cpp)
endif()
configure_file(unix/watcher.qrc ${CMAKE_BINARY_DIR} COPYONLY)
list(APPEND LEMON_FULL_SOURCES ${CMAKE_BINARY_DIR}/watcher.qrc)
add_executable(lemon ${GUI_TYPE} ${LEMON_FULL_SOURCES})
add_dependencies(lemon watcher_unix)
endif()
target_include_directories(lemon PUBLIC ${CMAKE_SOURCE_DIR}/src)
if(WIN32 AND ENABLE_XLS_EXPORT)
find_package(${LEMON_QT_LIBNAME} COMPONENTS AxContainer REQUIRED)
list(APPEND LEMON_QT_LIBS ${LEMON_QT_LIBNAME}::AxContainer)
add_definitions(-DENABLE_XLS_EXPORT)
endif()
target_precompile_headers(lemon PUBLIC ${CMAKE_SOURCE_DIR}/src/pch.h)
target_link_libraries(lemon PRIVATE ${LEMON_QT_LIBS} lemon-core lemon-base SingleApplication::SingleApplication)
if(WIN32 AND NOT LEMON_QT6)
target_link_libraries(lemon PRIVATE userenv)
endif()
if(ENABLE_LTO)
include(CheckIPOSupported)
check_ipo_supported(RESULT LTO_SUPPORTED OUTPUT error)
if(LTO_SUPPORTED)
set_property(TARGET lemon PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(STATUS "IPO / LTO not supported, disabled")
endif()
endif()
# ==================================================================================
# Platform-dependent installation process and deployment
# ==================================================================================
if(APPLE)
include(cmake/platforms/macos.cmake)
elseif(UNIX AND NOT APPLE AND NOT WIN32)
include(cmake/platforms/linux.cmake)
elseif(WIN32)
include(cmake/platforms/windows.cmake)
endif()
# ==================================================================================
# Lemon Package
# ==================================================================================
include(cmake/deployment.cmake)
feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
LEMONLOG(VERSION_STRING)
LEMONLOG(BUILD_VERSION)
LEMONLOG(CMAKE_BUILD_TYPE)
LEMONLOG(LEMON_BUILD_INFO)
LEMONLOG(LEMON_BUILD_EXTRA_INFO)
LEMONLOG(CMAKE_INSTALL_PREFIX)
LEMONLOG(CMAKE_BINARY_DIR)
message("")
message("======== LemonLime Build Statistics ========")
message("${LEMON_BUILD_STATS}")
message("============================================")
message("")