Add Code Coverage support using CMake (#265)
This commit is contained in:
Родитель
41a842c8b9
Коммит
65f12b369c
|
@ -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_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(USE_PREBUILT_SHADERS "Use externally built HLSL shaders" OFF)
|
||||||
|
|
||||||
option(BUILD_DXIL_SHADERS "Use DXC Shader Model 6 for shaders" ON)
|
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"))
|
if(BUILD_TESTING AND (EXISTS "${CMAKE_CURRENT_LIST_DIR}/Tests/CMakeLists.txt"))
|
||||||
enable_testing()
|
enable_testing()
|
||||||
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/Tests)
|
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"))
|
elseif(BUILD_FUZZING AND (EXISTS "${CMAKE_CURRENT_LIST_DIR}/Tests/fuzzloaders/CMakeLists.txt"))
|
||||||
message(STATUS "Building for fuzzing")
|
message(STATUS "Building for fuzzing")
|
||||||
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/Tests/fuzzloaders)
|
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/Tests/fuzzloaders)
|
||||||
|
|
|
@ -243,6 +243,23 @@
|
||||||
},
|
},
|
||||||
"hidden": true
|
"hidden": true
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "Analyze",
|
||||||
|
"cacheVariables":
|
||||||
|
{
|
||||||
|
"ENABLE_CODE_ANALYSIS": true
|
||||||
|
},
|
||||||
|
"hidden": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Coverage",
|
||||||
|
"cacheVariables":
|
||||||
|
{
|
||||||
|
"ENABLE_CODE_COVERAGE": true
|
||||||
|
},
|
||||||
|
"hidden": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "Fuzzing",
|
"name": "Fuzzing",
|
||||||
"cacheVariables": {
|
"cacheVariables": {
|
||||||
|
@ -327,8 +344,10 @@
|
||||||
{ "name": "x64-Debug-ICX" , "description": "Intel oneAPI Compiler (Debug) for Windows 10", "inherits": [ "base", "x64", "Debug", "IntelLLVM" ] },
|
{ "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-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", "Analyze" ] },
|
||||||
{ "name": "x64-Analyze" , "description": "MSVC for x64 (Debug) using /analyze", "inherits": [ "base", "x64", "Debug", "MSVC" ], "cacheVariables": { "ENABLE_CODE_ANALYSIS": true } }
|
{ "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": [
|
"testPresets": [
|
||||||
{ "name": "x64-Debug" , "configurePreset": "x64-Debug" },
|
{ "name": "x64-Debug" , "configurePreset": "x64-Debug" },
|
||||||
|
|
|
@ -49,7 +49,7 @@ if(MSVC)
|
||||||
list(APPEND COMPILER_SWITCHES "$<$<NOT:$<CONFIG:DEBUG>>:/guard:cf>")
|
list(APPEND COMPILER_SWITCHES "$<$<NOT:$<CONFIG:DEBUG>>:/guard:cf>")
|
||||||
list(APPEND LINKER_SWITCHES /DYNAMICBASE /NXCOMPAT /INCREMENTAL:NO)
|
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"))))
|
OR ((CMAKE_SIZEOF_VOID_P EQUAL 4) AND (NOT (${DIRECTX_ARCH} MATCHES "^arm"))))
|
||||||
list(APPEND LINKER_SWITCHES /SAFESEH)
|
list(APPEND LINKER_SWITCHES /SAFESEH)
|
||||||
endif()
|
endif()
|
||||||
|
@ -71,7 +71,7 @@ if(XBOX_CONSOLE_TARGET STREQUAL "scarlett")
|
||||||
elseif(XBOX_CONSOLE_TARGET MATCHES "xboxone|durango")
|
elseif(XBOX_CONSOLE_TARGET MATCHES "xboxone|durango")
|
||||||
list(APPEND COMPILER_SWITCHES $<IF:$<CXX_COMPILER_ID:MSVC>,/favor:AMD64 /arch:AVX,-march=btver2>)
|
list(APPEND COMPILER_SWITCHES $<IF:$<CXX_COMPILER_ID:MSVC>,/favor:AMD64 /arch:AVX,-march=btver2>)
|
||||||
elseif(NOT (${DIRECTX_ARCH} MATCHES "^arm"))
|
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>)
|
set(ARCH_SSE2 $<$<CXX_COMPILER_ID:MSVC,Intel>:/arch:SSE2> $<$<NOT:$<CXX_COMPILER_ID:MSVC,Intel>>:-msse2>)
|
||||||
else()
|
else()
|
||||||
set(ARCH_SSE2 $<$<NOT:$<CXX_COMPILER_ID:MSVC,Intel>>:-msse2>)
|
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_SWITCHES /fsanitize=address /fsanitize-coverage=inline-8bit-counters /fsanitize-coverage=edge /fsanitize-coverage=trace-cmp /fsanitize-coverage=trace-div)
|
||||||
set(ASAN_LIBS sancov.lib)
|
set(ASAN_LIBS sancov.lib)
|
||||||
endif()
|
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()
|
||||||
|
|
Загрузка…
Ссылка в новой задаче