diff options
author | Brad King <brad.king@kitware.com> | 2023-09-27 15:20:54 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2023-09-27 15:21:07 (GMT) |
commit | 81d863b60aa40c42f08736abbc3fa6715b553240 (patch) | |
tree | 0d7801a1fabf951dbedfc27228a78a595d96ea79 /Tests/RunCMake | |
parent | ab2149e6da27d8a7a278034773d00b64236059de (diff) | |
parent | bac468ddfd5eb207d64af527fa12466ceecee0dd (diff) | |
download | CMake-81d863b60aa40c42f08736abbc3fa6715b553240.zip CMake-81d863b60aa40c42f08736abbc3fa6715b553240.tar.gz CMake-81d863b60aa40c42f08736abbc3fa6715b553240.tar.bz2 |
Merge topic 'autogen-timestamp-per-config'
bac468ddfd AutoGen: Fix regression in timestamps on multi-config generators
c3f0825d3c Tests/RunCMake/Autogen: Factor out test setup
9654835b4f Tests/RunCMake/Autogen: Add expect_n_times() function
Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !8840
Diffstat (limited to 'Tests/RunCMake')
-rw-r--r-- | Tests/RunCMake/Autogen/AutoMocExecutableConfig.cmake | 13 | ||||
-rw-r--r-- | Tests/RunCMake/Autogen/AutoRccExecutableConfig.cmake | 13 | ||||
-rw-r--r-- | Tests/RunCMake/Autogen/AutoUicExecutableConfig.cmake | 13 | ||||
-rw-r--r-- | Tests/RunCMake/Autogen/MocExample.cmake | 11 | ||||
-rw-r--r-- | Tests/RunCMake/Autogen/RccExample.cmake | 11 | ||||
-rw-r--r-- | Tests/RunCMake/Autogen/RunCMakeTest.cmake | 201 | ||||
-rw-r--r-- | Tests/RunCMake/Autogen/UicExample.cmake | 11 |
7 files changed, 198 insertions, 75 deletions
diff --git a/Tests/RunCMake/Autogen/AutoMocExecutableConfig.cmake b/Tests/RunCMake/Autogen/AutoMocExecutableConfig.cmake index fd3614c..3ee9be9 100644 --- a/Tests/RunCMake/Autogen/AutoMocExecutableConfig.cmake +++ b/Tests/RunCMake/Autogen/AutoMocExecutableConfig.cmake @@ -1,17 +1,9 @@ -enable_language(CXX) - -set(CMAKE_CXX_STANDARD 11) -find_package(Qt${with_qt_version} REQUIRED COMPONENTS Core Widgets Gui) +include(MocExample.cmake) if(NOT TARGET Qt${with_qt_version}::moc) message(FATAL_ERROR "Qt${with_qt_version}::moc not found") endif() -add_library(dummy STATIC example.cpp) -target_link_libraries(dummy Qt${with_qt_version}::Core - Qt${with_qt_version}::Widgets - Qt${with_qt_version}::Gui) - get_target_property(moc_location Qt${with_qt_version}::moc IMPORTED_LOCATION) set_target_properties(dummy PROPERTIES AUTOMOC_MOC_OPTIONS "EXE_PATH=${moc_location}") @@ -20,5 +12,4 @@ add_executable(mymoc $<$<CONFIG:Debug>:exe_debug.cpp> $<$<CONFIG:RelWithDebInfo>:exe_relwithdebinfo.cpp> ) -set_target_properties(dummy PROPERTIES AUTOMOC_EXECUTABLE $<TARGET_FILE:mymoc> - AUTOMOC ON) +set_target_properties(dummy PROPERTIES AUTOMOC_EXECUTABLE $<TARGET_FILE:mymoc>) diff --git a/Tests/RunCMake/Autogen/AutoRccExecutableConfig.cmake b/Tests/RunCMake/Autogen/AutoRccExecutableConfig.cmake index a0e9ce9..0e46420 100644 --- a/Tests/RunCMake/Autogen/AutoRccExecutableConfig.cmake +++ b/Tests/RunCMake/Autogen/AutoRccExecutableConfig.cmake @@ -1,17 +1,9 @@ -enable_language(CXX) - -set(CMAKE_CXX_STANDARD 11) -find_package(Qt${with_qt_version} REQUIRED COMPONENTS Core Widgets Gui) +include(RccExample.cmake) if(NOT TARGET Qt${with_qt_version}::rcc) message(FATAL_ERROR "Qt${with_qt_version}::rcc not found") endif() -add_library(dummy STATIC example.cpp data.qrc) -target_link_libraries(dummy Qt${with_qt_version}::Core - Qt${with_qt_version}::Widgets - Qt${with_qt_version}::Gui) - get_target_property(rcc_location Qt${with_qt_version}::rcc IMPORTED_LOCATION) set_target_properties(dummy PROPERTIES AUTORCC_OPTIONS "EXE_PATH=${rcc_location}") @@ -20,5 +12,4 @@ add_executable(myrcc $<$<CONFIG:Debug>:exe_debug.cpp> $<$<CONFIG:RelWithDebInfo>:exe_relwithdebinfo.cpp> ) -set_target_properties(dummy PROPERTIES AUTORCC_EXECUTABLE $<TARGET_FILE:myrcc> - AUTORCC ON) +set_target_properties(dummy PROPERTIES AUTORCC_EXECUTABLE $<TARGET_FILE:myrcc>) diff --git a/Tests/RunCMake/Autogen/AutoUicExecutableConfig.cmake b/Tests/RunCMake/Autogen/AutoUicExecutableConfig.cmake index ce7675e..55b88b8 100644 --- a/Tests/RunCMake/Autogen/AutoUicExecutableConfig.cmake +++ b/Tests/RunCMake/Autogen/AutoUicExecutableConfig.cmake @@ -1,17 +1,9 @@ -enable_language(CXX) - -set(CMAKE_CXX_STANDARD 11) -find_package(Qt${with_qt_version} REQUIRED COMPONENTS Core Widgets Gui) +include(UicExample.cmake) if(NOT TARGET Qt${with_qt_version}::uic) message(FATAL_ERROR "Qt${with_qt_version}::uic not found") endif() -add_library(dummy STATIC example_ui.cpp uiA.ui) -target_link_libraries(dummy Qt${with_qt_version}::Core - Qt${with_qt_version}::Widgets - Qt${with_qt_version}::Gui) - get_target_property(uic_location Qt${with_qt_version}::uic IMPORTED_LOCATION) set_target_properties(dummy PROPERTIES AUTOUIC_OPTIONS "EXE_PATH=${uic_location}") @@ -20,5 +12,4 @@ add_executable(myuic $<$<CONFIG:Debug>:exe_debug.cpp> $<$<CONFIG:RelWithDebInfo>:exe_relwithdebinfo.cpp> ) -set_target_properties(dummy PROPERTIES AUTOUIC_EXECUTABLE $<TARGET_FILE:myuic> - AUTOUIC ON) +set_target_properties(dummy PROPERTIES AUTOUIC_EXECUTABLE $<TARGET_FILE:myuic>) diff --git a/Tests/RunCMake/Autogen/MocExample.cmake b/Tests/RunCMake/Autogen/MocExample.cmake new file mode 100644 index 0000000..f06f8f6 --- /dev/null +++ b/Tests/RunCMake/Autogen/MocExample.cmake @@ -0,0 +1,11 @@ +enable_language(CXX) + +set(CMAKE_CXX_STANDARD 11) +find_package(Qt${with_qt_version} REQUIRED COMPONENTS Core Widgets Gui) + +add_library(dummy STATIC example.cpp) +target_link_libraries(dummy Qt${with_qt_version}::Core + Qt${with_qt_version}::Widgets + Qt${with_qt_version}::Gui) + +set_target_properties(dummy PROPERTIES AUTOMOC ON) diff --git a/Tests/RunCMake/Autogen/RccExample.cmake b/Tests/RunCMake/Autogen/RccExample.cmake new file mode 100644 index 0000000..4554eb0 --- /dev/null +++ b/Tests/RunCMake/Autogen/RccExample.cmake @@ -0,0 +1,11 @@ +enable_language(CXX) + +set(CMAKE_CXX_STANDARD 11) +find_package(Qt${with_qt_version} REQUIRED COMPONENTS Core Widgets Gui) + +add_library(dummy STATIC example.cpp data.qrc) +target_link_libraries(dummy Qt${with_qt_version}::Core + Qt${with_qt_version}::Widgets + Qt${with_qt_version}::Gui) + +set_target_properties(dummy PROPERTIES AUTORCC ON) diff --git a/Tests/RunCMake/Autogen/RunCMakeTest.cmake b/Tests/RunCMake/Autogen/RunCMakeTest.cmake index 12a8f8e..38987b9 100644 --- a/Tests/RunCMake/Autogen/RunCMakeTest.cmake +++ b/Tests/RunCMake/Autogen/RunCMakeTest.cmake @@ -126,50 +126,69 @@ if (DEFINED with_qt_version) if(RunCMake_GENERATOR MATCHES "Make|Ninja") block() if(QtCore_VERSION VERSION_GREATER_EQUAL 5.15.0) - set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/QtAutoMocDeps-build) - run_cmake(QtAutoMocDeps) - set(RunCMake_TEST_NO_CLEAN 1) - # Build the project. - run_cmake_command(QtAutoMocDeps-build ${CMAKE_COMMAND} --build . --verbose) - # Touch just the library source file, which shouldn't cause a rerun of AUTOMOC - # for app_with_qt target. - file(TOUCH "${RunCMake_SOURCE_DIR}/simple_lib.cpp") - set(RunCMake_TEST_NOT_EXPECT_stdout "Automatic MOC for target app_with_qt|\ + if (RunCMake_GENERATOR MATCHES "Ninja Multi-Config") + set(config_list Debug Release RelWithDebInfo) + else() + set(config_list single-config) + endif() + foreach(config IN ITEMS ${config_list}) + block() + if (config STREQUAL "single-config") + set(config_suffix "") + else() + set(config_suffix "_${config}") + endif() + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/QtAutoMocDeps${config_suffix}-build) + run_cmake(QtAutoMocDeps) + set(RunCMake_TEST_NO_CLEAN 1) + # Build the project. + if (config STREQUAL "single-config") + set(config_param "") + else() + set(config_param "--config ${config}") + endif() + run_cmake_command(QtAutoMocDeps-build ${CMAKE_COMMAND} --build . --verbose ${config_param}) + # Touch just the library source file, which shouldn't cause a rerun of AUTOMOC + # for app_with_qt target. + file(TOUCH "${RunCMake_SOURCE_DIR}/simple_lib.cpp") + set(RunCMake_TEST_NOT_EXPECT_stdout "Automatic MOC for target app_with_qt|\ Automatic MOC for target sub_exe_1|\ Automatic MOC for target sub_exe_2") - set(RunCMake_TEST_VARIANT_DESCRIPTION "-Don't execute AUTOMOC for 'app_with_qt', 'sub_exe_1' and 'sub_exe_2'") - # Build and assert that AUTOMOC was not run for app_with_qt, sub_exe_1 and sub_exe_2. - run_cmake_command(QtAutoMocDeps-build ${CMAKE_COMMAND} --build . --verbose) - unset(RunCMake_TEST_VARIANT_DESCRIPTION) - unset(RunCMake_TEST_NOT_EXPECT_stdout) - - macro(check_file_exists file) - if (EXISTS "${file}") - set(check_result "PASSED") - set(message_type "STATUS") - else() - set(check_result "FAILED") - set(message_type "FATAL_ERROR") - endif() - - message(${message_type} "QtAutoMocDeps-build-\"${file}\" was generated - ${check_result}") - endmacro() - - check_file_exists("${RunCMake_TEST_BINARY_DIR}/app_with_qt_autogen/deps") - check_file_exists("${RunCMake_TEST_BINARY_DIR}/QtSubDir1/sub_exe_1_autogen/deps") - check_file_exists("${RunCMake_TEST_BINARY_DIR}/QtSubDir2/sub_exe_2_autogen/deps") - - check_file_exists("${RunCMake_TEST_BINARY_DIR}/app_with_qt_autogen/timestamp") - check_file_exists("${RunCMake_TEST_BINARY_DIR}/QtSubDir1/sub_exe_1_autogen/timestamp") - check_file_exists("${RunCMake_TEST_BINARY_DIR}/QtSubDir2/sub_exe_2_autogen/timestamp") - - # Touch a header file to make sure an automoc dependency cycle is not introduced. - file(TOUCH "${RunCMake_SOURCE_DIR}/MyWindow.h") - set(RunCMake_TEST_VARIANT_DESCRIPTION "-First build after touch to detect dependency cycle") - run_cmake_command(QtAutoMocDeps-build ${CMAKE_COMMAND} --build . --verbose) - # Need to run a second time to hit the dependency cycle. - set(RunCMake_TEST_VARIANT_DESCRIPTION "-Don't hit dependency cycle") - run_cmake_command(QtAutoMocDeps-build ${CMAKE_COMMAND} --build . --verbose) + set(RunCMake_TEST_VARIANT_DESCRIPTION "-Don't execute AUTOMOC for 'app_with_qt', 'sub_exe_1' and 'sub_exe_2'") + # Build and assert that AUTOMOC was not run for app_with_qt, sub_exe_1 and sub_exe_2. + run_cmake_command(QtAutoMocDeps-build ${CMAKE_COMMAND} --build . --verbose ${config_param}) + unset(RunCMake_TEST_VARIANT_DESCRIPTION) + unset(RunCMake_TEST_NOT_EXPECT_stdout) + + macro(check_file_exists file) + if (EXISTS "${file}") + set(check_result "PASSED") + set(message_type "STATUS") + else() + set(check_result "FAILED") + set(message_type "FATAL_ERROR") + endif() + + message(${message_type} "QtAutoMocDeps-build-\"${file}\" was generated - ${check_result}") + endmacro() + + check_file_exists("${RunCMake_TEST_BINARY_DIR}/app_with_qt_autogen/deps${config_suffix}") + check_file_exists("${RunCMake_TEST_BINARY_DIR}/QtSubDir1/sub_exe_1_autogen/deps${config_suffix}") + check_file_exists("${RunCMake_TEST_BINARY_DIR}/QtSubDir2/sub_exe_2_autogen/deps${config_suffix}") + + check_file_exists("${RunCMake_TEST_BINARY_DIR}/app_with_qt_autogen/timestamp${config_suffix}") + check_file_exists("${RunCMake_TEST_BINARY_DIR}/QtSubDir1/sub_exe_1_autogen/timestamp${config_suffix}") + check_file_exists("${RunCMake_TEST_BINARY_DIR}/QtSubDir2/sub_exe_2_autogen/timestamp${config_suffix}") + + # Touch a header file to make sure an automoc dependency cycle is not introduced. + file(TOUCH "${RunCMake_SOURCE_DIR}/MyWindow.h") + set(RunCMake_TEST_VARIANT_DESCRIPTION "-First build after touch to detect dependency cycle") + run_cmake_command(QtAutoMocDeps-build ${CMAKE_COMMAND} --build . --verbose) + # Need to run a second time to hit the dependency cycle. + set(RunCMake_TEST_VARIANT_DESCRIPTION "-Don't hit dependency cycle") + run_cmake_command(QtAutoMocDeps-build ${CMAKE_COMMAND} --build . --verbose) + endblock() + endforeach() endif() endblock() endif() @@ -239,6 +258,16 @@ ${make_program_stderr} endif() endfunction() + function(expect_n_times string_to_check expected_output expected_count test_name) + count_substring("${string_to_check}" "${expected_output}" count) + if(NOT count EQUAL ${expected_count}) + message(STATUS "${test_name}-expect_${expected_count}_times - FAILED") + message(FATAL_ERROR "Expected to find ${expected_output} exactly ${expected_count} times in ${string_to_check} but found ${count} occurrences of ${expected_output}") + else() + message(STATUS "${test_name}-expect_${expected_count}_times - PASSED") + endif() + endfunction() + function(not_expect make_program_stdout unexpected_output test_name) count_substring("${make_program_stdout}" "${unexpected_output}" count) if(NOT count EQUAL 0) @@ -253,6 +282,27 @@ ${make_program_stderr} foreach(exe IN ITEMS Moc Uic Rcc) if(RunCMake_GENERATOR MATCHES "Ninja Multi-Config") block() + set(RunCMake_TEST_VARIANT_DESCRIPTION "-CMake-configure") + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/Auto${exe}ExecutableConfig-multi-config-build) + run_cmake_with_options(Auto${exe}ExecutableConfig ${RunCMake_TEST_OPTIONS} -DCMAKE_AUTOGEN_VERBOSE=ON) + unset(RunCMake_TEST_VARIANT_DESCRIPTION) + set(RunCMake_TEST_NO_CLEAN 1) + foreach(config IN ITEMS Debug Release RelWithDebInfo) + block() + set(RunCMake_TEST_EXPECT_stdout ".*running_exe_${config}*") + set(RunCMake_TEST_VARIANT_DESCRIPTION "-${config}-expect_running_exe_${config}") + run_cmake_command(Auto${exe}ExecutableConfig-multi-config-build ${CMAKE_COMMAND} --build . --config ${config}) + endblock() + endforeach() + set(RunCMake_TEST_EXPECT_stdout "ninja: no work to do") + foreach(config IN ITEMS Debug Release RelWithDebInfo) + block() + set(RunCMake_TEST_VARIANT_DESCRIPTION "-${config}-expect_no_work_to_do") + run_cmake_command(Auto${exe}ExecutableConfig-multi-config-build ${CMAKE_COMMAND} --build . --config ${config}) + endblock() + endforeach() + endblock() + block() set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/Auto${exe}ExecutableConfig-build) run_cmake_with_options(Auto${exe}ExecutableConfig ${RunCMake_TEST_OPTIONS} -DCMAKE_AUTOGEN_VERBOSE=ON) foreach(config IN ITEMS Debug Release RelWithDebInfo) @@ -337,4 +387,71 @@ ${make_program_stderr} endif() endforeach() endif() + + # Visual Studio specific dependency tests + if (RunCMake_GENERATOR MATCHES "Visual Studio") + foreach(exe IN ITEMS Moc Uic Rcc) + block() + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${exe}Example-build) + set(RunCMake_TEST_VARIANT_DESCRIPTION "-CMake-configure") + run_cmake_with_options(${exe}Example ${RunCMake_TEST_OPTIONS} -DCMAKE_AUTOGEN_VERBOSE=ON) + unset(RunCMake_TEST_VARIANT_DESCRIPTION) + set(RunCMake_TEST_NO_CLEAN 1) + foreach(config IN ITEMS Debug Release RelWithDebInfo) + block() + set(RunCMake_TEST_VARIANT_DESCRIPTION "-${config}-first-build") + run_cmake_command(${exe}Example-build ${CMAKE_COMMAND} --build . --config ${config}) + endblock() + endforeach() + foreach(config IN ITEMS Debug Release RelWithDebInfo) + block() + if (exe STREQUAL "Moc" OR exe STREQUAL "Uic") + set(RunCMake_TEST_NOT_EXPECT_stdout "Auto${exe}") + set(not_expect_descripton "Auto${exe}") + else () + set(RunCMake_TEST_NOT_EXPECT_stdout "qrc_data.cpp|Auto${exe}") + set(not_expect_descripton "qrc_data.cpp_and_Auto${exe}") + endif() + set(RunCMake_TEST_VARIANT_DESCRIPTION "-second-build-${config}_expect_no_${not_expect_descripton}") + run_cmake_command(${exe}Example-build ${CMAKE_COMMAND} --build . --config ${config}) + endblock() + endforeach() + endblock() + endforeach() + endif() + + if (RunCMake_GENERATOR MATCHES "Xcode") + foreach(exe IN ITEMS Moc Uic Rcc) + block() + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${exe}Example-build) + set(RunCMake_TEST_VARIANT_DESCRIPTION "-CMake-configure") + set(RunCMake_TEST_EXPECT_stderr ".*") + run_cmake_with_options(${exe}Example ${RunCMake_TEST_OPTIONS} -DCMAKE_AUTOGEN_VERBOSE=ON) + set(RunCMake_TEST_NO_CLEAN 1) + set(RunCMake_MAKE_PROGRAM ${CMAKE_COMMAND}) + run_make_program(${RunCMake_TEST_BINARY_DIR} --build . --config Debug) + if (exe STREQUAL "Moc") + set(expected_count 16) + elseif (exe STREQUAL "Uic") + set(expected_count 4) + else() + set(expected_count 12) + endif() + expect_n_times("${make_program_stdout}" "Auto${exe}:" ${expected_count} "${exe}Example-build-Auto${exe}") + expect_n_times("${make_program_stdout}" "Auto${exe}:" ${expected_count} "${exe}Example-build-Auto${exe}") + + if (exe STREQUAL "Moc" OR exe STREQUAL "Uic") + expect_n_times("${make_program_stdout}" "AutoGen:" 20 "${exe}Example-build-AutoGen:") + endif() + + foreach(config IN ITEMS Debug Release RelWithDebInfo) + block() + run_make_program(${RunCMake_TEST_BINARY_DIR} --build . --config ${config}) + not_expect("${make_program_stdout}" "Auto${exe}" "${exe}Example-${config}_Auto${exe}") + not_expect("${make_program_stdout}" "AutoGen:" "${exe}Example-${config}_AutoGen") + endblock() + endforeach() + endblock() + endforeach() + endif() endif () diff --git a/Tests/RunCMake/Autogen/UicExample.cmake b/Tests/RunCMake/Autogen/UicExample.cmake new file mode 100644 index 0000000..4b1f8c1 --- /dev/null +++ b/Tests/RunCMake/Autogen/UicExample.cmake @@ -0,0 +1,11 @@ +enable_language(CXX) + +set(CMAKE_CXX_STANDARD 11) +find_package(Qt${with_qt_version} REQUIRED COMPONENTS Core Widgets Gui) + +add_library(dummy STATIC example_ui.cpp uiA.ui) +target_link_libraries(dummy Qt${with_qt_version}::Core + Qt${with_qt_version}::Widgets + Qt${with_qt_version}::Gui) + +set_target_properties(dummy PROPERTIES AUTOUIC ON) |