Add Code Coverage support using CMake (#265)

This commit is contained in:
Chuck Walbourn 2024-10-08 18:23:07 -07:00 коммит произвёл GitHub
Родитель 41a842c8b9
Коммит 65f12b369c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
3 изменённых файлов: 44 добавлений и 4 удалений

Просмотреть файл

@ -29,6 +29,8 @@ option(DISABLE_MSVC_ITERATOR_DEBUGGING "Disable iterator debugging in Debug conf
option(ENABLE_CODE_ANALYSIS "Use Static Code Analysis on build" OFF)
option(ENABLE_CODE_COVERAGE "Build with code-coverage" OFF)
option(USE_PREBUILT_SHADERS "Use externally built HLSL shaders" OFF)
option(BUILD_DXIL_SHADERS "Use DXC Shader Model 6 for shaders" ON)
@ -485,6 +487,10 @@ if(WIN32 AND (NOT WINDOWS_STORE) AND (NOT (DEFINED XBOX_CONSOLE_TARGET)))
if(BUILD_TESTING AND (EXISTS "${CMAKE_CURRENT_LIST_DIR}/Tests/CMakeLists.txt"))
enable_testing()
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/Tests)
if(ENABLE_CODE_COVERAGE AND (DEFINED COV_COMPILER_SWITCHES))
target_compile_options(${PROJECT_NAME} PRIVATE ${COV_COMPILER_SWITCHES})
endif()
elseif(BUILD_FUZZING AND (EXISTS "${CMAKE_CURRENT_LIST_DIR}/Tests/fuzzloaders/CMakeLists.txt"))
message(STATUS "Building for fuzzing")
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/Tests/fuzzloaders)

Просмотреть файл

@ -243,6 +243,23 @@
},
"hidden": true
},
{
"name": "Analyze",
"cacheVariables":
{
"ENABLE_CODE_ANALYSIS": true
},
"hidden": true
},
{
"name": "Coverage",
"cacheVariables":
{
"ENABLE_CODE_COVERAGE": true
},
"hidden": true
},
{
"name": "Fuzzing",
"cacheVariables": {
@ -327,8 +344,10 @@
{ "name": "x64-Debug-ICX" , "description": "Intel oneAPI Compiler (Debug) for Windows 10", "inherits": [ "base", "x64", "Debug", "IntelLLVM" ] },
{ "name": "x64-Release-ICX" , "description": "Intel oneAPI Compiler (Release) for Windows 10", "inherits": [ "base", "x64", "Release", "IntelLLVM" ] },
{ "name": "x64-Fuzzing" , "description": "MSVC for x64 (Release) with ASan", "inherits": [ "base", "x64", "Release", "MSVC", "Fuzzing" ] },
{ "name": "x64-Analyze" , "description": "MSVC for x64 (Debug) using /analyze", "inherits": [ "base", "x64", "Debug", "MSVC" ], "cacheVariables": { "ENABLE_CODE_ANALYSIS": true } }
{ "name": "x64-Analyze" , "description": "MSVC for x64 (Debug) using /analyze", "inherits": [ "base", "x64", "Debug", "MSVC", "Analyze" ] },
{ "name": "x64-Coverage" , "description": "MSVC for x64 (Debug) w/ Code Coverage", "inherits": [ "base", "x64", "Debug", "MSVC", "Coverage" ] },
{ "name": "x64-Coverage-Clang", "description": "Clang/LLVM for x64 (Debug) w/ Code Coverage", "inherits": [ "base", "x64", "Debug", "Clang", "Coverage" ] },
{ "name": "x64-Fuzzing" , "description": "MSVC for x64 (Release) with ASan", "inherits": [ "base", "x64", "Release", "MSVC", "Fuzzing" ] }
],
"testPresets": [
{ "name": "x64-Debug" , "configurePreset": "x64-Debug" },

Просмотреть файл

@ -49,7 +49,7 @@ if(MSVC)
list(APPEND COMPILER_SWITCHES "$<$<NOT:$<CONFIG:DEBUG>>:/guard:cf>")
list(APPEND LINKER_SWITCHES /DYNAMICBASE /NXCOMPAT /INCREMENTAL:NO)
if((${DIRECTX_ARCH} MATCHES "x86")
if((${DIRECTX_ARCH} STREQUAL "x86")
OR ((CMAKE_SIZEOF_VOID_P EQUAL 4) AND (NOT (${DIRECTX_ARCH} MATCHES "^arm"))))
list(APPEND LINKER_SWITCHES /SAFESEH)
endif()
@ -71,7 +71,7 @@ if(XBOX_CONSOLE_TARGET STREQUAL "scarlett")
elseif(XBOX_CONSOLE_TARGET MATCHES "xboxone|durango")
list(APPEND COMPILER_SWITCHES $<IF:$<CXX_COMPILER_ID:MSVC>,/favor:AMD64 /arch:AVX,-march=btver2>)
elseif(NOT (${DIRECTX_ARCH} MATCHES "^arm"))
if((${DIRECTX_ARCH} MATCHES "x86") OR (CMAKE_SIZEOF_VOID_P EQUAL 4))
if((${DIRECTX_ARCH} STREQUAL "x86") OR (CMAKE_SIZEOF_VOID_P EQUAL 4))
set(ARCH_SSE2 $<$<CXX_COMPILER_ID:MSVC,Intel>:/arch:SSE2> $<$<NOT:$<CXX_COMPILER_ID:MSVC,Intel>>:-msse2>)
else()
set(ARCH_SSE2 $<$<NOT:$<CXX_COMPILER_ID:MSVC,Intel>>:-msse2>)
@ -207,3 +207,18 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set(ASAN_SWITCHES /fsanitize=address /fsanitize-coverage=inline-8bit-counters /fsanitize-coverage=edge /fsanitize-coverage=trace-cmp /fsanitize-coverage=trace-div)
set(ASAN_LIBS sancov.lib)
endif()
#--- Code coverage
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(COV_COMPILER_SWITCHES --coverage -g)
if(${DIRECTX_ARCH} STREQUAL "x64")
set(COV_LIBS clang_rt.profile-x86_64.lib)
elseif(${DIRECTX_ARCH} STREQUAL "x86")
set(COV_LIBS clang_rt.profile-i386.lib)
elseif(${DIRECTX_ARCH} STREQUAL "arm64")
set(COV_LIBS clang_rt.profile-aarch64.lib)
endif()
elseif((CMAKE_CXX_COMPILER_ID MATCHES "MSVC") AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.33))
set(COV_LINKER_SWITCHES /PROFILE)
endif()