summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cmake/QtBaseGlobalTargets.cmake10
-rw-r--r--cmake/QtBuild.cmake297
-rw-r--r--cmake/QtResource.cmake.in270
-rw-r--r--src/corelib/CMakeLists.txt5
-rw-r--r--src/corelib/Qt6CoreMacros.cmake59
5 files changed, 355 insertions, 286 deletions
diff --git a/cmake/QtBaseGlobalTargets.cmake b/cmake/QtBaseGlobalTargets.cmake
index f17b47f675..ecfb4429d2 100644
--- a/cmake/QtBaseGlobalTargets.cmake
+++ b/cmake/QtBaseGlobalTargets.cmake
@@ -229,3 +229,13 @@ qt_install(FILES
DESTINATION "${__build_internals_install_dir}"
COMPONENT Devel
)
+
+# Generate the new resource API
+set(QT_CORE_RESOURCE_GENERATED_FILE_NAME "${INSTALL_CMAKE_NAMESPACE}CoreResource.cmake" CACHE INTERNAL "")
+set(QT_CORE_RESOURCE_GENERATED_FILE_PATH "${CMAKE_CURRENT_BINARY_DIR}/${QT_CORE_RESOURCE_GENERATED_FILE_NAME}" CACHE INTERNAL "")
+configure_file(
+ "${CMAKE_CURRENT_SOURCE_DIR}/cmake/QtResource.cmake.in"
+ "${QT_CORE_RESOURCE_GENERATED_FILE_PATH}"
+ @ONLY
+)
+include(${QT_CORE_RESOURCE_GENERATED_FILE_PATH})
diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake
index 62c0d66561..5a3577d161 100644
--- a/cmake/QtBuild.cmake
+++ b/cmake/QtBuild.cmake
@@ -1156,7 +1156,7 @@ function(add_qt_module target)
qt_parse_all_arguments(arg "add_qt_module"
"NO_MODULE_HEADERS;STATIC;DISABLE_TOOLS_EXPORT;EXCEPTIONS;INTERNAL_MODULE;NO_SYNC_QT"
"CONFIG_MODULE_NAME"
- "${__default_private_args};${__default_public_args};QMAKE_MODULE_CONFIG" ${ARGN})
+ "${__default_private_args};${__default_public_args};QMAKE_MODULE_CONFIG;EXTRA_CMAKE_FILES;EXTRA_CMAKE_INCLUDES" ${ARGN})
if(NOT DEFINED arg_CONFIG_MODULE_NAME)
set(arg_CONFIG_MODULE_NAME "${module_lower}")
@@ -1345,6 +1345,13 @@ function(add_qt_module target)
list(APPEND extra_cmake_includes "${INSTALL_CMAKE_NAMESPACE}${target}ConfigExtras.cmake")
endif()
+ foreach(cmake_file IN LISTS arg_EXTRA_CMAKE_FILES)
+ get_filename_component(basename ${cmake_file} NAME)
+ file(COPY ${cmake_file} DESTINATION ${config_build_dir})
+ list(APPEND extra_cmake_files "${config_build_dir}/${basename}")
+ endforeach()
+ list(APPEND extra_cmake_includes ${arg_EXTRA_CMAKE_INCLUDES})
+
set(extra_cmake_code "")
if(target STREQUAL Core)
@@ -1365,7 +1372,6 @@ set(QT_CMAKE_EXPORT_NAMESPACE ${QT_CMAKE_EXPORT_NAMESPACE})")
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
-
qt_install(FILES
"${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}Config.cmake"
"${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}ConfigVersion.cmake"
@@ -1899,6 +1905,36 @@ function(qt_install_qml_files target)
endfunction()
+
+function(add_qt_resource target resourceName)
+ # Don't try to add resources when cross compiling, and the target is actually a host target
+ # (like a tool).
+ qt_is_imported_target("${target}" is_imported)
+ if(is_imported)
+ return()
+ endif()
+
+ qt_parse_all_arguments(arg "add_qt_resource" "" "PREFIX;LANG;BASE" "FILES" ${ARGN})
+
+ QT6_PROCESS_RESOURCE(${target} ${resourceName}
+ PREFIX "${arg_PREFIX}"
+ LANG "${arg_LANG}"
+ BASE "${arg_BASE}"
+ FILES ${arg_FILES}
+ OUTPUT_TARGET out_target
+ )
+
+ if (out_target)
+ qt_internal_add_target_aliases("${out_target}")
+ qt_install(TARGETS "${out_target}"
+ EXPORT "${INSTALL_CMAKE_NAMESPACE}${target}Targets"
+ DESTINATION ${INSTALL_LIBDIR}
+ )
+ endif()
+
+endfunction()
+
+
# This function creates a CMake target for qml modules. It will also make
# sure that if no C++ source are present, that qml files show up in the project
# in an IDE. Finally, it will also create a custom ${target}_qmltypes which
@@ -2443,8 +2479,6 @@ function(add_qt_tool name)
endif()
endfunction()
-
-
function(qt_create_tracepoints name tracePointsFile)
#### TODO
string(TOLOWER "${name}" name)
@@ -2453,261 +2487,6 @@ function(qt_create_tracepoints name tracePointsFile)
"#include <private/qtrace_p.h>")
endfunction()
-function(qt_get_relative_resource_path_for_file output_alias file)
- get_property(alias SOURCE ${file} PROPERTY QT_RESOURCE_ALIAS)
- if (NOT alias)
- set(alias "${file}")
- endif()
- set(${output_alias} ${alias} PARENT_SCOPE)
-endfunction()
-
-# Inspect all files passed to a call to add_qt_resource. If there are any
-# files present, invoke the quick compiler and return the remaining resource
-# files that have not been prossed in REMAING_RESOURCES as well as the new
-# name for the resource in OUTPUT_RESOURCE_NAME.
-function(qt_quick_compiler_process_resources target resource_name)
-
- qt_parse_all_arguments(arg "qt_qtuick_compiler_process_resources"
- "" "PREFIX;OUTPUT_REMAINING_RESOURCES;OUTPUT_RESOURCE_NAME" "FILES" ${ARGN}
- )
-
- set(qml_files)
- set(resource_files)
- set(retained_files)
- # scan for qml files
- foreach(file IN LISTS arg_FILES)
- # check whether this resource should not be processed by the qt quick
- # compiler
- get_source_file_property(skip_compiler_check ${file} QT_SKIP_QUICKCOMPILER)
- get_source_file_property(retain_compiler_check ${file} QT_RETAIN_QUICKCOMPILER)
- if (skip_compiler_check)
- list(APPEND resource_files ${file})
- continue()
- endif()
-
- if (${file} MATCHES "\.js$"
- OR ${file} MATCHES "\.mjs$"
- OR ${file} MATCHES "\.qml$")
- list(APPEND qml_files ${file})
- if (retain_compiler_check)
- list(APPEND retained_files ${file})
- list(APPEND resource_files ${file})
- endif()
- else()
- list(APPEND resource_files ${file})
- endif()
- endforeach()
- if (NOT TARGET ${QT_CMAKE_EXPORT_NAMESPACE}::qmlcachegen AND qml_files)
- message(WARNING "add_qt_resource: Qml files were detected but the qmlcachgen target is not defined. Consider adding QmlTools to your find_package command.")
- endif()
-
- set(retained_resource_paths)
- if (TARGET ${QT_CMAKE_EXPORT_NAMESPACE}::qmlcachegen AND qml_files)
- # Enable qt quick compiler support
- set(qml_resource_file "${CMAKE_CURRENT_BINARY_DIR}/${resource_name}.qrc")
- if (resource_files)
- set(chained_resource_name "${resource_name}_qmlcache")
- endif()
-
- foreach(file IN LISTS qml_files)
- get_filename_component(file_absolute ${file} ABSOLUTE)
- file(RELATIVE_PATH file_relative ${CMAKE_CURRENT_SOURCE_DIR} ${file_absolute})
- qt_get_relative_resource_path_for_file(file_resource_path ${file})
- if (arg_PREFIX STREQUAL "/")
- # TO_CMAKE_PATH does not clean up cases such as //Foo
- set(file_resource_path "/${file_resource_path}")
- else()
- set(file_resource_path "${arg_PREFIX}/${file_resource_path}")
- endif()
- if (file IN_LIST retained_files)
- list(APPEND retained_resource_paths ${file_resource_path})
- endif()
- file(TO_CMAKE_PATH ${file_resource_path} file_resource_path)
- list(APPEND file_resource_paths ${file_resource_path})
- string(REGEX REPLACE "\.js$" "_js" compiled_file ${file_relative})
- string(REGEX REPLACE "\.mjs$" "_mjs" compiled_file ${compiled_file})
- string(REGEX REPLACE "\.qml$" "_qml" compiled_file ${compiled_file})
- set(compiled_file "${CMAKE_CURRENT_BINARY_DIR}/qmlcache/${resource_name}/${compiled_file}.cpp")
- add_custom_command(
- OUTPUT ${compiled_file}
- DEPENDS ${file_absolute}
- COMMAND
- ${QT_CMAKE_EXPORT_NAMESPACE}::qmlcachegen
- --resource-path ${file_resource_path}
- -o ${compiled_file}
- ${file_absolute}
- )
- target_sources(${target} PRIVATE ${compiled_file})
- endforeach()
-
- set(qmlcache_loader_list "${CMAKE_CURRENT_BINARY_DIR}/qmlcache/${resource_name}/qml_loader_file_list.rsp")
- file(GENERATE
- OUTPUT ${qmlcache_loader_list}
- CONTENT "$<JOIN:${file_resource_paths},\n>"
- )
-
- set(qmlcache_loader_file "${CMAKE_CURRENT_BINARY_DIR}/qmlcache/${resource_name}/qmlcache_loader.cpp")
- set(resource_name_arg "${resource_name}.qrc")
- if (chained_resource_name)
- set(resource_name_arg "${resource_name_arg}=${chained_resource_name}")
- endif()
-
- if (retained_resource_paths)
- set(retained_loader_list "${CMAKE_CURRENT_BINARY_DIR}/qmlcache/${resource_name}/retained_file_list.rsp")
- file(GENERATE
- OUTPUT ${retained_loader_list}
- CONTENT "$<JOIN:${retained_resource_paths},\n>"
- )
- set(retained_args "--retain" "@${retained_loader_list}")
- endif()
-
- add_custom_command(
- OUTPUT ${qmlcache_loader_file}
- DEPENDS ${qmlcache_loader_list}
- COMMAND
- ${QT_CMAKE_EXPORT_NAMESPACE}::qmlcachegen
- ${retained_args}
- --resource-name "${resource_name_arg}"
- -o ${qmlcache_loader_file}
- "@${qmlcache_loader_list}"
- )
-
- qt_propagate_generated_resource(${target} ${resource_name} ${qmlcache_loader_file})
-
- if (resource_files)
- set(resource_name ${chained_resource_name})
- endif()
- else()
- set(resource_files ${arg_FILES})
- endif()
-
- set(${arg_OUTPUT_REMAINING_RESOURCES} ${resource_files} PARENT_SCOPE)
- set(${arg_OUTPUT_RESOURCE_NAME} ${resource_name} PARENT_SCOPE)
-
-endfunction()
-
-
-function(qt_propagate_generated_resource target resource_name generated_source_code)
- get_target_property(type ${target} TYPE)
- if(type STREQUAL STATIC_LIBRARY)
- set(resource_target "${target}_resources_${resourceName}")
- add_library("${resource_target}" OBJECT "${generated_source_code}")
- qt_internal_add_target_aliases("${resource_target}")
- qt_install(TARGETS "${resource_target}"
- EXPORT "${INSTALL_CMAKE_NAMESPACE}${target}Targets"
- DESTINATION ${INSTALL_LIBDIR}
- )
- target_link_libraries(${target} INTERFACE "$<TARGET_OBJECTS:${INSTALL_CMAKE_NAMESPACE}::${resource_target}>")
- else()
- target_sources(${target} PRIVATE ${generated_source_code})
- endif()
-endfunction()
-
-function(add_qt_resource target resourceName)
- # Don't try to add resources when cross compiling, and the target is actually a host target
- # (like a tool).
- qt_is_imported_target("${target}" is_imported)
- if(is_imported)
- return()
- endif()
-
- qt_parse_all_arguments(rcc "add_qt_resource" "" "PREFIX;LANG;BASE" "FILES" ${ARGN})
-
- string(REPLACE "/" "_" resourceName ${resourceName})
- string(REPLACE "." "_" resourceName ${resourceName})
-
- # Apply base to all files
- if (rcc_BASE)
- foreach(file IN LISTS rcc_FILES)
- set(resource_file "${rcc_BASE}/${file}")
- qt_get_relative_resource_path_for_file(alias ${resource_file})
- # Handle case where resources were generated from a directory
- # different than the one where the main .pro file resides.
- # Unless otherwise specified, we should use the original file path
- # as alias.
- if (alias STREQUAL resource_file)
- set_source_files_properties(${resource_file} PROPERTIES QT_RESOURCE_ALIAS ${file})
- endif()
- file(TO_CMAKE_PATH ${resource_file} resource_file)
- list(APPEND resource_files ${resource_file})
- endforeach()
- else()
- set(resource_files ${rcc_FILES})
- endif()
-
- if(NOT rcc_PREFIX)
- get_target_property(rcc_PREFIX ${target} QT_RESOURCE_PREFIX)
- if (NOT rcc_PREFIX)
- message(FATAL_ERROR "add_qt_resource() was called without a PREFIX and the target does not provide QT_RESOURCE_PREFIX. Please either add a PREFIX or make the target ${target} provide a default.")
- endif()
- endif()
-
- # Apply quick compiler pass
- qt_quick_compiler_process_resources(${target} ${resourceName}
- FILES ${resource_files}
- PREFIX ${rcc_PREFIX}
- OUTPUT_REMAINING_RESOURCES resources
- OUTPUT_RESOURCE_NAME newResourceName
- )
-
- if (NOT resources)
- return()
- endif()
- set(generatedResourceFile "${CMAKE_CURRENT_BINARY_DIR}/generated_${newResourceName}.qrc")
- set(generatedSourceCode "${CMAKE_CURRENT_BINARY_DIR}/qrc_${newResourceName}.cpp")
-
- # Generate .qrc file:
-
- # <RCC><qresource ...>
- set(qrcContents "<RCC>\n <qresource")
- if (rcc_PREFIX)
- string(APPEND qrcContents " prefix=\"${rcc_PREFIX}\"")
- endif()
- if (rcc_LANG)
- string(APPEND qrcContents " lang=\"${rcc_LANG}\"")
- endif()
- string(APPEND qrcContents ">\n")
-
- foreach(file IN LISTS resources)
- qt_get_relative_resource_path_for_file(file_resource_path ${file})
-
- if (NOT IS_ABSOLUTE ${file})
- set(file "${CMAKE_CURRENT_SOURCE_DIR}/${file}")
- endif()
-
- ### FIXME: escape file paths to be XML conform
- # <file ...>...</file>
- string(APPEND qrcContents " <file alias=\"${file_resource_path}\">")
- string(APPEND qrcContents "${file}</file>\n")
- list(APPEND files "${file}")
- endforeach()
-
- # </qresource></RCC>
- string(APPEND qrcContents " </qresource>\n</RCC>\n")
-
- file(GENERATE OUTPUT "${generatedResourceFile}" CONTENT "${qrcContents}")
-
- # Process .qrc file:
- add_custom_command(OUTPUT "${generatedSourceCode}"
- COMMAND "${QT_CMAKE_EXPORT_NAMESPACE}::rcc"
- ARGS --name "${newResourceName}"
- --output "${generatedSourceCode}" "${generatedResourceFile}"
- DEPENDS ${resources} ${generatedResourceFile}
- COMMENT "RCC ${newResourceName}"
- VERBATIM)
-
- get_target_property(type "${target}" TYPE)
- # Only do this if newResourceName is the same as resourceName, since
- # the resource will be chainloaded by the qt quickcompiler
- # qml cache loader
- if(newResourceName STREQUAL resourceName)
- qt_propagate_generated_resource(${target} ${resourceName} "${generatedSourceCode}")
- else()
- target_sources(${target} PRIVATE "${generatedSourceCode}")
- endif()
-endfunction()
-
-
# Handle files that need special SIMD-related flags.
# This creates an object library and makes target link
# to it (privately).
diff --git a/cmake/QtResource.cmake.in b/cmake/QtResource.cmake.in
new file mode 100644
index 0000000000..cc396fc319
--- /dev/null
+++ b/cmake/QtResource.cmake.in
@@ -0,0 +1,270 @@
+#
+# All things resource related
+#
+
+function(__qt_get_relative_resource_path_for_file output_alias file)
+ get_property(alias SOURCE ${file} PROPERTY QT_RESOURCE_ALIAS)
+ if (NOT alias)
+ set(alias "${file}")
+ endif()
+ set(${output_alias} ${alias} PARENT_SCOPE)
+endfunction()
+
+function(__qt_propagate_generated_resource target resource_name generated_source_code output_generated_target)
+ get_target_property(type ${target} TYPE)
+ if(type STREQUAL STATIC_LIBRARY)
+ set(resource_target "${target}_resources_${resourceName}")
+ add_library("${resource_target}" OBJECT "${generated_source_code}")
+ target_link_libraries(${target} INTERFACE "$<TARGET_OBJECTS:${resource_target}>")
+ set(${output_generated_target} "${resource_target}" PARENT_SCOPE)
+ else()
+ set(${output_generated_target} "" PARENT_SCOPE)
+ target_sources(${target} PRIVATE ${generated_source_code})
+ endif()
+endfunction()
+
+# Inspect all files passed to a call to add_qt_resource. If there are any
+# files present, invoke the quick compiler and return the remaining resource
+# files that have not been prossed in REMAING_RESOURCES as well as the new
+# name for the resource in OUTPUT_RESOURCE_NAME.
+function(__qt_quick_compiler_process_resources target resource_name)
+
+ cmake_parse_arguments(arg
+ "" "PREFIX;OUTPUT_REMAINING_RESOURCES;OUTPUT_RESOURCE_NAME;OUTPUT_GENERATED_TARGET" "FILES" ${ARGN}
+ )
+
+ set(qml_files)
+ set(resource_files)
+ set(retained_files)
+ # scan for qml files
+ foreach(file IN LISTS arg_FILES)
+ # check whether this resource should not be processed by the qt quick
+ # compiler
+ get_source_file_property(skip_compiler_check ${file} QT_SKIP_QUICKCOMPILER)
+ get_source_file_property(retain_compiler_check ${file} QT_RETAIN_QUICKCOMPILER)
+ if (skip_compiler_check)
+ list(APPEND resource_files ${file})
+ continue()
+ endif()
+
+ if (${file} MATCHES "\.js$"
+ OR ${file} MATCHES "\.mjs$"
+ OR ${file} MATCHES "\.qml$")
+ list(APPEND qml_files ${file})
+ if (retain_compiler_check)
+ list(APPEND retained_files ${file})
+ list(APPEND resource_files ${file})
+ endif()
+ else()
+ list(APPEND resource_files ${file})
+ endif()
+ endforeach()
+ if (NOT TARGET @QT_CMAKE_EXPORT_NAMESPACE@::qmlcachegen AND qml_files)
+ message(WARNING "QT@PROJECT_VERSION_MAJOR@_PROCESS_RESOURCE: Qml files were detected but the qmlcachgen target is not defined. Consider adding QmlTools to your find_package command.")
+ endif()
+
+ set(retained_resource_paths)
+ if (TARGET @QT_CMAKE_EXPORT_NAMESPACE@::qmlcachegen AND qml_files)
+ # Enable qt quick compiler support
+ set(qml_resource_file "${CMAKE_CURRENT_BINARY_DIR}/${resource_name}.qrc")
+ if (resource_files)
+ set(chained_resource_name "${resource_name}_qmlcache")
+ endif()
+
+ foreach(file IN LISTS qml_files)
+ get_filename_component(file_absolute ${file} ABSOLUTE)
+ file(RELATIVE_PATH file_relative ${CMAKE_CURRENT_SOURCE_DIR} ${file_absolute})
+ __qt_get_relative_resource_path_for_file(file_resource_path ${file})
+ if (arg_PREFIX STREQUAL "/")
+ # TO_CMAKE_PATH does not clean up cases such as //Foo
+ set(file_resource_path "/${file_resource_path}")
+ else()
+ set(file_resource_path "${arg_PREFIX}/${file_resource_path}")
+ endif()
+ if (file IN_LIST retained_files)
+ list(APPEND retained_resource_paths ${file_resource_path})
+ endif()
+ file(TO_CMAKE_PATH ${file_resource_path} file_resource_path)
+ list(APPEND file_resource_paths ${file_resource_path})
+ string(REGEX REPLACE "\.js$" "_js" compiled_file ${file_relative})
+ string(REGEX REPLACE "\.mjs$" "_mjs" compiled_file ${compiled_file})
+ string(REGEX REPLACE "\.qml$" "_qml" compiled_file ${compiled_file})
+ set(compiled_file "${CMAKE_CURRENT_BINARY_DIR}/qmlcache/${resource_name}/${compiled_file}.cpp")
+ add_custom_command(
+ OUTPUT ${compiled_file}
+ DEPENDS ${file_absolute}
+ COMMAND
+ @QT_CMAKE_EXPORT_NAMESPACE@::qmlcachegen
+ --resource-path ${file_resource_path}
+ -o ${compiled_file}
+ ${file_absolute}
+ )
+ target_sources(${target} PRIVATE ${compiled_file})
+ endforeach()
+
+ set(qmlcache_loader_list "${CMAKE_CURRENT_BINARY_DIR}/qmlcache/${resource_name}/qml_loader_file_list.rsp")
+ file(GENERATE
+ OUTPUT ${qmlcache_loader_list}
+ CONTENT "$<JOIN:${file_resource_paths},\n>"
+ )
+
+ set(qmlcache_loader_file "${CMAKE_CURRENT_BINARY_DIR}/qmlcache/${resource_name}/qmlcache_loader.cpp")
+ set(resource_name_arg "${resource_name}.qrc")
+ if (chained_resource_name)
+ set(resource_name_arg "${resource_name_arg}=${chained_resource_name}")
+ endif()
+
+ if (retained_resource_paths)
+ set(retained_loader_list "${CMAKE_CURRENT_BINARY_DIR}/qmlcache/${resource_name}/retained_file_list.rsp")
+ file(GENERATE
+ OUTPUT ${retained_loader_list}
+ CONTENT "$<JOIN:${retained_resource_paths},\n>"
+ )
+ set(retained_args "--retain" "@${retained_loader_list}")
+ endif()
+
+ add_custom_command(
+ OUTPUT ${qmlcache_loader_file}
+ DEPENDS ${qmlcache_loader_list}
+ COMMAND
+ @QT_CMAKE_EXPORT_NAMESPACE@::qmlcachegen
+ ${retained_args}
+ --resource-name "${resource_name_arg}"
+ -o ${qmlcache_loader_file}
+ "@${qmlcache_loader_list}"
+ )
+
+ __qt_propagate_generated_resource(${target}
+ ${resource_name}
+ ${qmlcache_loader_file}
+ output_target)
+
+ set(${arg_OUTPUT_GENERATED_TARGET} "${output_target}" PARENT_SCOPE)
+
+ if (resource_files)
+ set(resource_name ${chained_resource_name})
+ endif()
+ else()
+ set(resource_files ${arg_FILES})
+ endif()
+
+ set(${arg_OUTPUT_REMAINING_RESOURCES} ${resource_files} PARENT_SCOPE)
+ set(${arg_OUTPUT_RESOURCE_NAME} ${resource_name} PARENT_SCOPE)
+
+endfunction()
+
+#
+# Process resources via file path instead of QRC files. Behind the
+# scnenes, it will generate a qrc file and apply post processing steps
+# when applicable. (e.g.: QtQuickCompiler)
+#
+# The QRC Prefix is set via the PREFIX parameter.
+#
+# Alias settings for files need to be set via the QT_RESOURCE_ALIAS property
+# via the set_soure_files_properties() command.
+#
+# When using this command with static libraries, a special target will be
+# generated. Should you wish to perform additional processing on said target
+# pass a value to the OUTPUT_TARGET parameter.
+#
+function(QT@PROJECT_VERSION_MAJOR@_PROCESS_RESOURCE target resourceName)
+
+ cmake_parse_arguments(rcc "" "PREFIX;LANG;BASE;OUTPUT_TARGET" "FILES" ${ARGN})
+
+ string(REPLACE "/" "_" resourceName ${resourceName})
+ string(REPLACE "." "_" resourceName ${resourceName})
+
+ # Apply base to all files
+ if (rcc_BASE)
+ foreach(file IN LISTS rcc_FILES)
+ set(resource_file "${rcc_BASE}/${file}")
+ __qt_get_relative_resource_path_for_file(alias ${resource_file})
+ # Handle case where resources were generated from a directory
+ # different than the one where the main .pro file resides.
+ # Unless otherwise specified, we should use the original file path
+ # as alias.
+ if (alias STREQUAL resource_file)
+ set_source_files_properties(${resource_file} PROPERTIES QT_RESOURCE_ALIAS ${file})
+ endif()
+ file(TO_CMAKE_PATH ${resource_file} resource_file)
+ list(APPEND resource_files ${resource_file})
+ endforeach()
+ else()
+ set(resource_files ${rcc_FILES})
+ endif()
+
+ if(NOT rcc_PREFIX)
+ get_target_property(rcc_PREFIX ${target} QT_RESOURCE_PREFIX)
+ if (NOT rcc_PREFIX)
+ message(FATAL_ERROR "QT@PROJECT_VERSION_MAJOR@_PROCESS_RESOURCE() was called without a PREFIX and the target does not provide QT_RESOURCE_PREFIX. Please either add a PREFIX or make the target ${target} provide a default.")
+ endif()
+ endif()
+
+ # Apply quick compiler pass
+ __qt_quick_compiler_process_resources(${target} ${resourceName}
+ FILES ${resource_files}
+ PREFIX ${rcc_PREFIX}
+ OUTPUT_REMAINING_RESOURCES resources
+ OUTPUT_RESOURCE_NAME newResourceName
+ OUTPUT_GENERATED_TARGET output_target
+ )
+
+ if (NOT resources)
+ return()
+ endif()
+ set(generatedResourceFile "${CMAKE_CURRENT_BINARY_DIR}/generated_${newResourceName}.qrc")
+ set(generatedSourceCode "${CMAKE_CURRENT_BINARY_DIR}/qrc_${newResourceName}.cpp")
+
+ # Generate .qrc file:
+
+ # <RCC><qresource ...>
+ set(qrcContents "<RCC>\n <qresource")
+ if (rcc_PREFIX)
+ string(APPEND qrcContents " prefix=\"${rcc_PREFIX}\"")
+ endif()
+ if (rcc_LANG)
+ string(APPEND qrcContents " lang=\"${rcc_LANG}\"")
+ endif()
+ string(APPEND qrcContents ">\n")
+
+ foreach(file IN LISTS resources)
+ __qt_get_relative_resource_path_for_file(file_resource_path ${file})
+
+ if (NOT IS_ABSOLUTE ${file})
+ set(file "${CMAKE_CURRENT_SOURCE_DIR}/${file}")
+ endif()
+
+ ### FIXME: escape file paths to be XML conform
+ # <file ...>...</file>
+ string(APPEND qrcContents " <file alias=\"${file_resource_path}\">")
+ string(APPEND qrcContents "${file}</file>\n")
+ list(APPEND files "${file}")
+ endforeach()
+
+ # </qresource></RCC>
+ string(APPEND qrcContents " </qresource>\n</RCC>\n")
+
+ file(GENERATE OUTPUT "${generatedResourceFile}" CONTENT "${qrcContents}")
+
+ # Process .qrc file:
+ add_custom_command(OUTPUT "${generatedSourceCode}"
+ COMMAND "@QT_CMAKE_EXPORT_NAMESPACE@::rcc"
+ ARGS --name "${newResourceName}"
+ --output "${generatedSourceCode}" "${generatedResourceFile}"
+ DEPENDS ${resources} ${generatedResourceFile}
+ COMMENT "RCC ${newResourceName}"
+ VERBATIM)
+
+ get_target_property(type "${target}" TYPE)
+ # Only do this if newResourceName is the same as resourceName, since
+ # the resource will be chainloaded by the qt quickcompiler
+ # qml cache loader
+ if(newResourceName STREQUAL resourceName)
+ __qt_propagate_generated_resource(${target} ${resourceName} "${generatedSourceCode}" output_target)
+ else()
+ target_sources(${target} PRIVATE "${generatedSourceCode}")
+ endif()
+ if (arg_OUTPUT_TARGET)
+ set(${arg_OUPUT_TARGET} "${output_target}" PARENT_SCOPE)
+ endif()
+endfunction()
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 ... )