Files
unison/build-support/custom-modules/ns3-coverage.cmake

51 lines
1.8 KiB
CMake
Raw Normal View History

2021-11-10 22:28:44 -03:00
# Copyright (c) 2017-2021 Universidade de Brasília
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License version 2 as published by the Free
# Software Foundation;
2021-11-10 22:28:44 -03:00
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
2021-11-10 22:28:44 -03:00
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA
2021-11-10 22:28:44 -03:00
#
# Author: Gabriel Ferreira <gabrielcarvfer@gmail.com>
if(${NS3_COVERAGE})
2022-04-03 23:56:07 -03:00
mark_as_advanced(GCOV)
find_program(GCOV gcov)
if(NOT ("${GCOV}" STREQUAL "GCOV-NOTFOUND"))
2021-11-10 22:28:44 -03:00
add_definitions(--coverage)
link_libraries(-lgcov)
endif()
2022-04-03 23:56:07 -03:00
mark_as_advanced(LCOV)
find_program(LCOV lcov)
if("${LCOV}" STREQUAL "LCOV-NOTFOUND")
2021-11-10 22:28:44 -03:00
message(FATAL_ERROR "LCOV is required but it is not installed.")
endif()
if(${NS3_COVERAGE_ZERO_COUNTERS})
set(zero_counters "--lcov-zerocounters")
endif()
# The following target will run test.py --no-build to generate the code
# coverage files .gcno and .gcda output will be in ${CMAKE_BINARY_DIR} a.k.a.
# cmake-cache or cmake-build-${build_suffix}
2021-11-10 22:28:44 -03:00
# Create output directory for coverage info and html
file(MAKE_DIRECTORY ${CMAKE_OUTPUT_DIRECTORY}/coverage)
# Extract code coverage results and build html report
add_custom_target(
coverage_gcc
COMMAND lcov -o ns3.info -c --directory ${CMAKE_BINARY_DIR} ${zero_counters}
COMMAND genhtml ns3.info
WORKING_DIRECTORY ${CMAKE_OUTPUT_DIRECTORY}/coverage
DEPENDS run_test_py
)
endif()