CMake build: Add a qtc_glob_resources function

This is the CMake equivalent of "RESOURCES = $$files()" from qmake.

Use it in StudioWelcome for the Qml resources.

Change-Id: I2f495e2c4bad9f0bb488dee7e8966e31acb51b5a
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
Alessandro Portale
2020-02-24 15:56:12 +01:00
parent ca2dd71d77
commit 3a29497717
3 changed files with 22 additions and 7 deletions

View File

@@ -1124,3 +1124,16 @@ function(finalize_qtc_gtest test_name)
finalize_test_setup(${test}) finalize_test_setup(${test})
endforeach() endforeach()
endfunction() endfunction()
# This is the CMake equivalent of "RESOURCES = $$files()" from qmake
function(qtc_glob_resources)
cmake_parse_arguments(_arg "" "QRC_FILE;ROOT;GLOB" "" ${ARGN})
file(GLOB_RECURSE fileList RELATIVE "${_arg_ROOT}" "${_arg_ROOT}/${_arg_GLOB}")
set(qrcData "<RCC><qresource>\n")
foreach(file IN LISTS fileList)
string(APPEND qrcData " <file alias=\"${file}\">${_arg_ROOT}/${file}</file>\n")
endforeach()
string(APPEND qrcData "</qresource></RCC>")
file(WRITE "${_arg_QRC_FILE}" "${qrcData}")
endfunction()

View File

@@ -1,3 +1,11 @@
set(qmlQrcFile "${CMAKE_CURRENT_BINARY_DIR}/StudioWelcome_qml.qrc")
qtc_glob_resources(
QRC_FILE "${qmlQrcFile}"
ROOT "${CMAKE_CURRENT_SOURCE_DIR}"
GLOB "qml/*.*"
)
add_qtc_plugin(StudioWelcome add_qtc_plugin(StudioWelcome
DEPENDS Qt5::QuickWidgets DEPENDS Qt5::QuickWidgets
PLUGIN_DEPENDS Core ProjectExplorer QtSupport PLUGIN_DEPENDS Core ProjectExplorer QtSupport
@@ -6,7 +14,7 @@ add_qtc_plugin(StudioWelcome
studiowelcomeplugin.cpp studiowelcomeplugin.h studiowelcomeplugin.cpp studiowelcomeplugin.h
studiowelcome_global.h studiowelcome_global.h
studiowelcome.qrc studiowelcome.qrc
studiowelcome_qml.qrc ${qmlQrcFile}
"${PROJECT_SOURCE_DIR}/src/share/3rdparty/studiofonts/studiofonts.qrc" "${PROJECT_SOURCE_DIR}/src/share/3rdparty/studiofonts/studiofonts.qrc"
EXTRA_TRANSLATIONS EXTRA_TRANSLATIONS
qml qml

View File

@@ -1,6 +0,0 @@
<!-- This file is the CMake equivalent of "RESOURCES = $$files(qml/*)" in studiowelcome.pro -->
<RCC>
<qresource>
<file>qml/</file>
</qresource>
</RCC>