-
Notifications
You must be signed in to change notification settings - Fork 257
/
CMakeLists.txt
333 lines (282 loc) · 9.44 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
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
# CMP0000: Call the cmake_minimum_required() command at the beginning of the top-level
# CMakeLists.txt file even before calling the project() command.
# The cmake_minimum_required(VERSION) command implicitly invokes the cmake_policy(VERSION)
# command to specify that the current project code is written for the given range of CMake
# versions.
project(qtermwidget)
include(GNUInstallDirs)
include(GenerateExportHeader)
include(CMakePackageConfigHelpers)
include(CheckFunctionExists)
include(CheckIncludeFile)
option(UPDATE_TRANSLATIONS "Update source translation translations/*.ts files" OFF)
option(BUILD_EXAMPLE "Build example application. Default OFF." OFF)
option(QTERMWIDGET_USE_UTEMPTER "Uses libutempter on Linux or libulog on FreeBSD for login records." OFF)
option(QTERMWIDGET_BUILD_PYTHON_BINDING "Build python binding" OFF)
option(USE_UTF8PROC "Use libutf8proc for better Unicode support. Default OFF" OFF)
# just change version for releases
# keep this in sync with the version in pyqt/pyproject.toml
set(QTERMWIDGET_VERSION_MAJOR "1")
set(QTERMWIDGET_VERSION_MINOR "3")
set(QTERMWIDGET_VERSION_PATCH "0")
set(QTERMWIDGET_VERSION "${QTERMWIDGET_VERSION_MAJOR}.${QTERMWIDGET_VERSION_MINOR}.${QTERMWIDGET_VERSION_PATCH}")
# additional cmake files
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Minimum Versions
set(QT_MINIMUM_VERSION "5.15.0")
set(LXQTBT_MINIMUM_VERSION "0.13.0")
find_package(Qt5Widgets "${QT_MINIMUM_VERSION}" REQUIRED)
find_package(Qt5LinguistTools "${QT_MINIMUM_VERSION}" REQUIRED)
find_package(lxqt-build-tools ${LXQTBT_MINIMUM_VERSION} REQUIRED)
if(USE_UTF8PROC)
find_package(Utf8Proc REQUIRED)
endif()
include(LXQtPreventInSourceBuilds)
include(LXQtTranslateTs)
include(LXQtCompilerSettings NO_POLICY_SCOPE)
include(LXQtCreatePkgConfigFile)
if(APPLE)
if(CMAKE_VERSION VERSION_GREATER 3.9)
cmake_policy(SET CMP0068 NEW)
set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)
endif()
endif()
set(QTERMWIDGET_LIBRARY_NAME qtermwidget5)
# main library
set(SRCS
lib/BlockArray.cpp
lib/ColorScheme.cpp
lib/Emulation.cpp
lib/Filter.cpp
lib/History.cpp
lib/HistorySearch.cpp
lib/KeyboardTranslator.cpp
lib/konsole_wcwidth.cpp
lib/kprocess.cpp
lib/kpty.cpp
lib/kptydevice.cpp
lib/kptyprocess.cpp
lib/Pty.cpp
lib/qtermwidget.cpp
lib/Screen.cpp
lib/ScreenWindow.cpp
lib/SearchBar.cpp
lib/Session.cpp
lib/ShellCommand.cpp
lib/TerminalCharacterDecoder.cpp
lib/TerminalDisplay.cpp
lib/tools.cpp
lib/Vt102Emulation.cpp
)
# Only the Headers that need to be moc'd go here
set(HDRS
lib/Emulation.h
lib/Filter.h
lib/HistorySearch.h
lib/kprocess.h
lib/kptydevice.h
lib/kptyprocess.h
lib/Pty.h
lib/qtermwidget.h
lib/ScreenWindow.h
lib/SearchBar.h
lib/Session.h
lib/TerminalDisplay.h
lib/Vt102Emulation.h
)
set(UI
lib/SearchBar.ui
)
# for distribution
set(HDRS_DISTRIB
lib/qtermwidget.h
lib/Emulation.h
lib/KeyboardTranslator.h
lib/Filter.h
lib/qtermwidget_interface.h
)
# dirs
set(KB_LAYOUT_DIR "${CMAKE_INSTALL_FULL_DATADIR}/${QTERMWIDGET_LIBRARY_NAME}/kb-layouts")
message(STATUS "Keyboard layouts will be installed in: ${KB_LAYOUT_DIR}")
set(COLORSCHEMES_DIR "${CMAKE_INSTALL_FULL_DATADIR}/${QTERMWIDGET_LIBRARY_NAME}/color-schemes")
message(STATUS "Color schemes will be installed in: ${COLORSCHEMES_DIR}" )
set(TRANSLATIONS_DIR "${CMAKE_INSTALL_FULL_DATADIR}/${QTERMWIDGET_LIBRARY_NAME}/translations")
message(STATUS "Translations will be installed in: ${TRANSLATIONS_DIR}")
set(QTERMWIDGET_INCLUDE_DIR "${CMAKE_INSTALL_FULL_INCLUDEDIR}/${QTERMWIDGET_LIBRARY_NAME}")
CHECK_FUNCTION_EXISTS(updwtmpx HAVE_UPDWTMPX)
qt5_wrap_cpp(MOCS ${HDRS})
qt5_wrap_ui(UI_SRCS ${UI})
set(PKG_CONFIG_REQ "Qt5Widgets")
lxqt_translate_ts(QTERMWIDGET_QM
TRANSLATION_DIR "lib/translations"
UPDATE_TRANSLATIONS
${UPDATE_TRANSLATIONS}
SOURCES
${SRCS} ${HDRS} ${UI}
INSTALL_DIR
${TRANSLATIONS_DIR}
COMPONENT
Runtime
)
add_library(${QTERMWIDGET_LIBRARY_NAME} SHARED ${SRCS} ${MOCS} ${UI_SRCS} ${QTERMWIDGET_QM})
target_link_libraries(${QTERMWIDGET_LIBRARY_NAME} Qt5::Widgets)
set_target_properties( ${QTERMWIDGET_LIBRARY_NAME} PROPERTIES
SOVERSION ${QTERMWIDGET_VERSION_MAJOR}
VERSION ${QTERMWIDGET_VERSION}
)
if(APPLE)
target_compile_definitions(${QTERMWIDGET_LIBRARY_NAME}
PRIVATE
"HAVE_UTMPX"
"UTMPX_COMPAT"
)
endif()
if(HAVE_UPDWTMPX)
target_compile_definitions(${QTERMWIDGET_LIBRARY_NAME}
PRIVATE
"HAVE_UPDWTMPX"
)
endif()
if (QTERMWIDGET_USE_UTEMPTER)
CHECK_INCLUDE_FILE(utempter.h HAVE_UTEMPTER)
if (HAVE_UTEMPTER)
target_compile_definitions(${QTERMWIDGET_LIBRARY_NAME} PRIVATE
"HAVE_UTEMPTER"
)
find_library(UTEMPTER_LIB NAMES utempter ulog REQUIRED)
target_link_libraries(${QTERMWIDGET_LIBRARY_NAME} ${UTEMPTER_LIB})
endif()
endif()
if (UTF8PROC_FOUND)
target_compile_definitions(${QTERMWIDGET_LIBRARY_NAME}
PRIVATE
"HAVE_UTF8PROC"
)
target_include_directories(${QTERMWIDGET_LIBRARY_NAME}
INTERFACE
${UTF8PROC_INCLUDE_DIRS}
)
target_link_libraries(${QTERMWIDGET_LIBRARY_NAME}
${UTF8PROC_LIBRARIES}
)
string(APPEND PKG_CONFIG_REQ ", libutf8proc")
endif()
if(APPLE)
set (CMAKE_SKIP_RPATH 1)
# this is a must to load the lib correctly
set_target_properties(${QTERMWIDGET_LIBRARY_NAME} PROPERTIES INSTALL_NAME_DIR ${CMAKE_INSTALL_FULL_LIBDIR})
endif()
target_compile_definitions(${QTERMWIDGET_LIBRARY_NAME}
PRIVATE
"KB_LAYOUT_DIR=\"${KB_LAYOUT_DIR}\""
"COLORSCHEMES_DIR=\"${COLORSCHEMES_DIR}\""
"TRANSLATIONS_DIR=\"${TRANSLATIONS_DIR}\""
"HAVE_POSIX_OPENPT"
"HAVE_SYS_TIME_H"
)
generate_export_header(${QTERMWIDGET_LIBRARY_NAME}
EXPORT_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/lib/qtermwidget_export.h"
BASE_NAME QTERMWIDGET
)
target_include_directories(${QTERMWIDGET_LIBRARY_NAME}
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/lib>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/lib>"
INTERFACE
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${QTERMWIDGET_LIBRARY_NAME}>"
)
write_basic_package_version_file(
"${CMAKE_BINARY_DIR}/${QTERMWIDGET_LIBRARY_NAME}-config-version.cmake"
VERSION ${QTERMWIDGET_VERSION}
COMPATIBILITY AnyNewerVersion
)
install(FILES
"${CMAKE_BINARY_DIR}/${QTERMWIDGET_LIBRARY_NAME}-config-version.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${QTERMWIDGET_LIBRARY_NAME}"
COMPONENT Devel
)
install(EXPORT
"${QTERMWIDGET_LIBRARY_NAME}-targets"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${QTERMWIDGET_LIBRARY_NAME}"
COMPONENT Devel
)
install(FILES
${HDRS_DISTRIB} "${CMAKE_CURRENT_BINARY_DIR}/lib/qtermwidget_export.h" "${CMAKE_CURRENT_BINARY_DIR}/lib/qtermwidget_version.h"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${QTERMWIDGET_LIBRARY_NAME}"
COMPONENT Devel
)
# keyboard layouts
install(DIRECTORY
lib/kb-layouts/
DESTINATION "${KB_LAYOUT_DIR}"
COMPONENT Runtime
FILES_MATCHING PATTERN "*.keytab"
)
# color schemes
install(DIRECTORY
lib/color-schemes/
DESTINATION "${COLORSCHEMES_DIR}"
COMPONENT Runtime
FILES_MATCHING PATTERN "*.*schem*"
)
lxqt_create_pkgconfig_file(
PACKAGE_NAME ${QTERMWIDGET_LIBRARY_NAME}
DESCRIPTIVE_NAME ${QTERMWIDGET_LIBRARY_NAME}
DESCRIPTION "QTermWidget library for Qt ${QTERMWIDGET_VERSION_MAJOR}.x"
INCLUDEDIRS ${QTERMWIDGET_LIBRARY_NAME}
LIBS ${QTERMWIDGET_LIBRARY_NAME}
REQUIRES ${PKG_CONFIG_REQ}
VERSION ${QTERMWIDGET_VERSION}
INSTALL
COMPONENT Devel
)
configure_file(
"${PROJECT_SOURCE_DIR}/cmake/${QTERMWIDGET_LIBRARY_NAME}-config.cmake.in"
"${CMAKE_BINARY_DIR}/${QTERMWIDGET_LIBRARY_NAME}-config.cmake"
@ONLY
)
configure_file(
"${PROJECT_SOURCE_DIR}/lib/qtermwidget_version.h.in"
"${CMAKE_BINARY_DIR}/lib/qtermwidget_version.h"
@ONLY
)
install(FILES
"${CMAKE_BINARY_DIR}/${QTERMWIDGET_LIBRARY_NAME}-config.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${QTERMWIDGET_LIBRARY_NAME}"
COMPONENT Devel
)
install(TARGETS ${QTERMWIDGET_LIBRARY_NAME}
DESTINATION "${CMAKE_INSTALL_LIBDIR}"
EXPORT "${QTERMWIDGET_LIBRARY_NAME}-targets"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
PUBLIC_HEADER
COMPONENT Runtime
)
export(TARGETS ${QTERMWIDGET_LIBRARY_NAME}
FILE "${CMAKE_BINARY_DIR}/${QTERMWIDGET_LIBRARY_NAME}-targets.cmake"
EXPORT_LINK_INTERFACE_LIBRARIES
)
# end of main library
# example application
if(BUILD_EXAMPLE)
set(EXAMPLE_SRC examples/cpp/main.cpp)
add_executable(example ${EXAMPLE_SRC})
target_link_libraries(example ${QTERMWIDGET_LIBRARY_NAME})
endif()
# end of example application
# python binding
if (QTERMWIDGET_BUILD_PYTHON_BINDING)
message(SEND_ERROR "QTERMWIDGET_BUILD_PYTHON_BINDING is no longer supported. Check README.md for how to build PyQt bindings.")
endif()
# end of python binding
CONFIGURE_FILE(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY
)
ADD_CUSTOM_TARGET(uninstall
"${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
)