diff options
author | Tobias Hunger <tobias.hunger@qt.io> | 2018-11-14 14:57:48 +0100 |
---|---|---|
committer | Tobias Hunger <tobias.hunger@qt.io> | 2018-11-22 15:19:22 +0000 |
commit | f4dc3dcacb61694915f45a0a0c47c85c21580d40 (patch) | |
tree | 23efe0575bbdc37e39a4aaba01468ece43b75b24 | |
parent | c68e5fc59ba8f0fd8b782a37df20ab9b7d7ecafa (diff) |
CMake: Add test for uic handling
Add a test for uic handling and make it pass.
Change-Id: I7e11f9f1fba0e40c748e3590a0d0cbb72c9ebc28
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
-rw-r--r-- | cmake/QtBuild.cmake | 36 | ||||
-rw-r--r-- | cmake/tests/CMakeLists.txt | 1 | ||||
-rw-r--r-- | cmake/tests/empty.cpp | 0 | ||||
-rw-r--r-- | cmake/tests/test.cmake | 50 | ||||
-rw-r--r-- | cmake/tests/uic/CMakeLists.txt | 31 | ||||
-rw-r--r-- | cmake/tests/uic/dialog/dialog.ui | 0 | ||||
-rw-r--r-- | cmake/tests/uic/window.ui | 0 |
7 files changed, 98 insertions, 20 deletions
diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake index a8ca77b64a..771d04f3a7 100644 --- a/cmake/QtBuild.cmake +++ b/cmake/QtBuild.cmake @@ -300,20 +300,23 @@ endfunction() # Any sources with the .ui extension are passed on to uic and the generated output # is added to the target sources. function(qt_internal_autouic target) - if ("x${ARGN}" STREQUAL "x") - return() - endif() + set(outfiles "") - set(_ui_files "") + get_target_property(source_dir "${target}" SOURCE_DIR) + get_target_property(binary_dir "${target}" BINARY_DIR) - foreach(s ${ARGN}) - get_filename_component(ext "${s}" EXT) + foreach(infile ${ARGN}) + get_filename_component(ext "${infile}" EXT) if("${ext}" STREQUAL ".ui") - qt_create_uic_command("${s}" _ui_file) - list(APPEND _ui_files "${_ui_file}") + qt_make_output_file("${infile}" "ui_" ".h" "${source_dir}" "${binary_dir}" outfile) + qt_create_uic_command("${infile}" "${source_dir}" "${outfile}") + list(APPEND outfiles "${outfile}") + + get_filename_component(outfile_path "${outfile}" PATH) + target_include_directories("${target}" PRIVATE "${outfile_path}") endif() endforeach() - target_sources("${target}" PRIVATE "${_ui_files}") + target_sources("${target}" PRIVATE "${outfiles}") endfunction() @@ -1055,20 +1058,13 @@ endfunction() # helper to set up a uic rule -function(qt_create_uic_command infile _result) - # Pass the parameters in a file. Set the working directory to - # be that containing the parameters file and reference it by - # just the file name. This is necessary because the moc tool on - # MinGW builds does not seem to handle spaces in the path to the - # file given with the @ syntax. - get_filename_component(_uic_basename "${infile}" NAME_WE) - set(outfile "ui_${_uic_basename}.h") +function(qt_create_uic_command infile source_dir outfile) add_custom_command(OUTPUT "${outfile}" - COMMAND "Qt::uic" "${CMAKE_CURRENT_SOURCE_DIR}/${infile}" -o "${CMAKE_CURRENT_BINARY_DIR}/${outfile}" + COMMAND "Qt::uic" "${infile}" -o "${outfile}" DEPENDS "${infile}" COMMENT "Running UIC on ${infile}." - VERBATIM) - set(${_result} "${CMAKE_CURRENT_BINARY_DIR}/${outfile}" PARENT_SCOPE) + WORKING_DIRECTORY "${source_dir}" VERBATIM) + set_source_files_properties("${outfile}" PROPERTIES HEADER_FILE_ONLY ON) endfunction() diff --git a/cmake/tests/CMakeLists.txt b/cmake/tests/CMakeLists.txt index 6b53c9703d..dd268bf254 100644 --- a/cmake/tests/CMakeLists.txt +++ b/cmake/tests/CMakeLists.txt @@ -46,3 +46,4 @@ endmacro() add_cmake_test_generate(features) add_cmake_test_generate(qt_make_output_file) +add_cmake_test_generate(uic) diff --git a/cmake/tests/empty.cpp b/cmake/tests/empty.cpp new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/cmake/tests/empty.cpp diff --git a/cmake/tests/test.cmake b/cmake/tests/test.cmake new file mode 100644 index 0000000000..8c11b3a42e --- /dev/null +++ b/cmake/tests/test.cmake @@ -0,0 +1,50 @@ +# FAKE moc-ing: +set(QT_MOCSCANNER /usr/bin/true) + +# Fake mocscanner run. +# The files passed in after MOC will be reported to be in need of moc-ing, +# but will not be built. +# The files passed in after MOC_AND_BUILD will be reported to be in need +# of moc-ing and should also be built by the target. +function(fake_moc_results) + cmake_parse_arguments(arg "" "" "INCLUDED;BUILT") + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/moc_files_included.txt" "${arg_INCLUDED}") + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/moc_files_to_build.txt" "${arg_BUILT}") +endfunction() + +# Test whether a target has a file listed in its sources. +# Tests with the BUILD flag set will require this file to be built, +# while those without will require the file to not be built by +# the target. +function(test_source_file target file) + cmake_parse_arguments(arg "BUILD" "" "" ${ARGN}) + + get_target_property(sources "${target}" SOURCES) + list(FIND sources "${file}" source_pos) + assert(NOT source_pos STREQUAL "-1") + + get_source_file_property(prop "${file}" HEADER_FILE_ONLY) + if (arg_BUILD) + assert(NOT prop) + else() + assert(prop) + endif() +endfunction() + +# Test whether or not a target uses a header path +# The test passes when the path is in the list of include directories. +# Passing 'UNKNOWN' to this function reverses the test result. +function(test_include_directory target path) + cmake_parse_arguments(arg "UNKNOWN" "" "" ${ARGN}) + get_target_property(includes "${target}" INCLUDE_DIRECTORIES) + list(FIND includes "${path}" include_pos) + if(arg_UNKNOWN) + assert(include_pos STREQUAL "-1") + else() + assert(NOT include_pos STREQUAL "-1") + endif() +endfunction() + +# Add Core and Qt::Core libraries: +add_library(Core SHARED "${CMAKE_CURRENT_LIST_DIR}/empty.cpp") +add_library(Qt::Core ALIAS Core) diff --git a/cmake/tests/uic/CMakeLists.txt b/cmake/tests/uic/CMakeLists.txt new file mode 100644 index 0000000000..b8455821de --- /dev/null +++ b/cmake/tests/uic/CMakeLists.txt @@ -0,0 +1,31 @@ +cmake_minimum_required(VERSION 3.12.0) + +project(UicTest + VERSION 1.0.0 + DESCRIPTION "Uic 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 + window.ui +) + +fake_moc_results() +extend_target(test_executable SOURCES dialog/dialog.ui) + +test_source_file(test_executable "${CMAKE_CURRENT_BINARY_DIR}/ui_window.h") +test_source_file(test_executable "${CMAKE_CURRENT_BINARY_DIR}/dialog/ui_dialog.h") + +test_include_directory(test_executable "${CMAKE_CURRENT_BINARY_DIR}/dialog") diff --git a/cmake/tests/uic/dialog/dialog.ui b/cmake/tests/uic/dialog/dialog.ui new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/cmake/tests/uic/dialog/dialog.ui diff --git a/cmake/tests/uic/window.ui b/cmake/tests/uic/window.ui new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/cmake/tests/uic/window.ui |