Using generated QRC file with cmake
-
Hi,
I'm using Qt6 via cmake and I generate my QRC file using a python script, like below:
set(out_file "${CMAKE_CURRENT_BINARY_DIR}/resources.qrc") add_custom_command( OUTPUT ${out_file} COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/gen-qt-resources-xml.py ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${APPDATA_FILE} ${out_file} DEPENDS ${ui_files} appdata-xml-merged COMMENT "Generating resources.qrc" )Then I do
qt_add_resources(zrythm "resources" FILES ${out_file})But this doesn't work (I get the error below), and I have no way to tell QT that there is a dependency on the generated file.
[cmake] CMake Error at /home/alex/opt/Qt6.7.2/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:1758 (message): [cmake] The source file [cmake] '/home/alex/Documents/git/zrythm/builddir_cmake/resources/resources.qrc' [cmake] was specified with an absolute path and is used in a Qt resource. Please [cmake] set the QT_RESOURCE_ALIAS property on that source file to a relative path [cmake] to make the file properly accessible via the resource system. [cmake] Call Stack (most recent call first): [cmake] /home/alex/opt/Qt6.7.2/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:2231 (__qt_get_relative_resource_path_for_file) [cmake] /home/alex/opt/Qt6.7.2/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:337 (_qt_internal_process_resource) [cmake] /home/alex/opt/Qt6.7.2/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:389 (qt6_add_resources) [cmake] resources/CMakeLists.txt:90 (qt_add_resources) [cmake] [cmake] [cmake] -- Configuring incomplete, errors occurred!Is this possible to do at all?
-
Why do you want to add a resource file to a Qt resource? Because this is what you're doing - see the documentation.
You either want
qt_add_resources(SOURCES example.qrc)or simply add the generated resource file to your target sources and make sure CMAKE_AUTORCC is on (which should be by default for qt projects iirc). -
I was indeed using the wrong variant. I'm not sure if that variant works with a generated .qrc file either, but I ended up just globbing the actual files and adding them to the FILES option, since that's what I was basically doing in my python script (I was globbing the files and outputing them in .qrc format). Thanks anyway
-
A alex-zrythm has marked this topic as solved on