DumuxTestMacros.cmake 2.53 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
###
# Add a test. All necessary calls to dune CMake macros for adding a
# test are called from this macro.
# The added test is automatically build if cmake is invode with the command
# line argument -DDUMUX_BUILD_ALL_TESTS:BOOL=TRUE otherwise the test is
# built only when "ctest" / "make test" is invoked.
# The test is only built if it does not already exist.
#
# Arguments:
# - dumux_test:                   name of the new test
# - dumux_test_executable:        name of the executable required by the test
# - dumux_test_executable_source: source file (.cc) of the new test
# - further arguments:            are optional and are used as arguments for calling the test
###
macro(add_dumux_test dumux_test dumux_test_executable dumux_test_executable_source)
16
  # if present, symlink the grids folder
17
18
  set(grids_directory ${CMAKE_CURRENT_SOURCE_DIR}/grids)
  if(EXISTS ${grids_directory} AND IS_DIRECTORY ${grids_directory})
19
    dune_symlink_to_source_files(FILES grids)
20
  endif()
21

22
  # if present, symlink the input file
23
24
25
26
27
28
  set(input_file ${CMAKE_CURRENT_SOURCE_DIR}/${dumux_test_executable}.input)
  if(NOT EXISTS ${input_file})
    get_filename_component(base_source_name ${dumux_test_executable_source} NAME_WE)
    set(input_file ${CMAKE_CURRENT_SOURCE_DIR}/${base_source_name}.input)
  endif()
  if(EXISTS ${input_file})
29
30
31
    # dune symlink takes a path relative to the source directory
    get_filename_component(input_file ${input_file} NAME_WE)
    dune_symlink_to_source_files(FILES ${input_file}.input)
32
33
  endif()

34
35
36
37
38
  # get optional arguments
  # cannot use ARGN directly with list() command, copy to a variable first
  set(dumux_test_args ${ARGN})
  list(LENGTH dumux_test_args num_dumux_test_args)

39
40
41
  # add executable
  # check whether executable already exists
  if(NOT TARGET ${dumux_test_executable})
42
    add_executable(${dumux_test_executable} ${dumux_test_executable_source})
43
  endif()
44
45

  # add test
46
  if(DUNE_COMMON_VERSION VERSION_LESS 2.5)
47
48
    # add test
    add_test(${dumux_test} ${dumux_test_args})
49

50
51
52
53
    # return code 77 should be interpreted as skipped test
    set_tests_properties(${dumux_test} PROPERTIES SKIP_RETURN_CODE 77)
    # tests always require the executable to run
    set_tests_properties(${dumux_test} PROPERTIES REQUIRED_FILES ${dumux_test_executable})
54
55
56
  else()
    dune_add_test(NAME ${dumux_test}
                  TARGET ${dumux_test_executable}
57
                  COMMAND ${dumux_test_args})
58
    # tests always require the executable to run
59
    set_tests_properties(${dumux_test} PROPERTIES REQUIRED_FILES ${dumux_test_executable})
60
  endif()
61
endmacro()