diff options
author | Brad King <brad.king@kitware.com> | 2024-01-18 14:01:04 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2024-01-18 14:01:17 (GMT) |
commit | c75047709f2ee2a3f8791f19b9ce8cc76e633521 (patch) | |
tree | 6d6dac7a7816e1431bec31f8786f09a9b3fe6932 /Tests | |
parent | d3adede1cd2f2dc570185903e306e8a7aeab69da (diff) | |
parent | 596e84b0d55c080b93a5ba2d2a4d24357375378c (diff) | |
download | CMake-c75047709f2ee2a3f8791f19b9ce8cc76e633521.zip CMake-c75047709f2ee2a3f8791f19b9ce8cc76e633521.tar.gz CMake-c75047709f2ee2a3f8791f19b9ce8cc76e633521.tar.bz2 |
Merge topic 'autogen-exe-per-config'
596e84b0d5 NinjaMultiConfig: Update tests for the new dependency change
7c39dabdbc Autogen: AUTO*_EXECUTABLE: add support for per-config values
Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !8919
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/RunCMake/Autogen/RunCMakeTest.cmake | 368 | ||||
-rw-r--r-- | Tests/RunCMake/Autogen/data.qrc | 4 | ||||
-rw-r--r-- | Tests/RunCMake/Autogen/example.cpp | 5 | ||||
-rw-r--r-- | Tests/RunCMake/Autogen/example.h | 12 | ||||
-rw-r--r-- | Tests/RunCMake/Autogen/example_ui.cpp | 5 | ||||
-rw-r--r-- | Tests/RunCMake/Autogen/example_ui.h | 14 | ||||
-rw-r--r-- | Tests/RunCMake/Autogen/exe.cpp | 4 | ||||
-rw-r--r-- | Tests/RunCMake/Autogen/exe_common.h | 48 | ||||
-rw-r--r-- | Tests/RunCMake/Autogen/exe_debug.cpp | 10 | ||||
-rw-r--r-- | Tests/RunCMake/Autogen/exe_release.cpp | 10 | ||||
-rw-r--r-- | Tests/RunCMake/Autogen/exe_relwithdebinfo.cpp | 10 | ||||
-rw-r--r-- | Tests/RunCMake/Autogen/uiA.ui | 24 | ||||
-rw-r--r-- | Tests/RunCMake/NinjaMultiConfig/QtX-debug-in-release-graph-build-check.cmake | 7 | ||||
-rw-r--r-- | Tests/RunCMake/NinjaMultiConfig/QtX.cmake | 36 | ||||
-rw-r--r-- | Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake | 64 |
15 files changed, 552 insertions, 69 deletions
diff --git a/Tests/RunCMake/Autogen/RunCMakeTest.cmake b/Tests/RunCMake/Autogen/RunCMakeTest.cmake index 1a7d4f0..d0bbbb0 100644 --- a/Tests/RunCMake/Autogen/RunCMakeTest.cmake +++ b/Tests/RunCMake/Autogen/RunCMakeTest.cmake @@ -128,65 +128,339 @@ if (DEFINED with_qt_version) if(QtCore_VERSION VERSION_GREATER_EQUAL 5.15.0) if (RunCMake_GENERATOR MATCHES "Ninja Multi-Config") set(config_list Debug Release RelWithDebInfo) + set(use_better_graph_list ON OFF) else() set(config_list single-config) + set(use_better_graph_list OFF) 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") - - # 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") + foreach(use_better_graph IN ITEMS ${use_better_graph_list}) + foreach(config IN ITEMS ${config_list}) + block() + if (config STREQUAL "single-config") + set(config_suffix "") + else() + set(config_path "_${config}") + if (use_better_graph) + set(config_suffix "_${config}") + endif() + endif() + + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/QtAutoMocDeps${config_path}-build) + run_cmake_with_options(QtAutoMocDeps ${RunCMake_TEST_OPTIONS} -DCMAKE_AUTOGEN_BETTER_GRAPH_MULTI_CONFIG=${use_better_graph}) + set(RunCMake_TEST_NO_CLEAN 1) + # Build the project. + if (config STREQUAL "single-config") + set(config_param "") else() - set(check_result "FAILED") - set(message_type "FATAL_ERROR") + 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 ${config_param}) + unset(RunCMake_TEST_VARIANT_DESCRIPTION) + unset(RunCMake_TEST_NOT_EXPECT_stdout) - message(${message_type} "QtAutoMocDeps-build-\"${file}\" was generated - ${check_result}") - endmacro() + 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() - 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") + message(${message_type} "QtAutoMocDeps-build-\"${file}\" was generated - ${check_result}") + endmacro() - 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") + 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}") - # 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() + 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() endforeach() endif() endblock() endif() + + function(run_make_program dir) + execute_process( + COMMAND "${RunCMake_MAKE_PROGRAM}" ${ARGN} + WORKING_DIRECTORY "${dir}" + OUTPUT_VARIABLE make_program_stdout + ERROR_VARIABLE make_program_stderr + RESULT_VARIABLE make_program_result + ) + if (NOT DEFINED RunMakeProgram_expected_result) + set(RunMakeProgram_expected_result 0) + endif() + if(NOT "${make_program_result}" MATCHES "${RunMakeProgram_expected_result}") + message(STATUS " +============ beginning of ${RunCMake_MAKE_PROGRAM}'s stdout ============ +${make_program_stdout} +=============== end of ${RunCMake_MAKE_PROGRAM}'s stdout =============== +") + message(STATUS " +============ beginning of ${RunCMake_MAKE_PROGRAM}'s stderr ============ +${make_program_stderr} +=============== end of ${RunCMake_MAKE_PROGRAM}'s stderr =============== +") + message(FATAL_ERROR + "top ${RunCMake_MAKE_PROGRAM} build failed exited with status ${make_program_result}") + endif() + set(make_program_stdout "${make_program_stdout}" PARENT_SCOPE) + endfunction(run_make_program) + + function(count_substring STRING SUBSTRING COUNT_VAR) + string(LENGTH "${STRING}" STRING_LENGTH) + string(LENGTH "${SUBSTRING}" SUBSTRING_LENGTH) + if (SUBSTRING_LENGTH EQUAL 0) + message(FATAL_ERROR "SUBSTRING_LENGTH is 0") + endif() + + if (STRING_LENGTH EQUAL 0) + message(FATAL_ERROR "STRING_LENGTH is 0") + endif() + + if (STRING_LENGTH LESS SUBSTRING_LENGTH) + message(FATAL_ERROR "STRING_LENGTH is less than SUBSTRING_LENGTH") + endif() + + set(COUNT 0) + string(FIND "${STRING}" "${SUBSTRING}" SUBSTRING_START) + while(SUBSTRING_START GREATER_EQUAL 0) + math(EXPR COUNT "${COUNT} + 1") + math(EXPR SUBSTRING_START "${SUBSTRING_START} + ${SUBSTRING_LENGTH}") + string(SUBSTRING "${STRING}" ${SUBSTRING_START} -1 STRING) + string(FIND "${STRING}" "${SUBSTRING}" SUBSTRING_START) + endwhile() + + set(${COUNT_VAR} ${COUNT} PARENT_SCOPE) + endfunction() + + function(expect_only_once make_program_stdout expected_output test_name) + count_substring("${make_program_stdout}" "${expected_output}" count) + if(NOT count EQUAL 1) + message(STATUS "${test_name}-expect_only_once - FAILED") + message(FATAL_ERROR "Expected to find ${expected_output} exactly once in ${make_program_stdout} but found ${count} occurrences of ${expected_output}") + else() + message(STATUS "${test_name}-expect_only_once - PASSED") + 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) + message(STATUS "${test_name}-not_expect - FAILED") + message(FATAL_ERROR "Expected to find ${unexpected_output} exactly 0 times in ${make_program_stdout} but found ${count} occurrences of ${unexpected_output}") + else() + message(STATUS "${test_name}-not_expect - PASSED") + endif() + endfunction() + + if (QtCore_VERSION VERSION_GREATER_EQUAL 5.15.0) + 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 -DCMAKE_AUTOGEN_BETTER_GRAPH_MULTI_CONFIG=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 -DCMAKE_AUTOGEN_BETTER_GRAPH_MULTI_CONFIG=ON) + foreach(config IN ITEMS Debug Release RelWithDebInfo) + block() + run_make_program(${RunCMake_TEST_BINARY_DIR} --verbose -f build-${config}.ninja) + + set(expected_output "running_exe_${config}") + expect_only_once("${make_program_stdout}" "${expected_output}" "Auto${exe}ExecutableConfig-${config}-${expected_output}") + + foreach(sub_config IN ITEMS Debug Release RelWithDebInfo) + if(NOT sub_config STREQUAL config) + set(unexpected_output "running_exe_${sub_config}") + not_expect("${make_program_stdout}" "${unexpected_output}" "Auto${exe}ExecutableConfig-${config}-${unexpected_output}") + endif() + endforeach() + + if (exe STREQUAL "Moc" OR exe STREQUAL "Uic") + set(expected_output "cmake_autogen") + else() + set(expected_output "cmake_autorcc") + endif() + expect_only_once("${make_program_stdout}" "${expected_output}" "Auto${exe}ExecutableConfig-${config}-${expected_output}") + endblock() + endforeach() + endblock() + block() + foreach(ninja_config IN ITEMS Debug Release RelWithDebInfo) + foreach(target_config IN ITEMS Debug Release RelWithDebInfo) + block() + set(TEST_SUFFIX "-CrossConfig-${ninja_config}-${target_config}") + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/Auto${exe}ExecutableConfig${TEST_SUFFIX}-build) + set(RunCMake_TEST_VARIANT_DESCRIPTION ${TEST_SUFFIX}) + run_cmake_with_options(Auto${exe}ExecutableConfig ${RunCMake_TEST_OPTIONS} -DCMAKE_CROSS_CONFIGS=all -DCMAKE_DEFAULT_BUILD_TYPE=${ninja_config} -DCMAKE_AUTOGEN_BETTER_GRAPH_MULTI_CONFIG=ON) + unset(RunCMake_TEST_VARIANT_DESCRIPTION) + + run_make_program(${RunCMake_TEST_BINARY_DIR} --verbose -f build-${ninja_config}.ninja dummy:${target_config}) + + set(expected_output "running_exe_${ninja_config}") + expect_only_once("${make_program_stdout}" "${expected_output}" "Auto${exe}ExecutableConfig${TEST_SUFFIX}-${expected_output}") + + foreach(sub_config IN ITEMS Debug Release RelWithDebInfo) + if(NOT sub_config STREQUAL ninja_config) + set(unexpected_output "running_exe_${sub_config}") + not_expect("${make_program_stdout}" "${unexpected_output}" "Auto${exe}ExecutableConfig${TEST_SUFFIX}-${unexpected_output}") + endif() + endforeach() + + if (exe STREQUAL "Moc" OR exe STREQUAL "Uic") + set(expected_output "cmake_autogen") + else() + set(expected_output "cmake_autorcc") + endif() + expect_only_once("${make_program_stdout}" "${expected_output}" "Auto${exe}ExecutableConfig${TEST_SUFFIX}-${expected_output}") + endblock() + endforeach() + endforeach() + endblock() + block() + foreach(ninja_config IN ITEMS Debug Release RelWithDebInfo) + set(TEST_SUFFIX "-CrossConfig-${ninja_config}-all-all") + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/Auto${exe}ExecutableConfig${TEST_SUFFIX}-build) + set(RunCMake_TEST_VARIANT_DESCRIPTION ${TEST_SUFFIX}) + run_cmake_with_options(Auto${exe}ExecutableConfig ${RunCMake_TEST_OPTIONS} -DCMAKE_CROSS_CONFIGS=all -DCMAKE_AUTOGEN_BETTER_GRAPH_MULTI_CONFIG=ON) + unset(RunCMake_TEST_VARIANT_DESCRIPTION) + run_make_program(${RunCMake_TEST_BINARY_DIR} --verbose -f build-${ninja_config}.ninja all:all) + endforeach() + endblock() + elseif (RunCMake_GENERATOR MATCHES "Ninja|Make") + block() + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/Auto${exe}ExecutableConfig-build) + foreach(config IN ITEMS Debug Release RelWithDebInfo) + block() + set(RunCMake_TEST_VARIANT_DESCRIPTION "-${config}") + run_cmake_with_options(Auto${exe}ExecutableConfig ${RunCMake_TEST_OPTIONS} -DCMAKE_BUILD_TYPE=${config} -DCMAKE_AUTOGEN_VERBOSE=ON) + unset(RunCMake_TEST_VARIANT_DESCRIPTION) + set(RunCMake_TEST_NO_CLEAN 1) + set(RunCMake_TEST_EXPECT_stdout ".*running_exe_${config}*") + run_cmake_command(Auto${exe}ExecutableConfig-${config}-build ${CMAKE_COMMAND} --build .) + endblock() + endforeach() + endblock() + 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 "Auto${exe}") + set(not_expect_descripton "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/data.qrc b/Tests/RunCMake/Autogen/data.qrc new file mode 100644 index 0000000..9bd068c --- /dev/null +++ b/Tests/RunCMake/Autogen/data.qrc @@ -0,0 +1,4 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource prefix="/res/affine"> +</qresource> +</RCC> diff --git a/Tests/RunCMake/Autogen/example.cpp b/Tests/RunCMake/Autogen/example.cpp new file mode 100644 index 0000000..7f1a781 --- /dev/null +++ b/Tests/RunCMake/Autogen/example.cpp @@ -0,0 +1,5 @@ +#include "example.h" + +Example::Example() +{ +} diff --git a/Tests/RunCMake/Autogen/example.h b/Tests/RunCMake/Autogen/example.h new file mode 100644 index 0000000..e8bfa42 --- /dev/null +++ b/Tests/RunCMake/Autogen/example.h @@ -0,0 +1,12 @@ +#ifndef EXAMPLE_H +#define EXAMPLE_H + +#include <QObject> + +class Example : public QObject +{ + Q_OBJECT + Example(); +}; + +#endif diff --git a/Tests/RunCMake/Autogen/example_ui.cpp b/Tests/RunCMake/Autogen/example_ui.cpp new file mode 100644 index 0000000..fb97c32 --- /dev/null +++ b/Tests/RunCMake/Autogen/example_ui.cpp @@ -0,0 +1,5 @@ +#include "example_ui.h" + +Example::Example() +{ +} diff --git a/Tests/RunCMake/Autogen/example_ui.h b/Tests/RunCMake/Autogen/example_ui.h new file mode 100644 index 0000000..d691133 --- /dev/null +++ b/Tests/RunCMake/Autogen/example_ui.h @@ -0,0 +1,14 @@ +#ifndef EXAMPLE_UI_H +#define EXAMPLE_UI_H + +#include <QObject> + +#include "ui_uiA.h" + +class Example : public QObject +{ + Q_OBJECT + Example(); +}; + +#endif diff --git a/Tests/RunCMake/Autogen/exe.cpp b/Tests/RunCMake/Autogen/exe.cpp new file mode 100644 index 0000000..f8b643a --- /dev/null +++ b/Tests/RunCMake/Autogen/exe.cpp @@ -0,0 +1,4 @@ +int main() +{ + return 0; +} diff --git a/Tests/RunCMake/Autogen/exe_common.h b/Tests/RunCMake/Autogen/exe_common.h new file mode 100644 index 0000000..15311c6 --- /dev/null +++ b/Tests/RunCMake/Autogen/exe_common.h @@ -0,0 +1,48 @@ +#ifndef EXE_COMMON_H +#define EXE_COMMON_H + +#include <cstdlib> +#include <fstream> +#include <string> +#include <vector> + +inline int runRealExe(const int argc, char** argv) +{ + std::vector<std::string> args; + std::string realMocPath; + std::string const pathArg = "EXE_PATH="; + std::string cmd; + if (argc > 1) { + for (int i = 1; i < argc; ++i) { + std::string const arg = argv[i]; + if (arg.find(pathArg) != std::string::npos) { + realMocPath = arg.substr(pathArg.length()); + // if EXE_PATH contains spaces, wrap it in quotes + if (realMocPath.find(" ") != std::string::npos) { + realMocPath = "\"" + realMocPath + "\""; + } + } else { + args.push_back(arg); + } + } + } +#ifdef _WIN32 + cmd += "cmd /C \""; +#endif + cmd += realMocPath + " "; + for (auto arg : args) { + // if arg contains spaces, wrap it in quotes + if (arg.find(' ') != std::string::npos) { + cmd += " \"" + arg + "\""; + } else { + cmd += " " + arg; + } + } +#ifdef _WIN32 + cmd += "\""; +#endif + std::cout << "Running real exe:" << cmd << std::endl; + return std::system(cmd.c_str()); +} + +#endif diff --git a/Tests/RunCMake/Autogen/exe_debug.cpp b/Tests/RunCMake/Autogen/exe_debug.cpp new file mode 100644 index 0000000..ae5185b --- /dev/null +++ b/Tests/RunCMake/Autogen/exe_debug.cpp @@ -0,0 +1,10 @@ +#include <fstream> +#include <iostream> + +#include "exe_common.h" + +int main(int argc, char* argv[]) +{ + std::cout << "running_exe_Debug\n"; + return runRealExe(argc, argv); +} diff --git a/Tests/RunCMake/Autogen/exe_release.cpp b/Tests/RunCMake/Autogen/exe_release.cpp new file mode 100644 index 0000000..384c992 --- /dev/null +++ b/Tests/RunCMake/Autogen/exe_release.cpp @@ -0,0 +1,10 @@ +#include <fstream> +#include <iostream> + +#include "exe_common.h" + +int main(int argc, char* argv[]) +{ + std::cout << "running_exe_Release\n"; + return runRealExe(argc, argv); +} diff --git a/Tests/RunCMake/Autogen/exe_relwithdebinfo.cpp b/Tests/RunCMake/Autogen/exe_relwithdebinfo.cpp new file mode 100644 index 0000000..aa6c558 --- /dev/null +++ b/Tests/RunCMake/Autogen/exe_relwithdebinfo.cpp @@ -0,0 +1,10 @@ +#include <fstream> +#include <iostream> + +#include "exe_common.h" + +int main(int argc, char* argv[]) +{ + std::cout << "running_exe_RelWithDebInfo\n"; + return runRealExe(argc, argv); +} diff --git a/Tests/RunCMake/Autogen/uiA.ui b/Tests/RunCMake/Autogen/uiA.ui new file mode 100644 index 0000000..4c5762e --- /dev/null +++ b/Tests/RunCMake/Autogen/uiA.ui @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>UiA</class> + <widget class="QWidget" name="UiA"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QTreeView" name="treeView"/> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/Tests/RunCMake/NinjaMultiConfig/QtX-debug-in-release-graph-build-check.cmake b/Tests/RunCMake/NinjaMultiConfig/QtX-debug-in-release-graph-build-check.cmake deleted file mode 100644 index 2d8df13..0000000 --- a/Tests/RunCMake/NinjaMultiConfig/QtX-debug-in-release-graph-build-check.cmake +++ /dev/null @@ -1,7 +0,0 @@ -check_files("${RunCMake_TEST_BINARY_DIR}" - INCLUDE - ${AUTOGEN_FILES} - - ${TARGET_FILE_exe_Debug} - ${TARGET_OBJECT_FILES_exe_Debug} - ) diff --git a/Tests/RunCMake/NinjaMultiConfig/QtX.cmake b/Tests/RunCMake/NinjaMultiConfig/QtX.cmake index 130f883..4d1bf13 100644 --- a/Tests/RunCMake/NinjaMultiConfig/QtX.cmake +++ b/Tests/RunCMake/NinjaMultiConfig/QtX.cmake @@ -19,16 +19,32 @@ if(${QtX}Core_VERSION VERSION_GREATER_EQUAL "5.15.0") set(moc_writes_depfiles 1) endif() -set(autogen_files) -if(moc_writes_depfiles) - list(APPEND autogen_files "${CMAKE_BINARY_DIR}/exe_autogen/deps") - list(APPEND autogen_files "${CMAKE_BINARY_DIR}/exe_autogen/timestamp") -endif() -foreach(c IN LISTS CMAKE_CONFIGURATION_TYPES) - list(APPEND autogen_files "${CMAKE_BINARY_DIR}/exe_autogen/mocs_compilation_${c}.cpp") - list(APPEND autogen_files "${CMAKE_BINARY_DIR}/exe_autogen/include_${c}/moc_qt5.cpp") +foreach(CONFIG IN LISTS CMAKE_CONFIGURATION_TYPES) + set(config_suffix "_${CONFIG}") + if (CMAKE_AUTOGEN_BETTER_GRAPH_MULTI_CONFIG) + set(autogen_files_config_suffix "${config_suffix}") + endif() + set(autogen_files) if(moc_writes_depfiles) - list(APPEND autogen_files "${CMAKE_BINARY_DIR}/exe_autogen/include_${c}/moc_qt5.cpp.d") + list(APPEND autogen_files "${CMAKE_BINARY_DIR}/exe_autogen/deps${autogen_files_config_suffix}") + list(APPEND autogen_files "${CMAKE_BINARY_DIR}/exe_autogen/timestamp${autogen_files_config_suffix}") endif() + if (CMAKE_AUTOGEN_BETTER_GRAPH_MULTI_CONFIG) + list(APPEND autogen_files "${CMAKE_BINARY_DIR}/exe_autogen/mocs_compilation${config_suffix}.cpp") + list(APPEND autogen_files "${CMAKE_BINARY_DIR}/exe_autogen/include${config_suffix}/moc_qt5.cpp") + if(moc_writes_depfiles) + list(APPEND autogen_files "${CMAKE_BINARY_DIR}/exe_autogen/include${config_suffix}/moc_qt5.cpp.d") + endif() + else() + foreach(c IN LISTS CMAKE_CONFIGURATION_TYPES) + list(APPEND autogen_files "${CMAKE_BINARY_DIR}/exe_autogen/mocs_compilation_${c}.cpp") + list(APPEND autogen_files "${CMAKE_BINARY_DIR}/exe_autogen/include_${c}/moc_qt5.cpp") + if(moc_writes_depfiles) + list(APPEND autogen_files "${CMAKE_BINARY_DIR}/exe_autogen/include_${c}/moc_qt5.cpp.d") + endif() + endforeach() + endif() + + file(APPEND "${CMAKE_BINARY_DIR}/target_files.cmake" "set(AUTOGEN_FILES${config_suffix} [==[${autogen_files}]==])\n") + unset(autogen_files) endforeach() -file(APPEND "${CMAKE_BINARY_DIR}/target_files.cmake" "set(AUTOGEN_FILES [==[${autogen_files}]==])\n") diff --git a/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake b/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake index 5c6a22d..88fd1e8 100644 --- a/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake +++ b/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake @@ -488,11 +488,65 @@ if(CMake_TEST_Qt_version) "-D${QtX}Core_DIR=${${QtX}Core_DIR}" "-DCMAKE_PREFIX_PATH:STRING=${CMAKE_PREFIX_PATH}" ) - run_cmake_configure(QtX) - unset(RunCMake_TEST_OPTIONS) - include(${RunCMake_TEST_BINARY_DIR}/target_files.cmake) - run_cmake_build(QtX debug-in-release-graph Release exe:Debug) + + foreach(use_better_graph IN ITEMS ON OFF) + foreach(target_config IN ITEMS Debug Release RelWithDebInfo) + foreach(ninja_config IN ITEMS Debug Release RelWithDebInfo) + block() + set(target_config_suffix "_${target_config}") + if (use_better_graph) + set(autogen_files_config_suffix "${target_config_suffix}") + else() + set(autogen_files_config_suffix "") + endif() + set(prefix "QtX") + set(case "${target_config}-in-${ninja_config}-better-graph-${use_better_graph}") + set(test_path "${prefix}-${case}") + set(RunCMake_TEST_VARIANT_DESCRIPTION "-${case}-configure") + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${test_path}-build) + run_cmake_with_options(QtX ${RunCMake_TEST_OPTIONS} + "-DCMAKE_AUTOGEN_BETTER_GRAPH_MULTI_CONFIG=${use_better_graph}") + unset(RunCMake_TEST_VARIANT_DESCRIPTION) + include(${RunCMake_TEST_BINARY_DIR}/target_files.cmake) + run_cmake_build(${test_path} "" ${ninja_config} exe:${target_config}) + check_files("${RunCMake_TEST_BINARY_DIR}" + INCLUDE + "${AUTOGEN_FILES${target_config_suffix}}" + "${TARGET_FILE_exe${target_config_suffix}}" + "${TARGET_OBJECT_FILES_exe${target_config_suffix}}" + ) + if (DEFINED RunCMake_TEST_FAILED AND NOT RunCMake_TEST_FAILED STREQUAL "") + message(FATAL_ERROR "RunCMake_TEST_FAILED:${RunCMake_TEST_FAILED}") + else() + message(STATUS "${test_path}-check-files - PASSED") + endif() + + check_file_contents("${RunCMake_TEST_BINARY_DIR}/exe_autogen/deps${autogen_files_config_suffix}" + "exe_autogen/timestamp${autogen_files_config_suffix}") + if (DEFINED RunCMake_TEST_FAILED AND NOT RunCMake_TEST_FAILED STREQUAL "") + message(FATAL_ERROR "RunCMake_TEST_FAILED:${RunCMake_TEST_FAILED}") + endif() + endblock() + endforeach() + endforeach() + endforeach() + if(CMake_TEST_${QtX}Core_Version VERSION_GREATER_EQUAL 5.15.0) - run_ninja(QtX automoc-check build-Debug.ninja -t query exe_autogen/timestamp) + foreach(use_better_graph IN ITEMS ON OFF) + foreach(target_config IN ITEMS Debug Release RelWithDebInfo) + foreach(ninja_config IN ITEMS Debug Release RelWithDebInfo) + set(prefix "QtX") + set(case "${target_config}-in-${ninja_config}-better-graph-${use_better_graph}") + set(test_path "${prefix}-${case}") + if (use_better_graph) + set(autogen_files_config_suffix "_${target_config}") + else() + set(autogen_files_config_suffix "") + endif() + set(RunCMake_TEST_VARIANT_DESCRIPTION "-automoc-check") + run_ninja(${test_path} "" build-${ninja_config}.ninja -t query exe_autogen/timestamp${autogen_files_config_suffix}) + endforeach() + endforeach() + endforeach() endif() endif() |