summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLeander Beernaert <leander.beernaert@qt.io>2019-08-19 16:19:08 +0200
committerLeander Beernaert <leander.beernaert@qt.io>2019-08-22 09:47:01 +0000
commit7a1853dbe2a3e316900ed1daf9f05deb37413d72 (patch)
tree882208a1912a5ab80c4c25ec7265fb8502d4305d /src
parent3cb9ee3a5b36e2c10dbaf1564852472e7e02a1ae (diff)
Extract add_qt_resource into reusable components
This patch moves all of the underlying code for add_qt_resource into a common reusable snippet for both the Qt build and user projects. For users, the new API is available under QT5_ADD_RESOURCES. If outfiles is a CMAKE target we will use the new API, otherwise we will fall back to the old behavior. This patch also adds EXTRA_CMAKE_FILES and EXTRA_CMAKE_INCLUDES to add_qt_module so that module specific cmake files can be installed and loaded by the module's config.cmake. The code will be installed under CMAKE_BINARY_DIR/Qt{}CoreResource.cmake and is injected into Qt{}Core_Config.cmake via the extra cmake includes passed into add_qt_module. To make sure it still works with QtBuild, we do the actual generation of the file from QtBaseGlobalTargets and include the generated file there as well. Change-Id: I85fefaa11dde01a6790d23c62d6a64cd157e2617 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/CMakeLists.txt5
-rw-r--r--src/corelib/Qt6CoreMacros.cmake59
2 files changed, 37 insertions, 27 deletions
diff --git a/src/corelib/CMakeLists.txt b/src/corelib/CMakeLists.txt
index 8d676e1be0..2959939458 100644
--- a/src/corelib/CMakeLists.txt
+++ b/src/corelib/CMakeLists.txt
@@ -250,6 +250,11 @@ add_qt_module(Core
PUBLIC_LIBRARIES # special case:
Qt::Platform # special case:
DISABLE_TOOLS_EXPORT # special case:
+ # special case begin
+ # Generated in QtBaseGlobalTargets
+ EXTRA_CMAKE_FILES ${QT_CORE_RESOURCE_GENERATED_FILE_PATH}
+ EXTRA_CMAKE_INCLUDES ${QT_CORE_RESOURCE_GENERATED_FILE_NAME}
+ # special case end
)
# special case begin
diff --git a/src/corelib/Qt6CoreMacros.cmake b/src/corelib/Qt6CoreMacros.cmake
index d5eb346871..52718cc824 100644
--- a/src/corelib/Qt6CoreMacros.cmake
+++ b/src/corelib/Qt6CoreMacros.cmake
@@ -256,41 +256,46 @@ function(QT5_ADD_BINARY_RESOURCES target )
endfunction()
+# qt5_add_resources(target resourcename ...
+# or
# qt5_add_resources(outfiles inputfile ... )
function(QT5_ADD_RESOURCES outfiles )
+ if (TARGET ${outfiles})
+ QT6_PROCESS_RESOURCE(${ARGV})
+ else()
+ set(options)
+ set(oneValueArgs)
+ set(multiValueArgs OPTIONS)
- set(options)
- set(oneValueArgs)
- set(multiValueArgs OPTIONS)
+ cmake_parse_arguments(_RCC "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
- cmake_parse_arguments(_RCC "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+ set(rcc_files ${_RCC_UNPARSED_ARGUMENTS})
+ set(rcc_options ${_RCC_OPTIONS})
- set(rcc_files ${_RCC_UNPARSED_ARGUMENTS})
- set(rcc_options ${_RCC_OPTIONS})
+ if("${rcc_options}" MATCHES "-binary")
+ message(WARNING "Use qt5_add_binary_resources for binary option")
+ endif()
- if("${rcc_options}" MATCHES "-binary")
- message(WARNING "Use qt5_add_binary_resources for binary option")
+ foreach(it ${rcc_files})
+ get_filename_component(outfilename ${it} NAME_WE)
+ get_filename_component(infile ${it} ABSOLUTE)
+ set(outfile ${CMAKE_CURRENT_BINARY_DIR}/qrc_${outfilename}.cpp)
+
+ _QT5_PARSE_QRC_FILE(${infile} _out_depends _rc_depends)
+ set_source_files_properties(${infile} PROPERTIES SKIP_AUTORCC ON)
+
+ add_custom_command(OUTPUT ${outfile}
+ COMMAND ${QT_CMAKE_EXPORT_NAMESPACE}::rcc
+ ARGS ${rcc_options} --name ${outfilename} --output ${outfile} ${infile}
+ MAIN_DEPENDENCY ${infile}
+ DEPENDS ${_rc_depends} "${_out_depends}" VERBATIM)
+ set_source_files_properties(${outfile} PROPERTIES SKIP_AUTOMOC ON)
+ set_source_files_properties(${outfile} PROPERTIES SKIP_AUTOUIC ON)
+ list(APPEND ${outfiles} ${outfile})
+ endforeach()
+ set(${outfiles} ${${outfiles}} PARENT_SCOPE)
endif()
-
- foreach(it ${rcc_files})
- get_filename_component(outfilename ${it} NAME_WE)
- get_filename_component(infile ${it} ABSOLUTE)
- set(outfile ${CMAKE_CURRENT_BINARY_DIR}/qrc_${outfilename}.cpp)
-
- _QT5_PARSE_QRC_FILE(${infile} _out_depends _rc_depends)
- set_source_files_properties(${infile} PROPERTIES SKIP_AUTORCC ON)
-
- add_custom_command(OUTPUT ${outfile}
- COMMAND ${QT_CMAKE_EXPORT_NAMESPACE}::rcc
- ARGS ${rcc_options} --name ${outfilename} --output ${outfile} ${infile}
- MAIN_DEPENDENCY ${infile}
- DEPENDS ${_rc_depends} "${_out_depends}" VERBATIM)
- set_source_files_properties(${outfile} PROPERTIES SKIP_AUTOMOC ON)
- set_source_files_properties(${outfile} PROPERTIES SKIP_AUTOUIC ON)
- list(APPEND ${outfiles} ${outfile})
- endforeach()
- set(${outfiles} ${${outfiles}} PARENT_SCOPE)
endfunction()
# qt5_add_big_resources(outfiles inputfile ... )