From 84585543025b817921721ca6d173730b8393b2ac Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Fri, 2 Sep 2016 21:40:05 +0100 Subject: Update test runner to support CMake better. Add support for: * Out-of-tree builds (by passing executable name from CMake to runtest.pl) * AppVeyor test status * Cross-platform cmake (using cmake -E instead of platform-specific commands) Get CMake to install binaries needed by tests, in correct locations, with correct names. --- infrastructure/cmake/CMakeLists.txt | 98 +++++++++++++++++++++++++++++++------ 1 file changed, 82 insertions(+), 16 deletions(-) (limited to 'infrastructure/cmake/CMakeLists.txt') diff --git a/infrastructure/cmake/CMakeLists.txt b/infrastructure/cmake/CMakeLists.txt index 2038b1c9..57de5039 100644 --- a/infrastructure/cmake/CMakeLists.txt +++ b/infrastructure/cmake/CMakeLists.txt @@ -55,6 +55,23 @@ set(files_to_configure include(FindPerl) set(TARGET_PERL ${PERL_EXECUTABLE}) +function(replace_file_if_different dest_file source_file) + execute_process( + COMMAND "${CMAKE_COMMAND}" -E + copy_if_different "${source_file}" "${dest_file}") + execute_process( + COMMAND "${CMAKE_COMMAND}" -E + remove "${source_file}") +endfunction() + +function(move_file_if_exists source_file dest_file) + if(EXISTS "${source_file}") + execute_process( + COMMAND "${CMAKE_COMMAND}" -E + rename "${source_file}" "${dest_file}") + endif() +endfunction() + foreach(file_to_configure ${files_to_configure}) configure_file("${base_dir}/${file_to_configure}.in" "${base_dir}/${file_to_configure}" @ONLY) endforeach() @@ -173,6 +190,18 @@ foreach(module_dep ${module_deps}) message(STATUS "add executable '${module_name}': '${module_files}'") endif() add_executable(${module_name} ${module_files}) + + # Unfortunately we have to use install(PROGRAMS) instead of + # install(TARGETS) because TARGETS doesn't allow us to change + # the executable name. + install(PROGRAMS "$" + CONFIGURATIONS Debug + DESTINATION "${base_dir}/debug/${module_dir}" + RENAME "${bin_name}${CMAKE_EXECUTABLE_SUFFIX}") + install(PROGRAMS "$" + CONFIGURATIONS Release + DESTINATION "${base_dir}/release/${module_dir}" + RENAME "${bin_name}${CMAKE_EXECUTABLE_SUFFIX}") elseif(module_name MATCHES "^test_") string(REGEX MATCH "^test_(.*)" valid_test ${module_name}) set(test_name ${CMAKE_MATCH_1}) @@ -183,12 +212,62 @@ foreach(module_dep ${module_deps}) endif() string(REPLACE "TEST_NAME" ${test_name} test_main "${test_template}") - file(WRITE "${module_path}/_main.cpp" "${test_main}") + file(WRITE "${module_path}/_main.cpp.new" "${test_main}") + replace_file_if_different( + "${module_path}/_main.cpp" + "${module_path}/_main.cpp.new") add_executable(${module_name} ${module_files} "${module_path}/_main.cpp") + + if(WIN32) + install(PROGRAMS "$" + CONFIGURATIONS Debug + DESTINATION "${base_dir}/debug/${module_dir}") + install(PROGRAMS "$" + CONFIGURATIONS Release + DESTINATION "${base_dir}/release/${module_dir}") + set(test_executable "$") + else() + # Unfortunately we have to use install(PROGRAMS) instead of + # install(TARGETS) because TARGETS doesn't allow us to change + # the executable name. + install(PROGRAMS "$" + CONFIGURATIONS Debug + DESTINATION "${base_dir}/debug/${module_dir}" + RENAME "_test") + install(PROGRAMS "$" + CONFIGURATIONS Release + DESTINATION "${base_dir}/release/${module_dir}" + RENAME "_test") + set(test_executable "./_test") + endif() + + if(${APPVEYOR_MODE}) + set(appveyor_runtest_pl_switch -a) + else() + set(appveyor_runtest_pl_switch) + endif() + + target_compile_definitions(${module_name} PRIVATE + -DTEST_EXECUTABLE="${test_executable}") add_test(NAME ${test_name} - COMMAND ${PERL_EXECUTABLE} ${base_dir}/runtest.pl.in ${test_name} - $ WORKING_DIRECTORY ${base_dir}) + COMMAND ${PERL_EXECUTABLE} ${base_dir}/runtest.pl + ${appveyor_runtest_pl_switch} -c ${test_name} + $ "$" "${test_executable}" + WORKING_DIRECTORY ${base_dir}) + + if(${APPVEYOR_MODE}) + execute_process(COMMAND appveyor AddTest -Name ${test_name} + -Framework Custom -FileName "") + endif() + + # It helps with debugging if the test depends on another step which + # prepares the target directory, and is always out of date. + add_custom_target(${module_name}-prepare + COMMAND ${PERL_EXECUTABLE} ${base_dir}/runtest.pl + -n -c ${test_name} + $ "$" "${test_executable}" + WORKING_DIRECTORY ${base_dir}) elseif(module_name MATCHES "^(lib_.*|qdbm)$") if(DEBUG) message(STATUS "add library '${module_name}': '${module_files}'") @@ -198,19 +277,6 @@ foreach(module_dep ${module_deps}) message(FATAL_ERROR "Unsupported module type: " ${module_name}) endif() - if(module_name MATCHES "^(bin|test)_") - # We need to install binaries in specific places so that test - # runner can find them: - install(FILES "$" - CONFIGURATIONS Debug - DESTINATION "${base_dir}/debug/${module_dir}" - RENAME "${bin_name}${CMAKE_EXECUTABLE_SUFFIX}") - install(FILES "$" - CONFIGURATIONS Release - DESTINATION "${base_dir}/release/${module_dir}" - RENAME "${bin_name}${CMAKE_EXECUTABLE_SUFFIX}") - endif() - target_compile_definitions(${module_name} PRIVATE -DBOX_MODULE="${module_name}") if(dependencies) -- cgit v1.2.3