1include(CMakeParseArguments) 2 3function(QTQUICK_COMPILER_DETERMINE_OUTPUT_FILENAME outvariable filename) 4 file(RELATIVE_PATH relpath ${CMAKE_CURRENT_SOURCE_DIR} ${filename}) 5 string(REPLACE \".qml\" \"_qml\" relpath ${relpath}) 6 string(REPLACE \".js\" \"_js\" relpath ${relpath}) 7 string(REPLACE \".mjs\" \"_mjs\" relpath ${relpath}) 8 string(REPLACE \"/\" \"_\" relpath ${relpath}) 9 set(${outvariable} ${CMAKE_CURRENT_BINARY_DIR}/${relpath}.cpp PARENT_SCOPE) 10endfunction() 11 12function(QTQUICK_COMPILER_ADD_RESOURCES outfiles) 13 set(options) 14 set(oneValueArgs) 15 set(multiValueArgs OPTIONS) 16 17 cmake_parse_arguments(_RCC \"${options}\" \"${oneValueArgs}\" \"${multiValueArgs}\" ${ARGN}) 18 19 find_package(Qt5 COMPONENTS Qml Core) 20 21!!IF isEmpty(CMAKE_BIN_DIR_IS_ABSOLUTE) 22 set(compiler_path \"${_qt5Core_install_prefix}/$${CMAKE_BIN_DIR}qmlcachegen$$CMAKE_BIN_SUFFIX\") 23!!ELSE 24 set(compiler_path \"$${CMAKE_BIN_DIR}qmlcachegen$$CMAKE_BIN_SUFFIX\") 25!!ENDIF 26 if(NOT EXISTS \"${compiler_path}\" ) 27 message(FATAL_ERROR \"The package \\\"Qt5QuickCompilerConfig\\\" references the file 28 \\\"${compiler_path}\\\" 29but this file does not exist. Possible reasons include: 30* The file was deleted, renamed, or moved to another location. 31* An install or uninstall procedure did not complete successfully. 32* The installation package was faulty and contained 33 \\\"${CMAKE_CURRENT_LIST_FILE}\\\" 34but not all the files it references. 35\") 36 endif() 37 38 get_target_property(rcc_path ${Qt5Core_RCC_EXECUTABLE} IMPORTED_LOCATION) 39 40 set(rcc_files ${_RCC_UNPARSED_ARGUMENTS}) 41 set(rcc_options ${_RCC_OPTIONS}) 42 set(filtered_rcc_files) 43 set(compiler_output) 44 set(rcc_files_with_compilation_units) 45 set(loader_flags) 46 47 foreach(_resource ${rcc_files}) 48 get_filename_component(resource_base ${_resource} NAME_WE) 49 set(new_resource_file ${CMAKE_CURRENT_BINARY_DIR}/${resource_base}_qmlcache.qrc) 50 51 get_filename_component(input_resource ${_resource} ABSOLUTE) 52 set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${input_resource}") 53 54 execute_process(COMMAND ${compiler_path} --filter-resource-file ${input_resource} -o ${new_resource_file} OUTPUT_VARIABLE remaining_files) 55 list(APPEND filtered_rcc_files ${new_resource_file}) 56 list(APPEND loader_flags \"--resource-file-mapping=${_resource}=${new_resource_file}\") 57 58 set(rcc_file_with_compilation_units) 59 60 execute_process(COMMAND ${rcc_path} -list \"${input_resource}\" OUTPUT_VARIABLE rcc_contents) 61 if (NOT rcc_contents STREQUAL \"\") 62 string(REGEX REPLACE \"[\r\n]+\" \";\" rcc_contents ${rcc_contents}) 63 foreach(it ${rcc_contents}) 64 get_filename_component(extension ${it} EXT) 65 if(extension STREQUAL \".qml\" OR extension STREQUAL \".js\" OR extension STREQUAL \".ui.qml\" OR extension STREQUAL \".mjs\") 66 qtquick_compiler_determine_output_filename(output_file ${it}) 67 add_custom_command(OUTPUT ${output_file} 68 COMMAND ${compiler_path} 69 ARGS --resource=${input_resource} ${it} -o ${output_file} 70 DEPENDS ${it} ${input_resource}) 71 list(APPEND compiler_output ${output_file}) 72 set(rcc_file_with_compilation_units ${input_resource}) 73 endif() 74 endforeach() 75 endif() 76 77 if(rcc_file_with_compilation_units) 78 list(APPEND rcc_files_with_compilation_units ${rcc_file_with_compilation_units}) 79 endif() 80 endforeach() 81 82 if(rcc_files_with_compilation_units) 83 set(loader_source ${CMAKE_CURRENT_BINARY_DIR}/qmlcache_loader.cpp) 84 add_custom_command(OUTPUT ${loader_source} COMMAND ${compiler_path} ARGS ${loader_flags} ${rcc_files_with_compilation_units} -o ${loader_source} DEPENDS ${rcc_files_with_compilation_units}) 85 list(APPEND compiler_output ${loader_source}) 86 endif() 87 88 qt5_add_resources(output_resources ${filtered_rcc_files} OPTIONS ${rcc_options}) 89 set(${outfiles} ${output_resources} ${compiler_output} PARENT_SCOPE) 90endfunction() 91