Prevent error in coverage target when building only static libs

This commit is contained in:
Martchus 2017-07-28 17:34:28 +02:00
parent 1af88c964e
commit e4709099d2
2 changed files with 16 additions and 10 deletions

View File

@ -240,16 +240,18 @@ endif()
# enable source code based coverage analysis using clang
option(CLANG_SOURCE_BASED_COVERAGE_ENABLED "enables creation of coverage targets for source-based coverage with clang" OFF)
if(CLANG_SOURCE_BASED_COVERAGE_ENABLED)
if(CMAKE_HOST_UNIX AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
if(NOT CMAKE_HOST_UNIX OR NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
message(FATAL_ERROR "Source-based coverage only available under UNIX with Clang")
endif()
if(NOT META_PROJECT_TYPE STREQUAL "application" AND DISABLE_SHARED_LIBS)
message(FATAL_ERROR "Source-based coverage not available when only building static libs")
endif()
set(CLANG_SOURCE_BASED_COVERAGE_AVAILABLE YES)
set(CLANG_SOURCE_BASED_COVERAGE_FLAGS -fprofile-instr-generate -fcoverage-mapping)
list(APPEND META_PRIVATE_SHARED_LIB_COMPILE_OPTIONS ${CLANG_SOURCE_BASED_COVERAGE_FLAGS})
list(APPEND META_PRIVATE_STATIC_LIB_COMPILE_OPTIONS ${CLANG_SOURCE_BASED_COVERAGE_FLAGS})
list(APPEND META_ADDITIONAL_SHARED_LINK_FLAGS ${CLANG_SOURCE_BASED_COVERAGE_FLAGS})
list(APPEND META_ADDITIONAL_STATIC_LINK_FLAGS ${CLANG_SOURCE_BASED_COVERAGE_FLAGS})
else()
message(FATAL_ERROR "Source-based coverage only available under UNIX with Clang")
endif()
endif()
# configure creation of install targets

View File

@ -154,11 +154,15 @@ if(CPP_UNIT_LIB OR META_NO_CPP_UNIT)
)
# make a test recognized by ctest
unset(RUN_TESTS_APPLICATION_ARG)
if(META_PROJECT_TYPE STREQUAL "application")
set(RUN_TESTS_APPLICATION_ARGS -a "$<TARGET_FILE:${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}>")
endif()
add_test(NAME ${META_PROJECT_NAME}_run_tests COMMAND
${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_tests
-p "${CMAKE_CURRENT_SOURCE_DIR}/testfiles"
-w "${CMAKE_CURRENT_BINARY_DIR}/testworkingdir"
-a "$<TARGET_FILE:${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}>"
${RUN_TESTS_APPLICATION_ARGS}
)
# enable source code based coverage analysis using clang
@ -188,7 +192,7 @@ if(CPP_UNIT_LIB OR META_NO_CPP_UNIT)
$<TARGET_FILE:${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_tests>
-p "${CMAKE_CURRENT_SOURCE_DIR}/testfiles"
-w "${CMAKE_CURRENT_BINARY_DIR}/testworkingdir"
-a "$<TARGET_FILE:${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}>"
${RUN_TESTS_APPLICATION_ARGS}
COMMENT "Executing ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_tests to generate raw profiling data for source-based coverage report"
DEPENDS "${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_tests"
)