1 # Macro which contains all bits and pieces to create the regression tests.
2 # This creates both a standalone target 'regression', and it integrates with
3 # 'ctest'. The first is prefered, as it is more verbose, and takes care of
4 # dependencies correctly.
6 # create_regression(file1 ...)
8 macro(create_regression)
9 set(REGRESSION_SOURCE_FILES ${ARGN})
11 foreach(REGRESSION_SOURCE_FILE IN LISTS REGRESSION_SOURCE_FILES)
12 string(REPLACE "${CMAKE_SOURCE_DIR}/regression/" "" REGRESSION_SOURCE_FILE_NAME "${REGRESSION_SOURCE_FILE}")
13 string(CONCAT REGRESSION_BINARY_FILE "${CMAKE_BINARY_DIR}/ai/" "${REGRESSION_SOURCE_FILE_NAME}")
15 add_custom_command(OUTPUT ${REGRESSION_BINARY_FILE}
16 COMMAND ${CMAKE_COMMAND} -E copy
17 ${REGRESSION_SOURCE_FILE}
18 ${REGRESSION_BINARY_FILE}
19 MAIN_DEPENDENCY ${REGRESSION_SOURCE_FILE}
20 COMMENT "Copying ${REGRESSION_SOURCE_FILE_NAME} regression file"
23 list(APPEND REGRESSION_BINARY_FILES ${REGRESSION_BINARY_FILE})
26 get_filename_component(REGRESSION_TEST_NAME "${CMAKE_CURRENT_SOURCE_DIR}" NAME)
28 # Create a new target which copies regression files
29 add_custom_target(regression_${REGRESSION_TEST_NAME}_files
31 ${REGRESSION_BINARY_FILES}
34 add_dependencies(regression_files regression_${REGRESSION_TEST_NAME}_files)
36 add_custom_target(regression_${REGRESSION_TEST_NAME}
37 COMMAND ${CMAKE_COMMAND}
38 -DOPENTTD_EXECUTABLE=$<TARGET_FILE:openttd>
39 -DEDITBIN_EXECUTABLE=${EDITBIN_EXECUTABLE}
40 -DREGRESSION_TEST=${REGRESSION_TEST_NAME}
41 -P "${CMAKE_SOURCE_DIR}/cmake/scripts/Regression.cmake"
42 DEPENDS openttd regression_${REGRESSION_TEST_NAME}_files
43 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
44 COMMENT "Running regression test ${REGRESSION_TEST_NAME}"
47 # Also make sure that 'make test' runs the regression
48 add_test(NAME regression_${REGRESSION_TEST_NAME}
49 COMMAND ${CMAKE_COMMAND}
50 -DOPENTTD_EXECUTABLE=$<TARGET_FILE:openttd>
51 -DEDITBIN_EXECUTABLE=${EDITBIN_EXECUTABLE}
52 -DREGRESSION_TEST=${REGRESSION_TEST_NAME}
53 -P "${CMAKE_SOURCE_DIR}/cmake/scripts/Regression.cmake"
54 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
57 add_dependencies(regression regression_${REGRESSION_TEST_NAME})