File: AddUnittests.cmake

package info (click to toggle)
madness 0.10.1~gite4aa500e-10
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 33,452 kB
  • ctags: 30,300
  • sloc: cpp: 267,232; ansic: 12,308; python: 4,961; fortran: 4,245; xml: 1,053; makefile: 717; perl: 244; yacc: 227; lex: 188; asm: 141; sh: 139; csh: 55
file content (29 lines) | stat: -rw-r--r-- 1,113 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
29
macro(add_unittests _component _sources _libs)

  # Add targets and for world_unittests
  add_custom_target(${_component}_unittests)
  add_dependencies(unittests ${_component}_unittests)
    
  # Add a test that builds the unit tests
  add_test(build_${_component}_unittests
      "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target ${_component}_unittests)
  
  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 executables
    add_executable(${_test} EXCLUDE_FROM_ALL ${_source_list})
    target_link_libraries(${_test} ${_libs})
    
    # Add the test and set dependencies
    add_test(NAME ${_component}-${_test} COMMAND ${_test})
    add_dependencies(${_component}_unittests ${_test})
    set_tests_properties(${_component}-${_test} 
        PROPERTIES DEPENDS build_${_component}_unittests)
 
  endforeach()

endmacro()