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.
8 macro(create_regression)
9 # Find all the files in the regression folder; they need to be copied to the
10 # build folder before we can run the regression
11 file(GLOB_RECURSE REGRESSION_SOURCE_FILES ${CMAKE_SOURCE_DIR}/regression/*)
12 foreach(REGRESSION_SOURCE_FILE IN LISTS REGRESSION_SOURCE_FILES)
13 string(REPLACE "${CMAKE_SOURCE_DIR}/regression/" "" REGRESSION_SOURCE_FILE_NAME "${REGRESSION_SOURCE_FILE}")
14 string(CONCAT REGRESSION_BINARY_FILE "${CMAKE_BINARY_DIR}/ai/" "${REGRESSION_SOURCE_FILE_NAME}")
16 if("${REGRESSION_SOURCE_FILE_NAME}" STREQUAL "regression.cfg")
20 add_custom_command(OUTPUT ${REGRESSION_BINARY_FILE}
21 COMMAND ${CMAKE_COMMAND} -E copy
22 ${REGRESSION_SOURCE_FILE}
23 ${REGRESSION_BINARY_FILE}
24 MAIN_DEPENDENCY ${REGRESSION_SOURCE_FILE}
25 COMMENT "Copying ${REGRESSION_SOURCE_FILE_NAME} regression file"
28 list(APPEND REGRESSION_BINARY_FILES ${REGRESSION_BINARY_FILE})
31 # Copy the regression configuration in a special folder, so all autogenerated
32 # folders end up in the same place after running regression.
33 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/regression/regression.cfg
34 COMMAND ${CMAKE_COMMAND} -E copy
35 ${CMAKE_SOURCE_DIR}/regression/regression.cfg
36 ${CMAKE_BINARY_DIR}/regression/regression.cfg
37 MAIN_DEPENDENCY ${CMAKE_SOURCE_DIR}/regression/regression.cfg
38 COMMENT "Copying ${REGRESSION_SOURCE_FILE_NAME} regression file"
40 list(APPEND REGRESSION_BINARY_FILES ${CMAKE_BINARY_DIR}/regression/regression.cfg)
42 # Create a new target which copies all regression files
43 add_custom_target(regression_files
44 ALL # this is needed because 'make test' doesn't resolve dependencies, and otherwise this is never executed
46 ${REGRESSION_BINARY_FILES}
51 # Find all the tests we have, and create a target for them
52 file(GLOB REGRESSION_TESTS ${CMAKE_SOURCE_DIR}/regression/*)
53 foreach(REGRESSION_TEST IN LISTS REGRESSION_TESTS)
54 get_filename_component(REGRESSION_TEST_NAME "${REGRESSION_TEST}" NAME)
56 if("${REGRESSION_TEST_NAME}" STREQUAL "regression.cfg")
60 add_custom_target(regression_${REGRESSION_TEST_NAME}
61 COMMAND ${CMAKE_COMMAND}
62 -DOPENTTD_EXECUTABLE=$<TARGET_FILE:openttd>
63 -DEDITBIN_EXECUTABLE=${EDITBIN_EXECUTABLE}
64 -DREGRESSION_TEST=${REGRESSION_TEST_NAME}
65 -P "${CMAKE_SOURCE_DIR}/cmake/scripts/Regression.cmake"
66 DEPENDS openttd regression_files
67 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
68 COMMENT "Running regression test ${REGRESSION_TEST_NAME}"
71 # Also make sure that 'make test' runs the regression
72 add_test(NAME regression_${REGRESSION_TEST_NAME}
73 COMMAND ${CMAKE_COMMAND}
74 -DOPENTTD_EXECUTABLE=$<TARGET_FILE:openttd>
75 -DEDITBIN_EXECUTABLE=${EDITBIN_EXECUTABLE}
76 -DREGRESSION_TEST=${REGRESSION_TEST_NAME}
77 -P "${CMAKE_SOURCE_DIR}/cmake/scripts/Regression.cmake"
78 WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
80 list(APPEND REGRESSION_TARGETS regression_${REGRESSION_TEST_NAME})
83 # Create a new target which runs the regression
84 add_custom_target(regression
85 DEPENDS ${REGRESSION_TARGETS})