forked from xvitaly/tuned-switcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
255 lines (206 loc) · 8.2 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
#
# SPDX-FileCopyrightText: 2021-2023 EasyCoding Team and contributors
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# ======================================================
# =============== Project initialization ===============
# ======================================================
cmake_minimum_required(VERSION 3.12)
project(tuned-switcher
VERSION 0.7.2
DESCRIPTION "Simple utility to manipulate the Tuned service"
HOMEPAGE_URL "https://github.com/xvitaly/tuned-switcher"
LANGUAGES CXX
)
set(RELEASE_DATE "2023-04-12")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# ======================================================
# ================== Project options ===================
# ======================================================
option(BUILD_DOC "Build documentation" OFF)
option(BUILD_MANPAGE "Build manpage" OFF)
option(BUILD_TESTS "Build tests" OFF)
# ======================================================
# ================= Internal variables =================
# ======================================================
set(SCHEME_NAME "org.easycoding.TunedSwitcher")
set(LAUNCHER_NAME "${SCHEME_NAME}.desktop")
set(APPDATA_MANIFEST "${SCHEME_NAME}.metainfo.xml")
# ======================================================
# ==================== Target names ====================
# ======================================================
set(APP_NAME "${CMAKE_PROJECT_NAME}")
set(LIB_NAME "${CMAKE_PROJECT_NAME}-lib")
set(I18N_NAME "${CMAKE_PROJECT_NAME}-i18n")
set(DOCS_NAME "${CMAKE_PROJECT_NAME}-docs")
set(MAN_NAME "${CMAKE_PROJECT_NAME}-man")
# ======================================================
# ================= Internal imports ===================
# ======================================================
include(GNUInstallDirs)
include(FindPackageHandleStandardArgs)
# ======================================================
# ================= External imports ===================
# ======================================================
include(cmake/FindPandoc.cmake)
include(cmake/FindTestHelpers.cmake)
# ======================================================
# ==================== Qt detection ====================
# ======================================================
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
set(QT_COMPONENTS
Core
DBus
Gui
LinguistTools
Widgets
)
find_package(Qt6 6.2.0
COMPONENTS ${QT_COMPONENTS}
QUIET
)
if (NOT Qt6_FOUND)
find_package(Qt5 5.15.0
COMPONENTS ${QT_COMPONENTS}
REQUIRED
)
endif()
# ======================================================
# ================= Doxygen detection ==================
# ======================================================
if (BUILD_DOC)
find_package(Doxygen REQUIRED)
set(DOXYGEN_PROJECT_LOGO "assets/icons/icon-64.png")
set(DOXYGEN_QUIET YES)
set(DOXYGEN_RECURSIVE YES)
set(DOXYGEN_GENERATE_HTML YES)
set(DOXYGEN_GENERATE_MAN NO)
set(DOXYGEN_QT_AUTOBRIEF YES)
set(DOXYGEN_MARKDOWN_SUPPORT YES)
set(DOXYGEN_BUILTIN_STL_SUPPORT YES)
set(DOXYGEN_EXTRACT_PRIVATE YES)
set(DOXYGEN_EXTRACT_PRIV_VIRTUAL YES)
set(DOXYGEN_EXTRACT_PACKAGE YES)
set(DOXYGEN_EXTRACT_STATIC YES)
set(DOXYGEN_EXTRACT_LOCAL_CLASSES YES)
set(DOXYGEN_EXTRACT_LOCAL_METHODS YES)
set(DOXYGEN_SHOW_INCLUDE_FILES YES)
set(DOXYGEN_BINARY_TOC YES)
set(DOXYGEN_TOC_EXPAND YES)
set(DOXYGEN_USE_MDFILE_AS_MAINPAGE "README.md")
endif()
# ======================================================
# ================== Library target ====================
# ======================================================
set(LIBRARY_HEADERS
src/lib/tunedtypes/tunedtypes.h
src/lib/translationmanager/translationmanager.h
src/lib/notificationsmanager/dbusconverters.h
src/lib/notificationsmanager/notificationsmanager.h
src/lib/tunedmanager/tunedmanager.h
)
set(LIBRARY_SOURCES
src/lib/tunedtypes/tunedtypes.cpp
src/lib/translationmanager/translationmanager.cpp
src/lib/notificationsmanager/notificationsmanager.cpp
src/lib/tunedmanager/tunedmanager.cpp
)
configure_file(
"src/lib/appconstants/appconstants.h.in"
"generated/appconstants/appconstants.h"
@ONLY
)
add_library(${LIB_NAME} OBJECT
${LIBRARY_HEADERS}
${LIBRARY_SOURCES}
)
target_include_directories(${LIB_NAME} PUBLIC
src/lib
"${CMAKE_CURRENT_BINARY_DIR}/generated"
)
target_link_libraries(${LIB_NAME} PUBLIC
Qt::Widgets
Qt::DBus
)
# ======================================================
# ================= Application target =================
# ======================================================
set(APPLICATION_HEADERS
src/app/trayicon/trayicon.h
src/app/mainwindow/mainwindow.h
)
set(APPLICATION_SOURCES
src/app/trayicon/trayicon.cpp
src/app/mainwindow/mainwindow.cpp
src/app/main.cpp
)
set(APPLICATION_RESOURCES
src/app/resources.qrc
)
set(APPLICATION_UI_SOURCES
src/app/mainwindow/mainwindow.ui
)
add_executable(${APP_NAME}
${APPLICATION_HEADERS}
${APPLICATION_SOURCES}
${APPLICATION_UI_SOURCES}
${APPLICATION_RESOURCES}
)
target_include_directories(${APP_NAME} PRIVATE
src/app
)
file(GLOB TS_GLOB "assets/i18n/${CMAKE_PROJECT_NAME}_*.ts")
if (Qt6_FOUND)
qt_add_translations(${APP_NAME}
TS_FILES ${TS_GLOB}
QM_FILES_OUTPUT_VARIABLE QM_FILES
)
else()
qt_add_translation(QM_FILES
${TS_GLOB}
)
add_custom_target(${I18N_NAME} ALL DEPENDS ${QM_FILES})
endif()
target_link_libraries(${APP_NAME} PRIVATE
Qt::Widgets
Qt::DBus
${LIB_NAME}
)
install(TARGETS ${APP_NAME}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(FILES ${QM_FILES} DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/${CMAKE_PROJECT_NAME}/translations")
# ======================================================
# =================== Assets target ====================
# ======================================================
install(FILES "assets/icons/icon.svg" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/scalable/apps" RENAME "${SCHEME_NAME}.svg")
foreach(ICON_SIZE 16 22 24 32 48 64 128 256)
install(FILES "assets/icons/icon-${ICON_SIZE}.png" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/${ICON_SIZE}x${ICON_SIZE}/apps" RENAME "${SCHEME_NAME}.png")
endforeach()
configure_file("assets/desktop/${CMAKE_PROJECT_NAME}.desktop.in" "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}.desktop" @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}.desktop" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/applications" RENAME "${LAUNCHER_NAME}")
if (BUILD_DOC)
doxygen_add_docs(${DOCS_NAME} src docs ALL WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMENT "Building documentation with Doxygen.")
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/html/" DESTINATION ${CMAKE_INSTALL_DOCDIR})
endif()
if (BUILD_MANPAGE)
configure_file("assets/manpage/${CMAKE_PROJECT_NAME}.md.in" "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}.md" @ONLY)
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${APP_NAME}.1" COMMAND "${Pandoc_EXECUTABLE}" ARGS "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}.md" -s -t man -o "${CMAKE_CURRENT_BINARY_DIR}/${APP_NAME}.1" COMMENT "Building manpage using Pandoc." VERBATIM)
add_custom_target(${MAN_NAME} ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${APP_NAME}.1")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${APP_NAME}.1" DESTINATION "${CMAKE_INSTALL_MANDIR}/man1")
endif()
configure_file("assets/metainfo/${CMAKE_PROJECT_NAME}.metainfo.xml.in" "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}.metainfo.xml" @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}.metainfo.xml" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/metainfo" RENAME "${APPDATA_MANIFEST}")
# ======================================================
# ==================== Tests target ====================
# ======================================================
if (BUILD_TESTS)
enable_testing()
add_test(NAME test-desktop COMMAND ${DesktopFileValidate_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}.desktop")
add_test(NAME test-metainfo COMMAND ${AppstreamUtil_EXECUTABLE} validate "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}.metainfo.xml")
endif()