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>
This commit is contained in:
Tobias Hunger 2018-11-14 14:57:48 +01:00
parent c68e5fc59b
commit f4dc3dcacb
7 changed files with 98 additions and 20 deletions

View File

@ -300,20 +300,23 @@ endfunction()
# Any sources with the .ui extension are passed on to uic and the generated output # Any sources with the .ui extension are passed on to uic and the generated output
# is added to the target sources. # is added to the target sources.
function(qt_internal_autouic target) function(qt_internal_autouic target)
if ("x${ARGN}" STREQUAL "x") set(outfiles "")
return()
endif()
set(_ui_files "") get_target_property(source_dir "${target}" SOURCE_DIR)
get_target_property(binary_dir "${target}" BINARY_DIR)
foreach(s ${ARGN}) foreach(infile ${ARGN})
get_filename_component(ext "${s}" EXT) get_filename_component(ext "${infile}" EXT)
if("${ext}" STREQUAL ".ui") if("${ext}" STREQUAL ".ui")
qt_create_uic_command("${s}" _ui_file) qt_make_output_file("${infile}" "ui_" ".h" "${source_dir}" "${binary_dir}" outfile)
list(APPEND _ui_files "${_ui_file}") 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() endif()
endforeach() endforeach()
target_sources("${target}" PRIVATE "${_ui_files}") target_sources("${target}" PRIVATE "${outfiles}")
endfunction() endfunction()
@ -1055,20 +1058,13 @@ endfunction()
# helper to set up a uic rule # helper to set up a uic rule
function(qt_create_uic_command infile _result) function(qt_create_uic_command infile source_dir outfile)
# 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")
add_custom_command(OUTPUT "${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}" DEPENDS "${infile}"
COMMENT "Running UIC on ${infile}." COMMENT "Running UIC on ${infile}."
VERBATIM) WORKING_DIRECTORY "${source_dir}" VERBATIM)
set(${_result} "${CMAKE_CURRENT_BINARY_DIR}/${outfile}" PARENT_SCOPE) set_source_files_properties("${outfile}" PROPERTIES HEADER_FILE_ONLY ON)
endfunction() endfunction()

View File

@ -46,3 +46,4 @@ endmacro()
add_cmake_test_generate(features) add_cmake_test_generate(features)
add_cmake_test_generate(qt_make_output_file) add_cmake_test_generate(qt_make_output_file)
add_cmake_test_generate(uic)

0
cmake/tests/empty.cpp Normal file
View File

50
cmake/tests/test.cmake Normal file
View File

@ -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)

View File

@ -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")

View File

View File