summaryrefslogtreecommitdiff
path: root/xT/CMakeLists.txt
blob: 56ab8350a2e65f3b6d2114e18058c76377590a42 (plain)
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
# As per Qt 6.8 documentation, at least 3.16 is necessary
cmake_minimum_required (VERSION 3.21.1)

file (READ ../xK-version project_version)
configure_file (../xK-version xK-version.tag COPYONLY)
string (STRIP "${project_version}" project_version)

# This is an entirely separate CMake project.
project (xT VERSION "${project_version}"
	DESCRIPTION "Qt frontend for xC" LANGUAGES CXX)

set (CMAKE_CXX_STANDARD 17)
set (CMAKE_CXX_STANDARD_REQUIRED ON)

find_package (Qt6 REQUIRED COMPONENTS Widgets Network Multimedia)
qt_standard_project_setup ()

add_compile_options ("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
add_compile_options ("$<$<CXX_COMPILER_ID:GNU>:-Wall;-Wextra>")
add_compile_options ("$<$<CXX_COMPILER_ID:Clang>:-Wall;-Wextra>")

set (project_config "${PROJECT_BINARY_DIR}/config.h")
configure_file ("${PROJECT_SOURCE_DIR}/config.h.in" "${project_config}")
include_directories ("${PROJECT_SOURCE_DIR}" "${PROJECT_BINARY_DIR}")

# Produce a beep sample
find_program (sox_EXECUTABLE sox REQUIRED)
set (beep "${PROJECT_BINARY_DIR}/beep.wav")
add_custom_command (OUTPUT "${beep}"
	COMMAND ${sox_EXECUTABLE} -b 16 -Dr 44100 -n "${beep}"
		synth 0.1 0 25 triangle 800 vol 0.5 fade t 0 -0 0.005 pad 0 0.05
	COMMENT "Generating a beep sample" VERBATIM)
set_property (SOURCE "${beep}" APPEND PROPERTY QT_RESOURCE_ALIAS beep.wav)

# Rasterize SVG icons
set (root "${PROJECT_SOURCE_DIR}/..")
set (CMAKE_MODULE_PATH "${root}/liberty/cmake")
include (IconUtils)

# It might generally be better to use QtSvg, though it is an extra dependency.
# The icon_to_png macro is not intended to be used like this.
foreach (icon xT xT-highlighted)
	icon_to_png (${icon} "${PROJECT_SOURCE_DIR}/${icon}.svg"
		48 "${PROJECT_BINARY_DIR}/resources" icon_png)
	set_property (SOURCE "${icon_png}"
		APPEND PROPERTY QT_RESOURCE_ALIAS "${icon}.png")
	list (APPEND icon_rsrc_list "${icon_png}")
endforeach ()

if (APPLE)
	set (MACOSX_BUNDLE_ICON_FILE xT.icns)
	icon_to_icns ("${PROJECT_SOURCE_DIR}/xT.svg"
		"${MACOSX_BUNDLE_ICON_FILE}" icon_icns)
else ()
	# The largest size is mainly for an appropriately sized Windows icon
	set (icon_base "${PROJECT_BINARY_DIR}/icons")
	set (icon_png_list)
	foreach (icon_size 16 32 48 256)
		icon_to_png (xT "${PROJECT_SOURCE_DIR}/xT.svg"
			${icon_size} "${icon_base}" icon_png)
		list (APPEND icon_png_list "${icon_png}")
	endforeach ()
	add_custom_target (icons ALL DEPENDS ${icon_png_list})
	if (WIN32)
		list (REMOVE_ITEM icon_png_list "${icon_png}")
		set (icon_ico "${PROJECT_BINARY_DIR}/xT.ico")
		icon_for_win32 ("${icon_ico}" "${icon_png_list}" "${icon_png}")

		set (resource_file "${PROJECT_BINARY_DIR}/xT.rc")
		list (APPEND project_sources "${resource_file}")
		add_custom_command (OUTPUT "${resource_file}"
			COMMAND ${CMAKE_COMMAND} -E echo "1 ICON \"xT.ico\""
				> ${resource_file} VERBATIM)
		set_property (SOURCE "${resource_file}"
			APPEND PROPERTY OBJECT_DEPENDS ${icon_ico})
	endif ()
endif ()

# Build the main executable and link it
find_program (awk_EXECUTABLE awk ${find_program_REQUIRE})
add_custom_command (OUTPUT xC-proto.cpp
	COMMAND ${CMAKE_COMMAND} -E env LC_ALL=C ${awk_EXECUTABLE}
		-f ${root}/liberty/tools/lxdrgen.awk
		-f ${root}/liberty/tools/lxdrgen-cpp.awk
		-v PrefixCamel=Relay
		${root}/xC.lxdr > xC-proto.cpp
	DEPENDS
		${root}/liberty/tools/lxdrgen.awk
		${root}/liberty/tools/lxdrgen-cpp.awk
		${root}/xC.lxdr
	COMMENT "Generating xC relay protocol code" VERBATIM)
add_custom_target (xC-proto DEPENDS ${PROJECT_BINARY_DIR}/xC-proto.cpp)

list (APPEND project_sources "${root}/liberty/tools/lxdrgen-cpp-qt.cpp")
qt_add_executable (xT
	xT.cpp ${project_config} ${project_sources} "${icon_icns}")
add_dependencies (xT xC-proto)
qt_add_resources (xT "rsrc" PREFIX / FILES "${beep}" ${icon_rsrc_list})
target_link_libraries (xT PRIVATE Qt6::Widgets Qt6::Network Qt6::Multimedia)
set_target_properties (xT PROPERTIES WIN32_EXECUTABLE ON MACOSX_BUNDLE ON
	MACOSX_BUNDLE_GUI_IDENTIFIER name.janouch.xT)

# https://stackoverflow.com/questions/79079161 and resolved in Qt Creator 16.
set (QT_QML_GENERATE_QMLLS_INI ON)

# The files to be installed
include (GNUInstallDirs)

if (ANDROID)
	install (TARGETS xT DESTINATION .)
elseif (APPLE OR WIN32)
	# TODO(p): Consider whether or not to use MSYS2.
	install (TARGETS xT DESTINATION .)
	# XXX: QTBUG-127075, which can be circumvented by manually running
	# macdeployqt on xT.app before the install.
	qt_generate_deploy_app_script (TARGET xT OUTPUT_SCRIPT deploy_xT)
	install (SCRIPT "${deploy_xT}")
else ()
	install (TARGETS xT DESTINATION ${CMAKE_INSTALL_BINDIR})
	install (FILES ../LICENSE DESTINATION ${CMAKE_INSTALL_DOCDIR})

	install (FILES xT.svg
		DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/scalable/apps)
	install (DIRECTORY ${icon_base}
		DESTINATION ${CMAKE_INSTALL_DATADIR})
	install (FILES xT.desktop
		DESTINATION ${CMAKE_INSTALL_DATADIR}/applications)
endif ()

# CPack
set (CPACK_PACKAGE_VENDOR "Premysl Eric Janouch")
set (CPACK_PACKAGE_CONTACT "Přemysl Eric Janouch <p@janouch.name>")
set (CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/../LICENSE")
set (CPACK_GENERATOR "TGZ;ZIP")
set (CPACK_PACKAGE_FILE_NAME
	"${PROJECT_NAME}-${PROJECT_VERSION}-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
set (CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME} ${PROJECT_VERSION}")
set (CPACK_SOURCE_GENERATOR "TGZ;ZIP")
set (CPACK_SOURCE_IGNORE_FILES "/build;/CMakeLists.txt.user")
set (CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}")

include (CPack)