aboutsummaryrefslogtreecommitdiff
path: root/xT/CMakeLists.txt
blob: 8157805cb558e451042dab02e9410014c0e2c03f (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
# 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 ()

# 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 ()

# 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})
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)

# At least with MinGW, this is a fully independent portable executable
# TODO(p): Figure this out once it builds.
install (TARGETS xT DESTINATION .)
set (CPACK_GENERATOR ZIP)
include (CPack)