forked from nuttyartist/notes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
371 lines (328 loc) · 13.8 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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
cmake_minimum_required(VERSION 3.10)
set(APP_VERSION 2.1.0)
set(APP_ID "io.github.nuttyartist.notes")
# Any of the options below can be changed by passing -D<option name>=<value> to CMake.
set(CMAKE_OSX_DEPLOYMENT_TARGET
"10.15"
CACHE STRING "Minimum macOS version to target for deployment")
set(USE_QT_VERSION
""
CACHE STRING "Use a specific version of Qt to build the app")
option(GIT_REVISION
"Append the current git revision to the app's version string" OFF)
option(UPDATE_CHECKER
"Enable or disable both the update checker and auto-updater" ON)
project(
Notes
VERSION ${APP_VERSION}
LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
# List of Qt components required to build the app.
set(QT_COMPONENTS
Core
Concurrent
Gui
Network
Sql
Test
Widgets)
# No Qt version was specified, try to use either Qt 6 (preferred) or Qt 5.
if(USE_QT_VERSION STREQUAL "")
# This can probably be simplified once the following bug gets resolved:
# https://gitlab.kitware.com/cmake/cmake/-/issues/23575
message(STATUS "Trying to find Qt 6...")
find_package(QT NAMES Qt6 QUIET)
if(NOT DEFINED QT_VERSION_MAJOR)
message(STATUS "Could not find Qt 6, will try Qt 5 next...")
find_package(QT NAMES Qt5 QUIET)
if(NOT DEFINED QT_VERSION_MAJOR)
message(FATAL_ERROR "Could not find Qt 5, aborting compilation.")
endif()
endif()
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS ${QT_COMPONENTS})
else()
if(NOT USE_QT_VERSION STREQUAL "5" AND NOT USE_QT_VERSION STREQUAL "6")
message(
FATAL_ERROR
"An unsupported version of Qt was specified: '${USE_QT_VERSION}'. Valid values are: 5 or 6."
)
endif()
message(STATUS "Trying to find Qt ${USE_QT_VERSION} (manually specified)...")
find_package(QT NAMES Qt${USE_QT_VERSION} QUIET)
if(NOT DEFINED QT_VERSION_MAJOR)
message(
FATAL_ERROR "Could not find Qt ${USE_QT_VERSION}, aborting compilation.")
endif()
find_package(Qt${USE_QT_VERSION} REQUIRED COMPONENTS ${QT_COMPONENTS})
endif()
message(STATUS "Success! Configuration details:")
message(STATUS "App name: ${PROJECT_NAME}")
message(STATUS "App version: ${PROJECT_VERSION}")
message(STATUS "Qt version: ${QT_VERSION}")
message(STATUS "Update checker: ${UPDATE_CHECKER}")
if(CMAKE_BUILD_TYPE STREQUAL "")
message(STATUS "Build type: (not set)")
else()
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
endif()
set(GIT_REV "")
if(GIT_REVISION)
if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
execute_process(
COMMAND git rev-parse --short HEAD
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_REV
ERROR_VARIABLE GIT_REV_ERR
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE)
if(GIT_REV)
message(STATUS "Git revision: ${GIT_REV}")
string(PREPEND GIT_REV "-g")
else()
message(FATAL_ERROR "Failed to retrieve git revision: ${GIT_REV_ERR}")
endif()
else()
message(
WARNING
"The GIT_REVISION option was set, but this is not a git repository.")
endif()
endif()
set(SOURCES
${PROJECT_SOURCE_DIR}/src/aboutwindow.cpp
${PROJECT_SOURCE_DIR}/src/aboutwindow.h
${PROJECT_SOURCE_DIR}/src/allnotebuttontreedelegateeditor.cpp
${PROJECT_SOURCE_DIR}/src/allnotebuttontreedelegateeditor.h
${PROJECT_SOURCE_DIR}/src/customapplicationstyle.cpp
${PROJECT_SOURCE_DIR}/src/customapplicationstyle.h
${PROJECT_SOURCE_DIR}/src/customdocument.cpp
${PROJECT_SOURCE_DIR}/src/customDocument.h
${PROJECT_SOURCE_DIR}/src/customMarkdownHighlighter.cpp
${PROJECT_SOURCE_DIR}/src/customMarkdownHighlighter.h
${PROJECT_SOURCE_DIR}/src/dbmanager.cpp
${PROJECT_SOURCE_DIR}/src/dbmanager.h
${PROJECT_SOURCE_DIR}/src/defaultnotefolderdelegateeditor.cpp
${PROJECT_SOURCE_DIR}/src/defaultnotefolderdelegateeditor.h
${PROJECT_SOURCE_DIR}/src/editorsettingsbutton.cpp
${PROJECT_SOURCE_DIR}/src/editorsettingsbutton.h
${PROJECT_SOURCE_DIR}/src/elidedlabel.cpp
${PROJECT_SOURCE_DIR}/src/elidedlabel.h
${PROJECT_SOURCE_DIR}/src/foldertreedelegateeditor.cpp
${PROJECT_SOURCE_DIR}/src/foldertreedelegateeditor.h
${PROJECT_SOURCE_DIR}/src/labeledittype.cpp
${PROJECT_SOURCE_DIR}/src/labeledittype.h
${PROJECT_SOURCE_DIR}/src/listviewlogic.cpp
${PROJECT_SOURCE_DIR}/src/listviewlogic.h
${PROJECT_SOURCE_DIR}/src/main.cpp
${PROJECT_SOURCE_DIR}/src/mainwindow.cpp
${PROJECT_SOURCE_DIR}/src/mainwindow.h
${PROJECT_SOURCE_DIR}/src/nodedata.cpp
${PROJECT_SOURCE_DIR}/src/nodedata.h
${PROJECT_SOURCE_DIR}/src/nodepath.cpp
${PROJECT_SOURCE_DIR}/src/nodepath.h
${PROJECT_SOURCE_DIR}/src/nodetreedelegate.cpp
${PROJECT_SOURCE_DIR}/src/nodetreedelegate.h
${PROJECT_SOURCE_DIR}/src/nodetreemodel.cpp
${PROJECT_SOURCE_DIR}/src/nodetreemodel.h
${PROJECT_SOURCE_DIR}/src/nodetreeview.cpp
${PROJECT_SOURCE_DIR}/src/nodetreeview.h
${PROJECT_SOURCE_DIR}/src/nodetreeview_p.h
${PROJECT_SOURCE_DIR}/src/noteeditorlogic.cpp
${PROJECT_SOURCE_DIR}/src/noteeditorlogic.h
${PROJECT_SOURCE_DIR}/src/notelistdelegate.cpp
${PROJECT_SOURCE_DIR}/src/notelistdelegateeditor.cpp
${PROJECT_SOURCE_DIR}/src/notelistdelegateeditor.h
${PROJECT_SOURCE_DIR}/src/notelistdelegate.h
${PROJECT_SOURCE_DIR}/src/notelistmodel.cpp
${PROJECT_SOURCE_DIR}/src/notelistmodel.h
${PROJECT_SOURCE_DIR}/src/notelistview.cpp
${PROJECT_SOURCE_DIR}/src/notelistview.h
${PROJECT_SOURCE_DIR}/src/notelistview_p.h
${PROJECT_SOURCE_DIR}/src/pushbuttontype.cpp
${PROJECT_SOURCE_DIR}/src/pushbuttontype.h
${PROJECT_SOURCE_DIR}/src/singleinstance.cpp
${PROJECT_SOURCE_DIR}/src/singleinstance.h
${PROJECT_SOURCE_DIR}/src/splitterstyle.cpp
${PROJECT_SOURCE_DIR}/src/splitterstyle.h
${PROJECT_SOURCE_DIR}/src/styleeditorwindow.cpp
${PROJECT_SOURCE_DIR}/src/styleeditorwindow.h
${PROJECT_SOURCE_DIR}/src/tagdata.cpp
${PROJECT_SOURCE_DIR}/src/tagdata.h
${PROJECT_SOURCE_DIR}/src/taglistdelegate.cpp
${PROJECT_SOURCE_DIR}/src/taglistdelegate.h
${PROJECT_SOURCE_DIR}/src/taglistmodel.cpp
${PROJECT_SOURCE_DIR}/src/taglistmodel.h
${PROJECT_SOURCE_DIR}/src/taglistview.cpp
${PROJECT_SOURCE_DIR}/src/taglistview.h
${PROJECT_SOURCE_DIR}/src/tagpool.cpp
${PROJECT_SOURCE_DIR}/src/tagpool.h
${PROJECT_SOURCE_DIR}/src/tagtreedelegateeditor.cpp
${PROJECT_SOURCE_DIR}/src/tagtreedelegateeditor.h
${PROJECT_SOURCE_DIR}/src/trashbuttondelegateeditor.cpp
${PROJECT_SOURCE_DIR}/src/trashbuttondelegateeditor.h
${PROJECT_SOURCE_DIR}/src/treeviewlogic.cpp
${PROJECT_SOURCE_DIR}/src/treeviewlogic.h
# ui
${PROJECT_SOURCE_DIR}/src/aboutwindow.ui
${PROJECT_SOURCE_DIR}/src/mainwindow.ui
${PROJECT_SOURCE_DIR}/src/styleeditorwindow.ui
# qrc files
${PROJECT_SOURCE_DIR}/src/fonts.qrc
${PROJECT_SOURCE_DIR}/src/images.qrc
${PROJECT_SOURCE_DIR}/src/styles.qrc)
# Third-party source files.
set(SOURCES_3RD_PARTY
${PROJECT_SOURCE_DIR}/3rdParty/qautostart/src/qautostart.cpp
${PROJECT_SOURCE_DIR}/3rdParty/qautostart/src/qautostart.h
${PROJECT_SOURCE_DIR}/3rdParty/qmarkdowntextedit/linenumberarea.h
${PROJECT_SOURCE_DIR}/3rdParty/qmarkdowntextedit/markdownhighlighter.cpp
${PROJECT_SOURCE_DIR}/3rdParty/qmarkdowntextedit/markdownhighlighter.h
${PROJECT_SOURCE_DIR}/3rdParty/qmarkdowntextedit/qmarkdowntextedit.cpp
${PROJECT_SOURCE_DIR}/3rdParty/qmarkdowntextedit/qmarkdowntextedit.h
${PROJECT_SOURCE_DIR}/3rdParty/qmarkdowntextedit/qownlanguagedata.cpp
${PROJECT_SOURCE_DIR}/3rdParty/qmarkdowntextedit/qownlanguagedata.h
${PROJECT_SOURCE_DIR}/3rdParty/qmarkdowntextedit/qplaintexteditsearchwidget.cpp
${PROJECT_SOURCE_DIR}/3rdParty/qmarkdowntextedit/qplaintexteditsearchwidget.h
${PROJECT_SOURCE_DIR}/3rdParty/qxt/qxtglobal.cpp
${PROJECT_SOURCE_DIR}/3rdParty/qxt/qxtglobal.h
${PROJECT_SOURCE_DIR}/3rdParty/qxt/qxtglobalshortcut.cpp
${PROJECT_SOURCE_DIR}/3rdParty/qxt/qxtglobalshortcut.h
${PROJECT_SOURCE_DIR}/3rdParty/qxt/qxtglobalshortcut_p.h)
if(UPDATE_CHECKER)
list(APPEND SOURCES ${PROJECT_SOURCE_DIR}/src/updaterwindow.cpp
${PROJECT_SOURCE_DIR}/src/updaterwindow.h
${PROJECT_SOURCE_DIR}/src/updaterwindow.ui)
list(
APPEND
SOURCES_3RD_PARTY
${PROJECT_SOURCE_DIR}/3rdParty/QSimpleUpdater/include/QSimpleUpdater.h
${PROJECT_SOURCE_DIR}/3rdParty/QSimpleUpdater/src/Downloader.cpp
${PROJECT_SOURCE_DIR}/3rdParty/QSimpleUpdater/src/Downloader.h
${PROJECT_SOURCE_DIR}/3rdParty/QSimpleUpdater/src/QSimpleUpdater.cpp
${PROJECT_SOURCE_DIR}/3rdParty/QSimpleUpdater/src/Updater.cpp
${PROJECT_SOURCE_DIR}/3rdParty/QSimpleUpdater/src/Updater.h)
endif()
if(APPLE)
list(APPEND SOURCES ${PROJECT_SOURCE_DIR}/src/framelesswindow.mm
${PROJECT_SOURCE_DIR}/src/framelesswindow.h
${PROJECT_SOURCE_DIR}/src/images/notes_icon.icns)
list(APPEND SOURCES_3RD_PARTY
${PROJECT_SOURCE_DIR}/3rdParty/qxt/qxtglobalshortcut_mac.cpp)
elseif(UNIX)
list(APPEND SOURCES_3RD_PARTY
${PROJECT_SOURCE_DIR}/3rdParty/qxt/qxtglobalshortcut_x11.cpp)
elseif(WIN32)
list(APPEND SOURCES ${PROJECT_SOURCE_DIR}/src/framelesswindow.cpp
${PROJECT_SOURCE_DIR}/src/framelesswindow.h
${PROJECT_SOURCE_DIR}/src/images/notes.rc)
list(APPEND SOURCES_3RD_PARTY
${PROJECT_SOURCE_DIR}/3rdParty/qxt/qxtglobalshortcut_win.cpp)
endif()
add_executable(${PROJECT_NAME} WIN32 MACOSX_BUNDLE ${SOURCES}
${SOURCES_3RD_PARTY})
target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/src)
# Include third-party headers as 'system' files, in order to silence compiler warnings on them.
target_include_directories(
${PROJECT_NAME} SYSTEM
PUBLIC ${PROJECT_SOURCE_DIR}/3rdParty/qautostart/src
${PROJECT_SOURCE_DIR}/3rdParty/qmarkdowntextedit
${PROJECT_SOURCE_DIR}/3rdParty/qxt)
if(UPDATE_CHECKER)
target_include_directories(
${PROJECT_NAME} SYSTEM
PUBLIC ${PROJECT_SOURCE_DIR}/3rdParty/QSimpleUpdater/include)
add_definitions(-DUPDATE_CHECKER)
endif()
target_compile_definitions(
${PROJECT_NAME}
PUBLIC APP_VERSION="${PROJECT_VERSION}${GIT_REV}"
QT_DISABLE_DEPRECATED_BEFORE=0x050900 QSU_INCLUDE_MOC=1)
# Enable useful compiler warnings (except on third-party code).
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES
"Clang")
target_compile_options(${PROJECT_NAME} PUBLIC -Wall -Wextra -Wpedantic
-Wshadow)
set_source_files_properties(${SOURCES_3RD_PARTY} PROPERTIES COMPILE_FLAGS -w)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND MSVC_VERSION GREATER_EQUAL
1920)
target_compile_options(${PROJECT_NAME} PUBLIC /W4)
set_source_files_properties(${SOURCES_3RD_PARTY} PROPERTIES COMPILE_FLAGS /w)
endif()
target_link_libraries(
${PROJECT_NAME}
PUBLIC Qt${QT_VERSION_MAJOR}::Concurrent
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::CorePrivate
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::GuiPrivate
Qt${QT_VERSION_MAJOR}::Network
Qt${QT_VERSION_MAJOR}::Sql
Qt${QT_VERSION_MAJOR}::Widgets
Qt${QT_VERSION_MAJOR}::WidgetsPrivate)
if(APPLE)
string(TIMESTAMP CURRENT_YEAR "%Y")
set(COPYRIGHT_TEXT
"Copyright (c) 2015-${CURRENT_YEAR} Ruby Mamistvalove and contributors.")
set_target_properties(
${PROJECT_NAME}
PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME}
MACOSX_BUNDLE_GUI_IDENTIFIER ${APP_ID}
MACOSX_BUNDLE_ICON_FILE "notes_icon.icns"
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION}
MACOSX_BUNDLE_LONG_VERSION_STRING ${PROJECT_VERSION}
MACOSX_BUNDLE_COPYRIGHT ${COPYRIGHT_TEXT}
MACOSX_BUNDLE_INFO_STRING ${COPYRIGHT_TEXT})
set_source_files_properties(${PROJECT_SOURCE_DIR}/src/images/notes_icon.icns
PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")
target_link_libraries(${PROJECT_NAME} PUBLIC "-framework Carbon"
"-framework Cocoa")
elseif(UNIX)
# On Linux, it's conventional for executables to be all lowercase.
string(TOLOWER ${PROJECT_NAME} BINARY_NAME)
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME ${BINARY_NAME})
target_link_libraries(${PROJECT_NAME} PUBLIC X11)
include(GNUInstallDirs)
configure_file(${PROJECT_SOURCE_DIR}/packaging/linux/common/notes.desktop.in
${CMAKE_BINARY_DIR}/${APP_ID}.desktop)
install(FILES ${CMAKE_BINARY_DIR}/${APP_ID}.desktop
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/applications)
configure_file(
${PROJECT_SOURCE_DIR}/packaging/linux/common/notes.appdata.xml.in
${CMAKE_BINARY_DIR}/${APP_ID}.metainfo.xml)
install(FILES ${CMAKE_BINARY_DIR}/${APP_ID}.metainfo.xml
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/metainfo)
foreach(
ICON_SIZE
16
22
24
32
48
64
128
256
512)
install(
FILES
${PROJECT_SOURCE_DIR}/packaging/linux/common/icons/${ICON_SIZE}x${ICON_SIZE}/notes.png
DESTINATION
${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/${ICON_SIZE}x${ICON_SIZE}/apps
RENAME ${APP_ID}.png)
endforeach()
install(
FILES ${PROJECT_SOURCE_DIR}/packaging/linux/common/icons/scalable/notes.svg
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/scalable/apps
RENAME ${APP_ID}.svg)
elseif(WIN32)
target_compile_definitions(${PROJECT_NAME} PUBLIC QXT_STATIC)
target_link_libraries(${PROJECT_NAME} PUBLIC user32)
endif()
install(
TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION bin
BUNDLE DESTINATION bin
LIBRARY DESTINATION lib)