CMake: Add a "Coverage" configuration, when using GCC/Clang

This commit is contained in:
Sam Edwards 2019-12-05 10:35:25 -07:00
parent 4000199acb
commit e474350a48
3 changed files with 38 additions and 3 deletions

View File

@ -117,8 +117,11 @@ if(INTERROGATE_PYTHON_INTERFACE)
# for pytest before adding this test. If the user doesn't have pytest, we'd
# like for the tests to fail.
# In the Coverage configuration, we also require pytest-cov
add_test(NAME pytest
COMMAND "${PYTHON_EXECUTABLE}" -m pytest "${PROJECT_SOURCE_DIR}/tests"
$<$<CONFIG:Coverage>:--cov=.>
WORKING_DIRECTORY "${PANDA_OUTPUT_DIR}")
endif()

View File

@ -21,6 +21,33 @@ set(CMAKE_SHARED_LINKER_FLAGS_STANDARD "")
set(CMAKE_MODULE_LINKER_FLAGS_STANDARD "")
set(CMAKE_EXE_LINKER_FLAGS_STANDARD "")
# Coverage (when we know how to support it)
if(CMAKE_CXX_COMPILER_ID MATCHES "(AppleClang|Clang)")
set(CMAKE_C_FLAGS_COVERAGE
"${CMAKE_C_FLAGS_DEBUG} -fprofile-instr-generate -fcoverage-mapping")
set(CMAKE_CXX_FLAGS_COVERAGE
"${CMAKE_CXX_FLAGS_DEBUG} -fprofile-instr-generate -fcoverage-mapping")
set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE
"${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fprofile-instr-generate")
set(CMAKE_MODULE_LINKER_FLAGS_COVERAGE
"${CMAKE_MODULE_LINKER_FLAGS_DEBUG} -fprofile-instr-generate")
set(CMAKE_EXE_LINKER_FLAGS_COVERAGE
"${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fprofile-instr-generate")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GCC")
set(CMAKE_C_FLAGS_COVERAGE "${CMAKE_C_FLAGS_DEBUG} --coverage")
set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_DEBUG} --coverage")
set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE
"${CMAKE_SHARED_LINKER_FLAGS_DEBUG} --coverage")
set(CMAKE_MODULE_LINKER_FLAGS_COVERAGE
"${CMAKE_MODULE_LINKER_FLAGS_DEBUG} --coverage")
set(CMAKE_EXE_LINKER_FLAGS_COVERAGE
"${CMAKE_EXE_LINKER_FLAGS_DEBUG} --coverage")
endif()
# Panda3D is now a C++11 project. Newer versions of CMake support this out of
# the box; for older versions we take a shot in the dark:
if(CMAKE_VERSION VERSION_LESS "3.1")

View File

@ -35,16 +35,21 @@ a CMake < 3.9. Making a guess if this is a multi-config generator.")
endif()
# Define the type of build we are setting up.
set(_configs Standard Release RelWithDebInfo Debug MinSizeRel)
if(DEFINED CMAKE_CXX_FLAGS_COVERAGE)
list(APPEND _configs Coverage)
endif()
if(IS_MULTICONFIG)
set(CMAKE_CONFIGURATION_TYPES Standard Release RelWithDebInfo Debug MinSizeRel)
set(CMAKE_CONFIGURATION_TYPES ${_configs})
else()
# CMAKE_BUILD_TYPE can't just be set using the usual set(CACHE) method since
# it's an empty string by default.
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Standard)
endif()
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
Standard Release RelWithDebInfo Debug MinSizeRel)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${_configs})
endif()
# Provide convenient boolean expression based on build type