Commit 305e61a12522446b5d28d3d817433e00f67a1bd8
Committed by
Moritz Wirger
1 parent
1e3b07c5
Fix problem that unittests can be executed when gcov or lcov are not installed
Showing
1 changed file
with
39 additions
and
33 deletions
hueplusplus/test/CMakeLists.txt
| ... | ... | @@ -49,36 +49,42 @@ add_custom_target("unittest" |
| 49 | 49 | COMMAND "${CMAKE_BINARY_DIR}/hueplusplus/test/test_HuePlusPlus" |
| 50 | 50 | ) |
| 51 | 51 | |
| 52 | -# GCov | |
| 53 | -include(CodeCoverage.cmake) | |
| 54 | -add_executable(testcov_HuePlusPlus ${TEST_SOURCES} ${hueplusplus_SOURCES}) | |
| 55 | -target_link_libraries(testcov_HuePlusPlus gtest gmock) | |
| 56 | -# prevent Main.cpp from defining main() | |
| 57 | -target_compile_definitions(testcov_HuePlusPlus PUBLIC MAIN_CPP_NO_MAIN_FUNCTION) | |
| 58 | -target_include_directories(testcov_HuePlusPlus PUBLIC ${GTest_INCLUDE_DIRS}) | |
| 59 | -target_include_directories(testcov_HuePlusPlus PUBLIC ${HuePlusPlus_INCLUDE_DIR}) | |
| 60 | -set_property(TARGET testcov_HuePlusPlus PROPERTY CXX_STANDARD 14) | |
| 61 | -set_property(TARGET testcov_HuePlusPlus PROPERTY CXX_EXTENSIONS OFF) | |
| 62 | -# this will be already done by APPEND_COVERAGE_COMPILER_FLAGS() | |
| 63 | -#set_target_properties( | |
| 64 | -# testcov_HuePlusPlus PROPERTIES | |
| 65 | -# COMPILE_FLAGS "-O0 -g -fprofile-arcs -ftest-coverage" | |
| 66 | -#) | |
| 67 | -# Normally this would be -lgcov, but on mac only -Lgcov works | |
| 68 | -#set_target_properties( | |
| 69 | -# testcov_HuePlusPlus PROPERTIES | |
| 70 | -# LINK_FLAGS "-O0 -g -Lgcov -fprofile-arcs -ftest-coverage" | |
| 71 | -#) | |
| 72 | -set(COVERAGE_EXCLUDES | |
| 73 | - '/usr/*' # unix | |
| 74 | - '*/build/*' | |
| 75 | - '*/json*' | |
| 76 | - '*/test/*' | |
| 77 | - '*/v1/*' # iOS | |
| 78 | -) | |
| 79 | -APPEND_COVERAGE_COMPILER_FLAGS() | |
| 80 | -SETUP_TARGET_FOR_COVERAGE( | |
| 81 | - NAME "coveragetest" | |
| 82 | - EXECUTABLE testcov_HuePlusPlus | |
| 83 | - DEPENDENCIES testcov_HuePlusPlus | |
| 84 | -) | |
| 52 | +# Check for prerequisites | |
| 53 | +find_program( GCOV_PATH gcov ) | |
| 54 | +find_program( LCOV_PATH lcov ) | |
| 55 | + | |
| 56 | +if(LCOV_PATH AND GCOV_PATH) | |
| 57 | + # GCov | |
| 58 | + include(CodeCoverage.cmake) | |
| 59 | + add_executable(testcov_HuePlusPlus ${TEST_SOURCES} ${hueplusplus_SOURCES}) | |
| 60 | + target_link_libraries(testcov_HuePlusPlus gtest gmock) | |
| 61 | + # prevent Main.cpp from defining main() | |
| 62 | + target_compile_definitions(testcov_HuePlusPlus PUBLIC MAIN_CPP_NO_MAIN_FUNCTION) | |
| 63 | + target_include_directories(testcov_HuePlusPlus PUBLIC ${GTest_INCLUDE_DIRS}) | |
| 64 | + target_include_directories(testcov_HuePlusPlus PUBLIC ${HuePlusPlus_INCLUDE_DIR}) | |
| 65 | + set_property(TARGET testcov_HuePlusPlus PROPERTY CXX_STANDARD 14) | |
| 66 | + set_property(TARGET testcov_HuePlusPlus PROPERTY CXX_EXTENSIONS OFF) | |
| 67 | + # this will be already done by APPEND_COVERAGE_COMPILER_FLAGS() | |
| 68 | + #set_target_properties( | |
| 69 | + # testcov_HuePlusPlus PROPERTIES | |
| 70 | + # COMPILE_FLAGS "-O0 -g -fprofile-arcs -ftest-coverage" | |
| 71 | + #) | |
| 72 | + # Normally this would be -lgcov, but on mac only -Lgcov works | |
| 73 | + #set_target_properties( | |
| 74 | + # testcov_HuePlusPlus PROPERTIES | |
| 75 | + # LINK_FLAGS "-O0 -g -Lgcov -fprofile-arcs -ftest-coverage" | |
| 76 | + #) | |
| 77 | + set(COVERAGE_EXCLUDES | |
| 78 | + '/usr/*' # unix | |
| 79 | + '*/build/*' | |
| 80 | + '*/json*' | |
| 81 | + '*/test/*' | |
| 82 | + '*/v1/*' # iOS | |
| 83 | + ) | |
| 84 | + APPEND_COVERAGE_COMPILER_FLAGS() | |
| 85 | + SETUP_TARGET_FOR_COVERAGE( | |
| 86 | + NAME "coveragetest" | |
| 87 | + EXECUTABLE testcov_HuePlusPlus | |
| 88 | + DEPENDENCIES testcov_HuePlusPlus | |
| 89 | + ) | |
| 90 | +endif() | ... | ... |