165 lines
6.1 KiB
CMake
165 lines
6.1 KiB
CMake
# 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)
|
|
install (TARGETS xT
|
|
BUNDLE DESTINATION .
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
|
|
|
# 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 ()
|
|
|
|
# Within MSYS2, windeployqt doesn't copy the compiler runtime,
|
|
# which is always linked dynamically by the Qt binaries.
|
|
# TODO(p): Consider whether or not to use MSYS2 to cross-compile, and how.
|
|
if (WIN32)
|
|
install (CODE [=[
|
|
set (bindir "${CMAKE_INSTALL_PREFIX}/bin")
|
|
execute_process (COMMAND cygpath -m /
|
|
OUTPUT_VARIABLE cygroot OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
if (cygroot)
|
|
execute_process (COMMAND ldd "${bindir}/xT.exe"
|
|
OUTPUT_VARIABLE ldd_output OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
string (REGEX MATCHALL " /mingw64/bin/[^ ]+ " libs "${ldd_output}")
|
|
foreach (lib ${libs})
|
|
string (STRIP "${lib}" lib)
|
|
file (COPY "${cygroot}${lib}" DESTINATION "${bindir}")
|
|
endforeach()
|
|
endif ()
|
|
]=])
|
|
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)
|