File: AddUnittests.cmake

package info (click to toggle)
madness 0.10.1%2Bgit20200818.eee5fd9f-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 34,980 kB
  • sloc: cpp: 280,841; ansic: 12,626; python: 4,961; fortran: 4,245; xml: 1,053; makefile: 714; sh: 276; perl: 244; yacc: 227; lex: 188; asm: 141; csh: 55
file content (28 lines) | stat: -rw-r--r-- 1,109 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
macro(add_unittests _component _sources _libs)

  # Add targets and for world_unittests
  add_custom_target_subproject(madness ${_component}_unittests)
  add_dependencies(unittests-madness ${_component}_unittests-madness)

  # Add a test that builds the unit tests
  add_test(build_${_component}_unittests
      "${CMAKE_COMMAND}" --build ${PROJECT_BINARY_DIR} --target ${_component}_unittests-madness)
  
  foreach(_source ${_sources})
    # Get the test name (the file name of the first source)
    string(REGEX MATCH "[A-Za-z_][A-Za-z0-9_]*\\.cc" _test_source "${_source}")
    string(REGEX MATCHALL "[A-Za-z0-9_\\.\\$<:>]+" _source_list "${_source}")
    get_filename_component(_test "${_test_source}" NAME_WE)
    
    # Create test executable
    add_mad_executable(${_test} "${_source_list}" "${_libs}")

    # Add the test and set dependencies
    add_test(NAME ${_component}-${_test} COMMAND ${_test})
    add_dependencies(${_component}_unittests-madness ${_test})
    set_tests_properties(${_component}-${_test} 
        PROPERTIES DEPENDS build_${_component}_unittests)
 
  endforeach()

endmacro()