forked from crow-translate/crow-translate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
314 lines (284 loc) · 11.6 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
cmake_minimum_required(VERSION 3.16.0)
project(crow-translate
VERSION 2.11.0
DESCRIPTION "A simple and lightweight translator that allows to translate and speak text using Google, Yandex, Bing, LibreTranslate and Lingva"
HOMEPAGE_URL crow-translate.github.io
LANGUAGES CXX
)
set(APPLICATION_NAME "Crow Translate")
set(APPLICATION_ID "io.crow_translate.CrowTranslate")
set(EXECUTABLE_NAME crow)
if(UNIX)
set(DESKTOP_FILE ${APPLICATION_ID}.desktop)
set(METAINFO_FILE ${APPLICATION_ID}.metainfo.xml)
endif()
set(CPACK_PACKAGE_VENDOR ${APPLICATION_NAME})
set(CPACK_PACKAGE_EXECUTABLES ${EXECUTABLE_NAME} ${APPLICATION_NAME})
set(CPACK_PACKAGE_INSTALL_DIRECTORY ${APPLICATION_NAME})
set(CPACK_PACKAGE_CONTACT [email protected])
set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/COPYING)
set(CPACK_PROJECT_CONFIG_FILE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/CPackProjectConfig.cmake)
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
set(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS_POLICY >=)
set(CPACK_DEBIAN_PACKAGE_RECOMMENDS "qtgstreamer-plugins-qt5, gstreamer1.0-plugins-good, gstreamer1.0-alsa, gstreamer1.0-pulseaudio, libqt5multimedia5-plugins")
set(CPACK_RPM_FILE_NAME RPM-DEFAULT)
set(CPACK_RPM_PACKAGE_LICENSE GPLv3)
set(CPACK_RPM_PACKAGE_GROUP Applications/Text)
set(CPACK_RPM_COMPRESSION_TYPE lzma)
set(CPACK_NSIS_DISPLAY_NAME ${APPLICATION_NAME})
set(CPACK_NSIS_INSTALLED_ICON_NAME ${EXECUTABLE_NAME}.exe)
set(CPACK_NSIS_EXECUTABLES_DIRECTORY .)
set(CPACK_NSIS_MUI_FINISHPAGE_RUN ${EXECUTABLE_NAME}.exe)
set(CPACK_EXTERNAL_PACKAGE_SCRIPT ${CMAKE_SOURCE_DIR}/cmake/AppImage.cmake)
set(CPACK_EXTERNAL_ENABLE_STAGING YES)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_WIN32_EXECUTABLE ON)
if(CMAKE_CXX_CLANG_TIDY)
# Exclude generated files
# We generate a dummy .clang-tidy file in the binary directory that disables
# all clang-tidy checks except one that will never match. This one check is
# necessary; clang-tidy reports an error when no checks are enabled.
# https://gitlab.kitware.com/cmake/cmake/-/issues/19772
file(WRITE ${CMAKE_BINARY_DIR}/.clang-tidy "Checks: '-*,llvm-twine-local'")
endif()
option(WITH_PORTABLE_MODE "Enable portable functionality" OFF)
option(WITH_KWAYLAND "Use KWayland for better Wayland integration" ON)
find_package(ECM REQUIRED NO_MODULE)
list(APPEND CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
set(QAPPLICATION_CLASS QApplication)
option(QHOTKEY_INSTALL OFF)
add_subdirectory(src/third-party/singleapplication)
add_subdirectory(src/third-party/qhotkey)
add_subdirectory(src/third-party/qtaskbarcontrol)
add_subdirectory(src/qonlinetranslator)
if(WIN32)
add_subdirectory(src/qgittag)
endif()
find_package(Qt5 REQUIRED COMPONENTS Widgets LinguistTools Concurrent)
find_package(Tesseract REQUIRED)
if(UNIX)
find_package(Qt5 REQUIRED COMPONENTS DBus)
if(NOT APPLE)
find_package(XCB REQUIRED COMPONENTS XCB)
if(WITH_KWAYLAND)
find_package(KF5Wayland REQUIRED COMPONENTS Client)
endif()
endif()
endif()
include(GNUInstallDirs)
include(CPack)
if(UNIX)
include(ECMInstallIcons)
endif()
if(WIN32 OR APPLE)
include(ECMAddAppIcon)
endif()
set(APP_ICONS
data/icons/app/128-apps-crow-translate.png
data/icons/app/150-apps-crow-translate.png
data/icons/app/16-apps-crow-translate.png
data/icons/app/22-apps-crow-translate.png
data/icons/app/256-apps-crow-translate.png
data/icons/app/310-apps-crow-translate.png
data/icons/app/32-apps-crow-translate.png
data/icons/app/44-apps-crow-translate.png
data/icons/app/48-apps-crow-translate.png
data/icons/app/512-apps-crow-translate.png
data/icons/app/64-apps-crow-translate.png
)
qt5_add_translation(QM_FILES
data/translations/${PROJECT_NAME}_ar_SA.ts
data/translations/${PROJECT_NAME}_az_AZ.ts
data/translations/${PROJECT_NAME}_de_DE.ts
data/translations/${PROJECT_NAME}_el_GR.ts
data/translations/${PROJECT_NAME}_es_ES.ts
data/translations/${PROJECT_NAME}_eu_ES.ts
data/translations/${PROJECT_NAME}_fi_FI.ts
data/translations/${PROJECT_NAME}_fr_FR.ts
data/translations/${PROJECT_NAME}_hi_IN.ts
data/translations/${PROJECT_NAME}_hu_HU.ts
data/translations/${PROJECT_NAME}_id_ID.ts
data/translations/${PROJECT_NAME}_it_IT.ts
data/translations/${PROJECT_NAME}_ko_KR.ts
data/translations/${PROJECT_NAME}_ms_MY.ts
data/translations/${PROJECT_NAME}_nl_NL.ts
data/translations/${PROJECT_NAME}_pl_PL.ts
data/translations/${PROJECT_NAME}_pt_BR.ts
data/translations/${PROJECT_NAME}_pt_PT.ts
data/translations/${PROJECT_NAME}_ru_RU.ts
data/translations/${PROJECT_NAME}_sq_AL.ts
data/translations/${PROJECT_NAME}_tr_TR.ts
data/translations/${PROJECT_NAME}_ug_CN.ts
data/translations/${PROJECT_NAME}_uk_UA.ts
data/translations/${PROJECT_NAME}_zh_CN.ts
data/translations/${PROJECT_NAME}_zh_TW.ts
)
configure_file(src/cmake.h.in cmake.h)
add_executable(${PROJECT_NAME}
data/icons/flags.qrc
${QM_FILES}
data/icons/icon-theme.qrc
data/icons/engines/engines.qrc
src/languagesdialog.cpp
src/languagesdialog.ui
src/cli.cpp
src/contextmenu.cpp
src/languagebuttonswidget.cpp
src/languagebuttonswidget.ui
src/main.cpp
src/mainwindow.cpp
src/mainwindow.ui
src/ocr/ocr.cpp
src/ocr/screengrabbers/abstractscreengrabber.cpp
src/ocr/screengrabbers/genericscreengrabber.cpp
src/ocr/snippingarea.cpp
src/popupwindow.cpp
src/popupwindow.ui
src/screenwatcher.cpp
src/selection.cpp
src/settings/appsettings.cpp
src/settings/ocrlanguageslistwidget.cpp
src/settings/settingsdialog.cpp
src/settings/settingsdialog.ui
src/settings/shortcutsmodel/shortcutitem.cpp
src/settings/shortcutsmodel/shortcutsmodel.cpp
src/settings/shortcutsmodel/shortcutsview.cpp
src/settings/tesseractparameterstablewidget.cpp
src/settings/autostartmanager/abstractautostartmanager.cpp
src/sourcetextedit.cpp
src/speakbuttons.cpp
src/speakbuttons.ui
src/transitions/languagedetectedtransition.cpp
src/transitions/ocruninitializedtransition.cpp
src/transitions/playerstoppedtransition.cpp
src/transitions/retranslationtransition.cpp
src/transitions/snippingvisibletransition.cpp
src/transitions/textemptytransition.cpp
src/transitions/translatorabortedtransition.cpp
src/transitions/translatorerrortransition.cpp
src/translationedit.cpp
src/trayicon.cpp
)
if(UNIX AND NOT APPLE)
target_sources(${PROJECT_NAME} PRIVATE
src/xdgdesktopportal.cpp
src/ocr/screengrabbers/dbusscreengrabber.cpp
src/ocr/screengrabbers/waylandgnomescreengrabber.cpp
src/ocr/screengrabbers/waylandplasmascreengrabber.cpp
src/ocr/screengrabbers/waylandportalscreengrabber.cpp
src/settings/autostartmanager/unixautostartmanager.cpp
src/settings/autostartmanager/portalautostartmanager.cpp
)
if(WITH_KWAYLAND)
target_sources(${PROJECT_NAME} PRIVATE
src/waylandhelper.cpp
)
endif(WITH_KWAYLAND)
elseif(APPLE)
ecm_add_app_icon(MACOS_ICON ICONS ${APP_ICONS})
target_sources(${PROJECT_NAME} PRIVATE
${MACOS_ICON}
data/icons/app/app.qrc
src/settings/autostartmanager/macosautostartmanager.cpp
)
elseif(WIN32)
ecm_add_app_icon(WINDOWS_ICON ICONS ${APP_ICONS})
target_sources(${PROJECT_NAME} PRIVATE
${WINDOWS_ICON}
data/icons/app/app.qrc
src/updaterdialog.cpp
src/updaterdialog.ui
src/settings/autostartmanager/windowsautostartmanager.cpp
)
endif()
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME ${EXECUTABLE_NAME})
target_link_libraries(${PROJECT_NAME} PRIVATE
SingleApplication::SingleApplication
QHotkey::QHotkey
QTaskbarControl::QTaskbarControl
QOnlineTranslator::QOnlineTranslator
Qt5::Concurrent
Tesseract::Tesseract
)
if(UNIX)
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::DBus)
if(NOT APPLE)
target_link_libraries(${PROJECT_NAME} PRIVATE XCB::XCB)
if(WITH_KWAYLAND)
target_link_libraries(${PROJECT_NAME} PRIVATE KF5::WaylandClient)
target_compile_definitions(${PROJECT_NAME} PRIVATE WITH_KWAYLAND)
endif()
endif()
elseif(WIN32)
target_link_libraries(${PROJECT_NAME} PRIVATE QGitTag::QGitTag)
endif()
if(WITH_PORTABLE_MODE)
target_compile_definitions(${PROJECT_NAME} PRIVATE WITH_PORTABLE_MODE)
endif()
if(UNIX AND NOT APPLE)
install(TARGETS ${PROJECT_NAME})
install(FILES ${QM_FILES} DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/${PROJECT_NAME}/translations)
install(FILES data/${DESKTOP_FILE} DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/applications)
install(FILES data/${METAINFO_FILE} DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/metainfo)
ecm_install_icons(ICONS
${APP_ICONS}
data/icons/app/sc-apps-crow-translate.svg
data/icons/app/16-status-crow-translate-tray-dark.png
data/icons/app/16-status-crow-translate-tray-light.png
data/icons/app/22-status-crow-translate-tray-dark.png
data/icons/app/22-status-crow-translate-tray-light.png
data/icons/app/24-status-crow-translate-tray-dark.png
data/icons/app/24-status-crow-translate-tray-light.png
data/icons/app/sc-status-crow-translate-tray-dark.svg
data/icons/app/sc-status-crow-translate-tray-light.svg
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons
)
elseif(APPLE)
set_target_properties(${PROJECT_NAME} PROPERTIES
MACOSX_BUNDLE ON
MACOSX_BUNDLE_BUNDLE_NAME ${APPLICATION_NAME}
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_GUI_IDENTIFIER ${APPLICATION_ID}
MACOSX_BUNDLE_INFO_STRING ${PROJECT_DESCRIPTION}
RESOURCE "${QM_FILES}"
)
elseif(WIN32)
install(TARGETS ${PROJECT_NAME} DESTINATION .)
install(FILES ${QM_FILES} DESTINATION translations)
# Bundle Qt dependencies
find_program(WINDEPLOYQT windeployqt PATH_SUFFIXES tools/qt5/bin)
install(CODE "execute_process(COMMAND ${WINDEPLOYQT} --no-compiler-runtime --no-angle \${CMAKE_INSTALL_PREFIX}/$<TARGET_FILE_NAME:${PROJECT_NAME}>)")
# Bundle OpenSLL libraries that required for Qt networking manually because it not handled by windeployqt
find_file(SLL_DLL NAMES libssl-1_1-x64.dll libssl-1_1.dll libssl.dll PATH_SUFFIXES tools/qt5/bin)
find_file(CRYPTO_DLL NAMES libcrypto-1_1-x64.dll libcrypto-1_1.dll libcrypto.dll PATH_SUFFIXES tools/qt5/bin)
install(FILES ${SLL_DLL} ${CRYPTO_DLL} DESTINATION .)
# Install other non-Qt runtime depenencies
install(CODE [[
file(GET_RUNTIME_DEPENDENCIES
EXECUTABLES $<TARGET_FILE:crow-translate>
PRE_EXCLUDE_REGEXES api-ms qt5
POST_EXCLUDE_REGEXES C:[/\\]Windows[/\\]
RESOLVED_DEPENDENCIES_VAR RESOLVED_DEPENDENCIES
UNRESOLVED_DEPENDENCIES_VAR UNRESOLVED_DEPENDENCIES
)
foreach(DEPENDENCY ${UNRESOLVED_DEPENDENCIES})
message(WARNING "Unable to resolve dependency ${DEPENDENCY}")
endforeach()
foreach(DEPENDENCY ${RESOLVED_DEPENDENCIES})
message("Copying ${DEPENDENCY}")
file(INSTALL
DESTINATION "${CMAKE_INSTALL_PREFIX}"
FILES "${DEPENDENCY}"
)
endforeach()
file(WRITE ${CMAKE_INSTALL_PREFIX}/qt.conf "[Paths]") # Setup Qt libraries paths
]])
endif()