test/CMakeLists.txt
author Tero Marttila <terom@fixme.fi>
Fri, 08 May 2009 00:11:35 +0300
changeset 187 5d100c79521a
parent 186 33ef336dbb4b
child 191 031582f7b61b
permissions -rw-r--r--
fix CMake TEST_OBJECT_PATH, ENABLE_TEST_COVERAGE test-target and cleanup of .gcda's
find_package (LCOV)

# static flags
set (TEST_FLAGS --debug)

# add LCOV coverage stuff
if (LCOV_FOUND)
    # static flags
    set (LCOV_FLAGS )
    set (LCOV_GENHTML_FLAGS )

    # path to the file generated by `lcov --capture`
    set (LCOV_CAPTURE_PATH ${CMAKE_CURRENT_BINARY_DIR}/lcov-capture-info)

    message (STATUS "test object files are located in ${TEST_OBJECT_DIR}")

    # unless coverage is disabled
    if (ENABLE_TEST_COVERAGE)
        # create the test target with lcov instrumentation
        add_custom_target (test
            COMMAND ${CMAKE_COMMAND} -DTEST_OBJECT_DIR="${TEST_OBJECT_DIR}" -P "${CMAKE_CURRENT_SOURCE_DIR}/CleanProfileData.cmake"
            COMMAND test_harness ${TEST_FLAGS}
            COMMAND ${LCOV_EXECUTABLE} ${LCOV_FLAGS} --directory ${TEST_OBJECT_DIR} --capture --output-file ${LCOV_CAPTURE_PATH}
            COMMAND ${LCOV_GENHTML_EXECUTABLE} ${LCOV_GENHTML_FLAGS} --output-directory ${CMAKE_CURRENT_BINARY_DIR} ${LCOV_CAPTURE_PATH}
        )

        set (TEST_TARGET_DEFINED TRUE)
    endif (ENABLE_TEST_COVERAGE)
endif (LCOV_FOUND)

if (NOT TEST_TARGET_DEFINED)
    # add default `test` target
    add_custom_target (test
        COMMAND test_harness ${TEST_FLAGS}
    )
        
    set (TEST_TARGET_DEFINED TRUE)

endif (NOT TEST_TARGET_DEFINED)

# add utility targets to run the test_harness executable
add_custom_target (test_list
    COMMAND test_harness ${TEST_FLAGS} --list
)