-
Notifications
You must be signed in to change notification settings - Fork 7
/
CMakeLists.txt
242 lines (215 loc) · 9.21 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
cmake_minimum_required(VERSION 3.20)
project(Lith)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
include(CMakeDependentOption)
include(FeatureSummary)
include(GenerateExportHeader)
include(cmake/CPM.cmake)
if(NOT CMAKE_CROSSCOMPILING)
# Doesn't make sense when running on another device
option(LITH_FEATURE_QHOT "Download and build https://github.com/patrickelectric/qhot - a live-reloading tool for UI development." OFF)
endif()
option(LITH_FORCE_DOWNLOAD_DEPENDENCIES "Force downloading 3rd party dependencies even if they are installed." OFF)
option(LITH_FORCE_LOCAL_PACKAGES_ONLY "Completely disable downloading 3rd party dependencies, only the ones from find_package will be used." OFF)
option(LITH_BUILD_TESTS "While building the application, build tests, too" OFF)
if(NOT CMAKE_SYSTEM_NAME STREQUAL Emscripten)
# There's no WebAssembly backend
option(LITH_FEATURE_KEYCHAIN "Use QtKeychain to store credentials securely" ON)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(LITH_DEPENDENCY_ENABLE_DBUS ON)
else()
set(LITH_DEPENDENCY_ENABLE_DBUS OFF)
endif()
if(LITH_FEATURE_KEYCHAIN)
set(LITH_DEPENDENCY_ENABLE_KEYCHAIN ON)
else()
set(LITH_DEPENDENCY_ENABLE_KEYCHAIN OFF)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Android")
set(ANDROID_OPENSSL_PATH "${ANDROID_SDK_ROOT}/android_openssl/ssl_3" CACHE STRING "Path to the folder with https://github.com/KDAB/android_openssl.git")
endif()
set(VERSION "0.0.0" CACHE STRING "This is where we start working with the version string as passed from the build script")
set(VERSION_RELEASEDATE "1970-01-01" CACHE STRING "Release date to be used in metadata, used in Linux appdata only for now.")
find_package(Git REQUIRED)
# rerun git metadata retrieval on each commit message change
set_property(
DIRECTORY
APPEND
PROPERTY CMAKE_CONFIGURE_DEPENDS ${CMAKE_CURRENT_LIST_DIR}/.git/COMMIT_EDITMSG
)
execute_process(
COMMAND "${GIT_EXECUTABLE}" rev-parse HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
OUTPUT_VARIABLE COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND "${GIT_EXECUTABLE}" describe --tags --dirty
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
OUTPUT_VARIABLE GIT_STATE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND "${GIT_EXECUTABLE}" describe --tags --abbrev=0
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
OUTPUT_VARIABLE GIT_LAST_TAG
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND "${GIT_EXECUTABLE}" tag -l "${GIT_LAST_TAG}" "--format=%(creatordate:short)"
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
OUTPUT_VARIABLE GIT_LAST_TAG_DATE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (VERSION AND NOT "${VERSION}" STREQUAL "0.0.0")
set(PROJECT_VERSION ${VERSION} CACHE STRING "" FORCE)
if (NOT "${VERSION_RELEASEDATE}" STREQUAL "1970-01-01")
set(PROJECT_VERSION_RELEASEDATE "${VERSION_RELEASEDATE}" CACHE STRING "" FORCE)
else()
message("Release date was not supplied but version was, metadata will show today")
string(TIMESTAMP PROJECT_VERSION_RELEASEDATE "%Y-%m-%d")
endif()
message("Building Lith version ${PROJECT_VERSION}, release date: ${PROJECT_VERSION_RELEASEDATE}")
elseif(GIT_LAST_TAG)
set(PROJECT_VERSION "${GIT_LAST_TAG}" CACHE STRING "" FORCE)
set(PROJECT_VERSION_RELEASEDATE "${GIT_LAST_TAG_DATE}" CACHE STRING "" FORCE)
message("Version passed to CMake was empty, using last one retrieved from git: ${PROJECT_VERSION}, tagged on ${PROJECT_VERSION_RELEASEDATE}")
else()
set(PROJECT_VERSION "0.0.0" CACHE STRING "" FORCE)
set(PROJECT_VERSION_RELEASEDATE "1970-01-01" CACHE STRING "" FORCE)
message(WARNING "Version passed to CMake was empty, this may have been done on accident, using ${PROJECT_VERSION}")
endif()
string(REPLACE "." ";" VERSION_LIST ${PROJECT_VERSION})
list(GET VERSION_LIST 0 PROJECT_VERSION_MAJOR)
list(GET VERSION_LIST 1 PROJECT_VERSION_MINOR)
list(GET VERSION_LIST 2 PROJECT_VERSION_PATCH)
if(CMAKE_BUILD_TYPE STREQUAL Debug OR CMAKE_BUILD_TYPE STREQUAL Profile)
set(LITH_IS_DEBUG_BUILD ON CACHE STRING "")
endif()
find_package(Qt6 COMPONENTS Widgets Gui Quick Multimedia Qml QuickControls2 QuickLayouts QuickDialogs2 QuickTemplates2 WebSockets Xml REQUIRED)
if (LITH_DEPENDENCY_ENABLE_DBUS)
find_package(Qt6 COMPONENTS DBus REQUIRED)
endif()
if(LITH_BUILD_TESTS)
find_package(Qt6 COMPONENTS Test REQUIRED)
enable_testing()
endif()
if (LITH_FORCE_DOWNLOAD_DEPENDENCIES)
message(STATUS "All dependencies will be downloaded and built")
set(CPM_USE_LOCAL_PACKAGES OFF CACHE BOOL "" FORCE)
set(CPM_LOCAL_PACKAGES_ONLY OFF CACHE BOOL "" FORCE)
elseif(LITH_FORCE_LOCAL_PACKAGES_ONLY)
message(STATUS "CMake will enforce use your systemwide dependencies")
set(CPM_USE_LOCAL_PACKAGES ON CACHE BOOL "" FORCE)
set(CPM_LOCAL_PACKAGES_ONLY ON CACHE BOOL "" FORCE)
else()
message(STATUS "CMake will try to use your systemwide dependencies, if installed")
set(CPM_USE_LOCAL_PACKAGES ON CACHE BOOL "" FORCE)
set(CPM_LOCAL_PACKAGES_ONLY OFF CACHE BOOL "" FORCE)
endif()
if(LITH_DEPENDENCY_ENABLE_KEYCHAIN)
CPMAddPackage(
NAME Qt6Keychain
GIT_REPOSITORY https://github.com/frankosterfeld/qtkeychain.git
GIT_TAG 38ff50766c7e4ec490fecb2d9939b7cdc4b74b8e
VERSION 0.14.3
EXCLUDE_FROM_ALL ON
OPTIONS "BUILD_WITH_QT6 ON" "USE_CREDENTIAL_STORE ON" "BUILD_SHARED_LIBS OFF" "BUILD_TRANSLATIONS OFF"
)
endif()
set(LITH_QCORO_DEPENDENCY_MODULES
Core
Network
WebSockets
)
if (LITH_DEPENDENCY_ENABLE_DBUS)
list(APPEND LITH_QCORO_DEPENDENCY_MODULES
"DBus"
)
endif()
CPMAddPackage(
NAME QCoro6
GIT_REPOSITORY https://github.com/danvratil/qcoro
GIT_TAG fa5bc4296a252ad71c85209b60675bb025024a1e
VERSION 0.10.0
EXCLUDE_FROM_ALL ON
OPTIONS "QCORO_BUILD_EXAMPLES OFF" "BUILD_TESTING OFF" "QCORO_WITH_QTDBUS ${LITH_DEPENDENCY_ENABLE_DBUS}"
FIND_PACKAGE_ARGUMENTS "COMPONENTS ${LITH_QCORO_DEPENDENCY_MODULES} REQUIRED"
)
qt_standard_project_setup(REQUIRES 6.5)
get_target_property(QT_MOC_EXECUTABLE Qt::moc IMPORTED_LOCATION)
get_filename_component(QT_BINARY_PREFIX ${QT_MOC_EXECUTABLE} DIRECTORY)
get_filename_component(QT_INSTALL_PREFIX ${QT_BINARY_PREFIX} DIRECTORY)
qcoro_enable_coroutines()
# I'm pretty sure I'm doing something wrong with this but I haven't found a better way to create the macOS bundle
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(LITH_INSTALL_LIBDIR "Lith.app/Contents/Frameworks/")
else()
set(LITH_INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR})
endif()
if (UNIX AND NOT APPLE)
set(LITH_INSTALL_MODULEDIR "${CMAKE_INSTALL_PREFIX}/${LITH_INSTALL_LIBDIR}/Lith/modules")
else()
set(LITH_INSTALL_MODULEDIR "${CMAKE_INSTALL_PREFIX}/${LITH_INSTALL_LIBDIR}/modules")
endif()
set(QML_IMPORT_PATH "${CMAKE_BINARY_DIR}/modules" CACHE STRING "")
#set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${LITH_INSTALL_LIBDIR}")
add_subdirectory(assets)
add_subdirectory(modules/Lith/Style)
add_subdirectory(modules/Lith/UI)
add_subdirectory(modules/Lith/Core)
add_subdirectory(app)
add_dependencies(Lith LithStyleplugin LithUIplugin LithCoreplugin)
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
configure_file(${CMAKE_SOURCE_DIR}/dist/linux/app.lith.Lith.appdata.xml.in ${CMAKE_BINARY_DIR}/dist/linux/app.lith.Lith.appdata.xml)
install(FILES ${CMAKE_BINARY_DIR}/dist/linux/app.lith.Lith.appdata.xml DESTINATION share/metainfo)
install(FILES ${CMAKE_SOURCE_DIR}/dist/linux/app.lith.Lith.desktop DESTINATION share/applications)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/assets/icons/linux/hicolor DESTINATION share/icons)
endif()
if (LITH_FEATURE_QHOT)
CPMAddPackage(
NAME qhot
GIT_REPOSITORY https://github.com/MartinBriza/qhot.git
GIT_TAG 942aa3d6fb1badf8952b4fb127d6881861611771
EXCLUDE_FROM_ALL ON
)
get_property(qhot_BINARY_DIR TARGET qhot PROPERTY BINARY_DIR)
get_property(qhot_NAME TARGET qhot PROPERTY NAME)
add_executable(Lith-qhot EXCLUDE_FROM_ALL)
add_dependencies(Lith Lith-qhot)
add_dependencies(Lith-qhot qhot)
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(qhot_FULL_BINARY_PATH "${CMAKE_BINARY_DIR}/${qhot_NAME}.exe")
set_target_properties(Lith-qhot PROPERTIES
LINKER_LANGUAGE NONE
OUTPUT_NAME Lith-qhot
SUFFIX .bat
)
configure_file(dist/Lith-qhot.bat.in Lith-qhot.bat
@ONLY
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
else()
if (APPLE)
set(qhot_FULL_BINARY_PATH "${qhot_BINARY_DIR}/${qhot_NAME}.app/Contents/MacOS/${qhot_NAME}")
else()
set(qhot_FULL_BINARY_PATH "${qhot_BINARY_DIR}/${qhot_NAME}")
endif()
set_target_properties(Lith-qhot PROPERTIES
LINKER_LANGUAGE NONE
OUTPUT_NAME Lith-qhot.sh
)
configure_file(dist/Lith-qhot.sh.in Lith-qhot.sh
@ONLY
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
endif()
endif()
feature_summary(WHAT ALL)