mirror of
https://github.com/LizardByte/Sunshine.git
synced 2026-09-03 06:34:27 +08:00
build(Linux): use compiler-selected libgcov for coverage (#5597)
This commit is contained in:
@@ -191,7 +191,9 @@ check() {
|
||||
export CXX="g++${_gcc_env_suffix}"
|
||||
|
||||
cd "${srcdir}/build/tests"
|
||||
./test_sunshine --gtest_color=yes --gtest_output=xml:test_results.xml
|
||||
# Do not silently upload misleading coverage if the gcov runtime cannot
|
||||
# write profile data, such as when its version differs from the compiler.
|
||||
GCOV_EXIT_AT_ERROR=1 ./test_sunshine --gtest_color=yes --gtest_output=xml:test_results.xml
|
||||
|
||||
# Generate coverage report
|
||||
# Run gcovr from the build directory (where all .gcda/.gcno files are)
|
||||
|
||||
@@ -34,42 +34,23 @@ else()
|
||||
set(CMAKE_C_FLAGS "-fprofile-arcs -ftest-coverage -ggdb -O0")
|
||||
endif()
|
||||
|
||||
# Find the correct libgcov library path matching the gcc compiler version
|
||||
# This ensures the test executable links against the same libgcov version used during compilation
|
||||
if(UNIX AND NOT APPLE)
|
||||
# Get the gcc compiler version
|
||||
# Link the libgcov that belongs to the selected compiler. Asking GCC directly
|
||||
# avoids selecting another installed GCC version through platform-specific
|
||||
# library directory names (for example, the GCC required by CUDA on Arch Linux).
|
||||
if(UNIX AND NOT APPLE AND CMAKE_C_COMPILER_ID STREQUAL "GNU")
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_C_COMPILER} -dumpversion
|
||||
OUTPUT_VARIABLE GCC_VERSION
|
||||
COMMAND ${CMAKE_C_COMPILER} -print-file-name=libgcov.a
|
||||
OUTPUT_VARIABLE LIBGCOV_LIBRARY
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
RESULT_VARIABLE LIBGCOV_RESULT
|
||||
)
|
||||
|
||||
# Extract major version
|
||||
string(REGEX MATCH "^[0-9]+" GCC_MAJOR_VERSION "${GCC_VERSION}")
|
||||
|
||||
# Search for the gcc library directory matching this version
|
||||
file(GLOB GCC_LIB_DIRS "/usr/lib/gcc/*/*${GCC_MAJOR_VERSION}.*")
|
||||
|
||||
if(GCC_LIB_DIRS)
|
||||
list(GET GCC_LIB_DIRS 0 GCC_LIB_DIR)
|
||||
message(STATUS "Found GCC library directory: ${GCC_LIB_DIR}")
|
||||
|
||||
# Look for libgcov.a in the gcc library directory
|
||||
find_library(LIBGCOV_LIBRARY
|
||||
NAMES gcov
|
||||
PATHS ${GCC_LIB_DIR}
|
||||
NO_DEFAULT_PATH
|
||||
)
|
||||
|
||||
if(LIBGCOV_LIBRARY)
|
||||
message(STATUS "Found libgcov: ${LIBGCOV_LIBRARY}")
|
||||
# Store this to link against later
|
||||
set(GCOV_LINK_LIBRARY ${LIBGCOV_LIBRARY})
|
||||
else()
|
||||
message(WARNING "Could not find libgcov in ${GCC_LIB_DIR}")
|
||||
endif()
|
||||
if(LIBGCOV_RESULT EQUAL 0 AND EXISTS "${LIBGCOV_LIBRARY}")
|
||||
message(STATUS "Found libgcov: ${LIBGCOV_LIBRARY}")
|
||||
set(GCOV_LINK_LIBRARY "${LIBGCOV_LIBRARY}")
|
||||
else()
|
||||
message(WARNING "Could not find GCC library directory for version ${GCC_VERSION}")
|
||||
message(WARNING "Could not find libgcov for ${CMAKE_C_COMPILER}")
|
||||
unset(GCOV_LINK_LIBRARY)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user