Add Code Coverage support using CMake (#531)
This commit is contained in:
Родитель
8a4ff7101f
Коммит
cb1dcca12e
|
@ -39,6 +39,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(NO_WCHAR_T "Use legacy wide-character as unsigned short" OFF)
|
||||
|
@ -568,7 +570,7 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
|||
|
||||
if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.37)
|
||||
AND (NOT (${DIRECTX_ARCH} MATCHES "^arm"))
|
||||
AND ((${DIRECTX_ARCH} MATCHES "x64") OR (CMAKE_SIZEOF_VOID_P EQUAL 8)))
|
||||
AND ((${DIRECTX_ARCH} STREQUAL "x64") OR (CMAKE_SIZEOF_VOID_P EQUAL 8)))
|
||||
# Enable since DirectXTex library has a lot of large switch statements
|
||||
target_compile_options(${PROJECT_NAME} PRIVATE /jumptablerdata)
|
||||
endif()
|
||||
|
@ -659,6 +661,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)
|
||||
|
|
|
@ -231,6 +231,24 @@
|
|||
"strategy": "external"
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"name": "Analyze",
|
||||
"cacheVariables":
|
||||
{
|
||||
"ENABLE_CODE_ANALYSIS": true
|
||||
},
|
||||
"hidden": true
|
||||
},
|
||||
{
|
||||
"name": "Coverage",
|
||||
"cacheVariables":
|
||||
{
|
||||
"BUILD_TOOLS": false,
|
||||
"ENABLE_CODE_COVERAGE": true
|
||||
},
|
||||
"hidden": true
|
||||
},
|
||||
{
|
||||
"name": "Fuzzing",
|
||||
"cacheVariables": {
|
||||
|
@ -353,8 +371,10 @@
|
|||
{ "name": "x64-Debug-ICX" , "description": "Intel oneAPI Compiler (Debug) with DX12", "inherits": [ "base", "x64", "Debug", "IntelLLVM" ] },
|
||||
{ "name": "x64-Release-ICX" , "description": "Intel oneAPI Compiler (Release) with DX12", "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) with DX12 using /analyze", "inherits": [ "base", "x64", "Debug", "MSVC" ], "cacheVariables": { "ENABLE_CODE_ANALYSIS": true } }
|
||||
{ "name": "x64-Analyze" , "description": "MSVC for x64 (Debug) with DX12 using /analyze", "inherits": [ "base", "x64", "Debug", "MSVC", "Analyze" ] },
|
||||
{ "name": "x64-Coverage" , "description": "MSVC for x64 (Debug) with DX12 w/ Code Coverage", "inherits": [ "base", "x64", "Debug", "MSVC", "Coverage" ] },
|
||||
{ "name": "x64-Coverage-Clang", "description": "Clang/LLVM for x64 (Debug) with DX12 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()
|
||||
|
|
Загрузка…
Ссылка в новой задаче