blob: 99bbbbf90f7dd4ae8211d539c977f6eab2150a68 [file] [log] [blame]
# Find nosetests; see add_nosetests() from utils.cmake for opting in to
# nosetests in a specific directory.
find_program(NOSETESTS_EXE NAMES nosetests)
if (NOT NOSETESTS_EXE)
message(STATUS "nosetests was not found - python code will not be tested")
endif()
# Find asciidoctor; see add_asciidoc() from utils.cmake for
# adding documents.
find_program(ASCIIDOCTOR_EXE NAMES asciidoctor)
if (NOT ASCIIDOCTOR_EXE)
message(STATUS "asciidoctor was not found - no documentation will be"
" generated")
endif()
# On Windows, CMake by default compiles with the shared CRT.
# Ensure that gmock compiles the same, otherwise failures will occur.
if(WIN32)
# TODO(awoloszyn): Once we support selecting CRT versions,
# make sure this matches correctly.
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
endif(WIN32)
find_program(PYTHON_EXE python REQUIRED)
option(ENABLE_CODE_COVERAGE "Enable collecting code coverage." OFF)
if (ENABLE_CODE_COVERAGE)
if (NOT UNIX)
message(FATAL_ERROR "Code coverage on non-UNIX system not supported yet.")
endif()
if (NOT "${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
message(FATAL_ERROR "Code coverage with non-Debug build can be misleading.")
endif()
find_program(LCOV_EXE NAMES lcov)
if (NOT LCOV_EXE)
message(FATAL_ERROR "lcov was not found")
endif()
find_program(GENHTML_EXE NAMES genhtml)
if (NOT GENHTML_EXE)
message(FATAL_ERROR "genhtml was not found")
endif()
set(LCOV_BASE_DIR ${CMAKE_BINARY_DIR})
set(LCOV_INFO_FILE ${LCOV_BASE_DIR}/lcov.info)
set(COVERAGE_STAT_HTML_DIR ${LCOV_BASE_DIR}/coverage-report)
add_custom_target(clean-coverage
# Remove all gcov .gcda files in the directory recursively.
COMMAND ${LCOV_EXE} --directory . --zerocounters -q
# Remove all lcov .info files.
COMMAND ${CMAKE_COMMAND} -E remove ${LCOV_INFO_FILE}
# Remove all html report files.
COMMAND ${CMAKE_COMMAND} -E remove_directory ${COVERAGE_STAT_HTML_DIR}
# TODO(antiagainst): the following two commands are here to remedy the
# problem of "reached unexpected end of file" experienced by lcov.
# The symptom is that some .gcno files are wrong after code change and
# recompiling. We don't know the exact reason yet. Figure it out.
# Remove all .gcno files in the directory recursively.
COMMAND ${PYTHON_EXE}
${shaderc_SOURCE_DIR}/utils/remove-file-by-suffix.py . ".gcno"
# .gcno files are not tracked by CMake. So no recompiling is triggered
# even if they are missing. Unfortunately, we just removed all of them
# in the above.
COMMAND ${CMAKE_COMMAND} --build . --target clean
WORKING_DIRECTORY ${LCOV_BASE_DIR}
COMMENT "Clean coverage files"
)
add_custom_target(report-coverage
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR}
# Run all tests.
COMMAND ctest --output-on-failure
# Collect coverage data from gcov .gcda files.
COMMAND ${LCOV_EXE} --directory . --capture -o ${LCOV_INFO_FILE}
# Remove coverage info for system header files.
COMMAND ${LCOV_EXE}
--remove ${LCOV_INFO_FILE} '/usr/include/*' -o ${LCOV_INFO_FILE}
# Remove coverage info for external and third_party code.
COMMAND ${LCOV_EXE}
--remove ${LCOV_INFO_FILE} '${shaderc_SOURCE_DIR}/ext/*'
-o ${LCOV_INFO_FILE}
COMMAND ${LCOV_EXE}
--remove ${LCOV_INFO_FILE} '${shaderc_SOURCE_DIR}/third_party/*'
-o ${LCOV_INFO_FILE}
# Remove coverage info for tests.
COMMAND ${LCOV_EXE}
--remove ${LCOV_INFO_FILE} '*_test.cc' -o ${LCOV_INFO_FILE}
# Generate html report file.
COMMAND ${GENHTML_EXE}
${LCOV_INFO_FILE} -t "Coverage Report" -o ${COVERAGE_STAT_HTML_DIR}
DEPENDS clean-coverage
WORKING_DIRECTORY ${LCOV_BASE_DIR}
COMMENT "Collect and analyze coverage data"
)
endif()