summaryrefslogtreecommitdiff
path: root/infrastructure/cmake
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2016-09-02 21:40:05 +0100
committerChris Wilson <chris+github@qwirx.com>2016-08-28 22:09:52 +0100
commit84585543025b817921721ca6d173730b8393b2ac (patch)
tree1ada4629819cb573b951ca6ff6c656046eae3185 /infrastructure/cmake
parent688eda8b55b57b711020148c5b048de7c06d1744 (diff)
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.
Diffstat (limited to 'infrastructure/cmake')
-rw-r--r--infrastructure/cmake/CMakeLists.txt98
1 files changed, 82 insertions, 16 deletions
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 "$<TARGET_FILE:${module_name}>"
+ CONFIGURATIONS Debug
+ DESTINATION "${base_dir}/debug/${module_dir}"
+ RENAME "${bin_name}${CMAKE_EXECUTABLE_SUFFIX}")
+ install(PROGRAMS "$<TARGET_FILE:${module_name}>"
+ 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 "$<TARGET_FILE:${module_name}>"
+ CONFIGURATIONS Debug
+ DESTINATION "${base_dir}/debug/${module_dir}")
+ install(PROGRAMS "$<TARGET_FILE:${module_name}>"
+ CONFIGURATIONS Release
+ DESTINATION "${base_dir}/release/${module_dir}")
+ set(test_executable "$<TARGET_FILE_NAME:${module_name}>")
+ 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 "$<TARGET_FILE:${module_name}>"
+ CONFIGURATIONS Debug
+ DESTINATION "${base_dir}/debug/${module_dir}"
+ RENAME "_test")
+ install(PROGRAMS "$<TARGET_FILE:${module_name}>"
+ 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}
- $<CONFIG> WORKING_DIRECTORY ${base_dir})
+ COMMAND ${PERL_EXECUTABLE} ${base_dir}/runtest.pl
+ ${appveyor_runtest_pl_switch} -c ${test_name}
+ $<CONFIG> "$<TARGET_FILE:${module_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}
+ $<CONFIG> "$<TARGET_FILE:${module_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 "$<TARGET_FILE:${module_name}>"
- CONFIGURATIONS Debug
- DESTINATION "${base_dir}/debug/${module_dir}"
- RENAME "${bin_name}${CMAKE_EXECUTABLE_SUFFIX}")
- install(FILES "$<TARGET_FILE:${module_name}>"
- 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)