diff options
author | Simon Hausmann <[email protected]> | 2018-02-14 16:47:57 +0100 |
---|---|---|
committer | Simon Hausmann <[email protected]> | 2018-02-15 14:59:45 +0000 |
commit | ee3fe11b023ac3dfb449156db1d3732a70e3ff32 (patch) | |
tree | ca4ef15e153cd8418811f69cbf1292015c91de4f | |
parent | 16ca5eab9bdd31774dc8e657f217e044640eecff (diff) |
Add support for qtquick_compiler_add_resources with cmake builds
Change-Id: I2addc2442c51bde6a854e5e9bbb79032e1c9f9bf
Reviewed-by: Lars Knoll <[email protected]>
-rw-r--r-- | tests/auto/cmake/CMakeLists.txt | 11 | ||||
-rw-r--r-- | tests/auto/cmake/qtquickcompiler/CMakeLists.txt | 14 | ||||
-rw-r--r-- | tests/auto/cmake/qtquickcompiler/main.cpp | 9 | ||||
-rw-r--r-- | tests/auto/cmake/qtquickcompiler/main.qml | 4 | ||||
-rw-r--r-- | tests/auto/cmake/qtquickcompiler/qqc_test.qrc | 6 | ||||
-rw-r--r-- | tools/qmlcachegen/Qt5QuickCompilerConfig.cmake | 73 | ||||
-rw-r--r-- | tools/qmlcachegen/qmlcachegen.pro | 5 |
7 files changed, 122 insertions, 0 deletions
diff --git a/tests/auto/cmake/CMakeLists.txt b/tests/auto/cmake/CMakeLists.txt index 4b9fbe75ac..4d4d8e3db7 100644 --- a/tests/auto/cmake/CMakeLists.txt +++ b/tests/auto/cmake/CMakeLists.txt @@ -15,3 +15,14 @@ test_module_includes( ) expect_pass(test_plugins) + +add_test(qtquickcompiler ${CMAKE_CTEST_COMMAND} + --build-and-test + "${CMAKE_CURRENT_SOURCE_DIR}/qtquickcompiler/" + "${CMAKE_CURRENT_BINARY_DIR}/qtquickcompiler" + --build-config "${CMAKE_BUILD_TYPE}" + --build-generator ${CMAKE_GENERATOR} + --build-makeprogram ${CMAKE_MAKE_PROGRAM} + --build-project qqc_test + --build-options "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" ${BUILD_OPTIONS_LIST} +) diff --git a/tests/auto/cmake/qtquickcompiler/CMakeLists.txt b/tests/auto/cmake/qtquickcompiler/CMakeLists.txt new file mode 100644 index 0000000000..6dee1e25dc --- /dev/null +++ b/tests/auto/cmake/qtquickcompiler/CMakeLists.txt @@ -0,0 +1,14 @@ + +cmake_minimum_required(VERSION 2.8) +project(qqc_test) + +find_package(Qt5Qml 5.0.0 REQUIRED) +find_package(Qt5Gui 5.0.0 REQUIRED) +find_package(Qt5QuickCompiler) + +set(CMAKE_CXXFLAGS "${CMAKE_CXXFLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}") + +qtquick_compiler_add_resources(RESOURCES qqc_test.qrc) + +add_executable(qqc_test "${CMAKE_CURRENT_SOURCE_DIR}/main.cpp" ${RESOURCES}) +target_link_libraries(qqc_test Qt5::Gui Qt5::Qml) diff --git a/tests/auto/cmake/qtquickcompiler/main.cpp b/tests/auto/cmake/qtquickcompiler/main.cpp new file mode 100644 index 0000000000..47fc709c0a --- /dev/null +++ b/tests/auto/cmake/qtquickcompiler/main.cpp @@ -0,0 +1,9 @@ + +#include <QtGui> +#include <QtQml> + +int main(int argc, char **argv) +{ + QGuiApplication app(argc, argv); + return app.exec(); +} diff --git a/tests/auto/cmake/qtquickcompiler/main.qml b/tests/auto/cmake/qtquickcompiler/main.qml new file mode 100644 index 0000000000..1f146d89c3 --- /dev/null +++ b/tests/auto/cmake/qtquickcompiler/main.qml @@ -0,0 +1,4 @@ +import QtQml 2.0 +QtObject { + property bool success: 42 +} diff --git a/tests/auto/cmake/qtquickcompiler/qqc_test.qrc b/tests/auto/cmake/qtquickcompiler/qqc_test.qrc new file mode 100644 index 0000000000..f128b7004b --- /dev/null +++ b/tests/auto/cmake/qtquickcompiler/qqc_test.qrc @@ -0,0 +1,6 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> +<file>./main.qml</file> +<file>./main.cpp</file> +</qresource> +</RCC> diff --git a/tools/qmlcachegen/Qt5QuickCompilerConfig.cmake b/tools/qmlcachegen/Qt5QuickCompilerConfig.cmake new file mode 100644 index 0000000000..6fe1662995 --- /dev/null +++ b/tools/qmlcachegen/Qt5QuickCompilerConfig.cmake @@ -0,0 +1,73 @@ +include(CMakeParseArguments) + +function(QTQUICK_COMPILER_DETERMINE_OUTPUT_FILENAME outvariable filename) + file(RELATIVE_PATH relpath ${CMAKE_CURRENT_SOURCE_DIR} ${filename}) + string(REPLACE ".qml" "_qml" relpath ${relpath}) + string(REPLACE ".js" "_js" relpath ${relpath}) + string(REPLACE "/" "_" relpath ${relpath}) + set(${outvariable} ${CMAKE_CURRENT_BINARY_DIR}/${relpath}.cpp PARENT_SCOPE) +endfunction() + +function(QTQUICK_COMPILER_ADD_RESOURCES outfiles) + set(options) + set(oneValueArgs) + set(multiValueArgs OPTIONS) + + cmake_parse_arguments(_RCC "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + find_package(Qt5 COMPONENTS Qml Core) + + set(compiler_path "${_qt5Core_install_prefix}/bin/qmlcachegen") + + get_target_property(rcc_path ${Qt5Core_RCC_EXECUTABLE} IMPORTED_LOCATION) + + set(rcc_files ${_RCC_UNPARSED_ARGUMENTS}) + set(rcc_options ${_RCC_OPTIONS}) + set(filtered_rcc_files) + set(compiler_output) + set(rcc_files_with_compilation_units) + set(loader_flags) + + foreach(_resource ${rcc_files}) + get_filename_component(resource_base ${_resource} NAME_WE) + set(new_resource_file ${CMAKE_CURRENT_BINARY_DIR}/${resource_base}_qmlcache.qrc) + + get_filename_component(input_resource ${_resource} ABSOLUTE) + + execute_process(COMMAND ${compiler_path} -filter-resource-file ${input_resource} -o ${new_resource_file} OUTPUT_VARIABLE remaining_files) + if(remaining_files) + list(APPEND filtered_rcc_files ${new_resource_file}) + list(APPEND loader_flags "--resource-file-mapping=${_resource}=${new_resource_file}") + else() + list(APPEND loader_flags "--resource-file-mapping=${_resource}") + endif() + + set(rcc_file_with_compilation_units) + + exec_program(${rcc_path} ARGS -list ${input_resource} OUTPUT_VARIABLE rcc_contents) + string(REGEX REPLACE "[\r\n]+" ";" rcc_contents ${rcc_contents}) + foreach(it ${rcc_contents}) + get_filename_component(extension ${it} EXT) + if("x${extension}" STREQUAL "x.qml" OR "x${extension}" STREQUAL "x.js" OR "x${extension}" STREQUAL "x.ui.qml") + qtquick_compiler_determine_output_filename(output_file ${it}) + add_custom_command(OUTPUT ${output_file} COMMAND ${compiler_path} ARGS --resource=${input_resource} ${it} -o ${output_file} DEPENDS ${it}) + list(APPEND compiler_output ${output_file}) + set(rcc_file_with_compilation_units ${input_resource}) + endif() + endforeach() + + if(rcc_file_with_compilation_units) + list(APPEND rcc_files_with_compilation_units ${rcc_file_with_compilation_units}) + endif() + endforeach() + + if(rcc_files_with_compilation_units) + set(loader_source ${CMAKE_CURRENT_BINARY_DIR}/qmlcache_loader.cpp) + 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}) + list(APPEND compiler_output ${loader_source}) + endif() + + qt5_add_resources(output_resources ${filtered_rcc_files} OPTIONS ${options}) + set(${outfiles} ${output_resources} ${compiler_output} PARENT_SCOPE) +endfunction() + diff --git a/tools/qmlcachegen/qmlcachegen.pro b/tools/qmlcachegen/qmlcachegen.pro index 1b76833b5a..391f0c3889 100644 --- a/tools/qmlcachegen/qmlcachegen.pro +++ b/tools/qmlcachegen/qmlcachegen.pro @@ -14,6 +14,11 @@ build_integration.path = $$[QT_HOST_DATA]/mkspecs/features prefix_build: INSTALLS += build_integration else: COPIES += build_integration +cmake_build_integration.files = Qt5QuickCompilerConfig.cmake +cmake_build_integration.path = $$[QT_INSTALL_LIBS]/cmake/Qt5QuickCompiler +prefix_build: INSTALLS += cmake_build_integration +else: COPIES += cmake_build_integration + QMAKE_TARGET_DESCRIPTION = QML Cache Generator load(qt_tool) |