diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2024-12-03 15:25:21 +0100 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2024-12-15 06:57:28 +0100 |
commit | 918c589c657be0c0885610d2eaafcd21a3ab1ba9 (patch) | |
tree | 81b5d4429c9fd5f543192635443e8a12728bdf0c /xT/CMakeLists.txt | |
parent | 21095a11d60ef7c1a2d72dca60f90faf640965e6 (diff) | |
download | xK-918c589c657be0c0885610d2eaafcd21a3ab1ba9.tar.gz xK-918c589c657be0c0885610d2eaafcd21a3ab1ba9.tar.xz xK-918c589c657be0c0885610d2eaafcd21a3ab1ba9.zip |
Add a Qt Widgets frontend to xC
This is very much a work in progress, though functional.
Qt Widgets are basically non-working on Android,
though Qt Quick requires a radically different approach.
Diffstat (limited to 'xT/CMakeLists.txt')
-rw-r--r-- | xT/CMakeLists.txt | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/xT/CMakeLists.txt b/xT/CMakeLists.txt new file mode 100644 index 0000000..8157805 --- /dev/null +++ b/xT/CMakeLists.txt @@ -0,0 +1,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) |