diff options
author | Tobias Hunger <tobias.hunger@qt.io> | 2018-11-15 12:01:22 +0100 |
---|---|---|
committer | Tobias Hunger <tobias.hunger@qt.io> | 2018-11-22 15:19:41 +0000 |
commit | 13e1c93e370551a7398d8e819b8ec4710def0151 (patch) | |
tree | 1e4e1655b83b46fb29d883825d118afbdb476f7a /cmake | |
parent | f4dc3dcacb61694915f45a0a0c47c85c21580d40 (diff) |
CMake: Add test for QRC and make it pass
Add a test for QRC file handling in cmake and fix the qrc file handling
to handle qrc files in subfolders properly.
Change-Id: Iff4224e59e7ee1badacce5fc00dbf68aef69bffe
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/QtBuild.cmake | 44 | ||||
-rw-r--r-- | cmake/tests/CMakeLists.txt | 1 | ||||
-rw-r--r-- | cmake/tests/qrc/CMakeLists.txt | 31 | ||||
-rw-r--r-- | cmake/tests/qrc/dialog/dialog.qrc | 0 | ||||
-rw-r--r-- | cmake/tests/qrc/qrc.qrc | 0 |
5 files changed, 55 insertions, 21 deletions
diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake index 771d04f3a7..c453e41334 100644 --- a/cmake/QtBuild.cmake +++ b/cmake/QtBuild.cmake @@ -358,21 +358,18 @@ endfunction() # This function creates the necessary rule to call rcc on the given # resource file and stores the name of the to-be generated C++ source # file (created by rcc) in the outCppFile variable. -function(qt_create_rcc_command resourceFile outCppFile) - get_filename_component(outfilename "${resourceFile}" NAME_WE) - get_filename_component(infile "${resourceFile}" ABSOLUTE) - set(generatedCppFile "${CMAKE_CURRENT_BINARY_DIR}/qrc_${outfilename}.cpp") - - qt_extract_qrc_dependencies("${infile}" _out_depends _rc_depends) +function(qt_create_rcc_command resourceFile source_dir binary_dir outfile) + qt_extract_qrc_dependencies("${infile}" out_depends rc_depends "${source_dir}" "${binary_dir}") set_source_files_properties("${infile}" PROPERTIES SKIP_AUTORCC ON) - add_custom_command(OUTPUT "${generatedCppFile}" - COMMAND "Qt::rcc" --name "${outfilename}" --output "${generatedCppFile}" "${infile}" + get_filename_component(outfilename "${resourceFile}" NAME_WE) + add_custom_command(OUTPUT "${outfile}" + COMMAND "Qt::rcc" --name "${outfilename}" --output "${outfile}" "${resourceFile}" MAIN_DEPENDENCY "${infile}" - DEPENDS "${_rc_depends}" "${_out_depends}" VERBATIM) - set_source_files_properties("${generatedCppFile}" PROPERTIES SKIP_AUTOMOC ON) - set_source_files_properties("${generatedCppFile}" PROPERTIES SKIP_AUTOUIC ON) - set("${outCppFile}" "${generatedCppFile}" PARENT_SCOPE) + DEPENDS "${rc_depends}" "${out_depends}" + WORKING_DIRECTORY "${source_dir}" VERBATIM) + set_source_files_properties("${outfile}" PROPERTIES SKIP_AUTOMOC ON) + set_source_files_properties("${outfile}" PROPERTIES SKIP_AUTOUIC ON) endfunction() @@ -380,20 +377,25 @@ endfunction() # Any sources ending with the .qrc extension are treated as Qt resources and rules # to call rcc are generated. The source files rcc generates are added to the target. function(qt_internal_autorcc target) - if ("x${ARGN}" STREQUAL "x") - return() - endif() + get_target_property(binary_dir "${target}" BINARY_DIR) + get_target_property(source_dir "${target}" SOURCE_DIR) - set(_qrc_cpp_files "") + set(qrc_outfiles "") - foreach(s ${ARGN}) - get_filename_component(ext "${s}" EXT) + foreach(infile ${ARGN}) + get_filename_component(ext "${infile}" EXT) if("${ext}" STREQUAL ".qrc") - qt_create_rcc_command("${s}" _qrc_cpp_file) - list(APPEND _qrc_cpp_files "${_qrc_cpp_file}") + qt_make_output_file("${infile}" "qrc_" ".cpp" "${source_dir}" "${binary_dir}" outfile) + list(FIND all_sources "${outfile}" known_result) + if (known_result GREATER -1) + continue() + endif() + + qt_create_rcc_command("${infile}" "${source_dir}" "${binary_dir}" "${outfile}") + list(APPEND qrc_outfiles "${outfile}") endif() endforeach() - target_sources("${target}" PRIVATE "${_qrc_cpp_files}") + target_sources("${target}" PRIVATE "${qrc_outfiles}") endfunction() diff --git a/cmake/tests/CMakeLists.txt b/cmake/tests/CMakeLists.txt index dd268bf254..3f51c24025 100644 --- a/cmake/tests/CMakeLists.txt +++ b/cmake/tests/CMakeLists.txt @@ -45,5 +45,6 @@ macro(add_cmake_test_generate name) endmacro() add_cmake_test_generate(features) +add_cmake_test_generate(qrc) add_cmake_test_generate(qt_make_output_file) add_cmake_test_generate(uic) diff --git a/cmake/tests/qrc/CMakeLists.txt b/cmake/tests/qrc/CMakeLists.txt new file mode 100644 index 0000000000..fc28390300 --- /dev/null +++ b/cmake/tests/qrc/CMakeLists.txt @@ -0,0 +1,31 @@ +cmake_minimum_required(VERSION 3.12.0) + +project(QrcTest + VERSION 1.0.0 + DESCRIPTION "Qrc test" + HOMEPAGE_URL "https://qt.io/" + LANGUAGES CXX +) + +## Add some paths to check for cmake modules: +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../;${CMAKE_CURRENT_SOURCE_DIR}/../../3rdparty/extra-cmake-modules/find-modules;${CMAKE_CURRENT_SOURCE_DIR}/../../3rdparty/kwin") + +## Qt specific setup common for all modules: +include(QtSetup) + +include(../test.cmake) + +fake_moc_results() +add_qt_executable(test_executable + SOURCES + ../main.cpp + qrc.qrc +) + +fake_moc_results() +extend_target(test_executable SOURCES dialog/dialog.qrc) + +test_source_file(test_executable "${CMAKE_CURRENT_BINARY_DIR}/qrc_qrc.cpp" BUILD) +test_source_file(test_executable "${CMAKE_CURRENT_BINARY_DIR}/dialog/qrc_dialog.cpp" BUILD) + +test_include_directory(test_executable "${CMAKE_CURRENT_BINARY_DIR}/dialog" UNKNOWN) diff --git a/cmake/tests/qrc/dialog/dialog.qrc b/cmake/tests/qrc/dialog/dialog.qrc new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/cmake/tests/qrc/dialog/dialog.qrc diff --git a/cmake/tests/qrc/qrc.qrc b/cmake/tests/qrc/qrc.qrc new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/cmake/tests/qrc/qrc.qrc |