diff --git a/CMLibCodeAnalysisClangAnalyze.cmake b/CMLibCodeAnalysisClangAnalyze.cmake index bf911f1..b80d2f7 100644 --- a/CMLibCodeAnalysisClangAnalyze.cmake +++ b/CMLibCodeAnalysisClangAnalyze.cmake @@ -1,16 +1,19 @@ +find_program(CLANG_CHECK_EXE + NAMES clang-check-10 + clang-check-9 + clang-check-8 + clang-check-7 + clang-check-6.0 + clang-check) +if(CLANG_CHECK_EXE) + option(CLANG_ANALYZE_FIX "Perform fixes for Clang-Check" OFF) +endif() + function(add_clang_analyze_check) list(GET ARGN 0 _target) set(_sources ${ARGN}) list(REMOVE_AT _sources 0) - option(CLANG_ANALYZE_FIX "Perform fixes for Clang-Check" OFF) - find_program(CLANG_CHECK_EXE - NAMES clang-check-10 - clang-check-9 - clang-check-8 - clang-check-7 - clang-check-6.0 - clang-check) if(CLANG_CHECK_EXE) if(CLANG_CHECK_FIX) list(APPEND _args "-fix") diff --git a/CMLibCodeAnalysisClangTidy.cmake b/CMLibCodeAnalysisClangTidy.cmake index 02ba516..ad0d30d 100644 --- a/CMLibCodeAnalysisClangTidy.cmake +++ b/CMLibCodeAnalysisClangTidy.cmake @@ -1,20 +1,23 @@ +find_program(CLANG_TIDY_EXE + NAMES clang-tidy-10 + clang-tidy-9 + clang-tidy-8 + clang-tidy-7 + clang-tidy-6.0 + clang-tidy) +if(CLANG_TIDY_EXE) + option(CLANG_TIDY_FIX "Perform fixes for Clang-Tidy" OFF) + if(CLANG_TIDY_FIX) + list(APPEND _args "-fix") + endif() +endif() + function(add_clang_tidy_check) list(GET ARGN 0 _target) set(_sources ${ARGN}) list(REMOVE_AT _sources 0) - option(CLANG_TIDY_FIX "Perform fixes for Clang-Tidy" OFF) - find_program(CLANG_TIDY_EXE - NAMES clang-tidy-10 - clang-tidy-9 - clang-tidy-8 - clang-tidy-7 - clang-tidy-6.0 - clang-tidy) if(CLANG_TIDY_EXE) - if(CLANG_TIDY_FIX) - list(APPEND _args "-fix") - endif() if(NOT TARGET clang-tidy-check) add_custom_target(clang-tidy-check) endif() diff --git a/CMLibCodeCoverage.cmake b/CMLibCodeCoverage.cmake index 528e1e9..41d621b 100644 --- a/CMLibCodeCoverage.cmake +++ b/CMLibCodeCoverage.cmake @@ -1,38 +1,42 @@ +option(ENABLE_CODE_COVERAGE "Enable code coverage support" OFF) +find_program(LCOV_EXE NAMES lcov) +find_program(GENHTML_EXE NAMES genhtml) + function(add_code_coverage) list(GET ARGN 0 _target) - if(ENABLE_CODE_COVERAGE AND CMAKE_CXX_COMPILER_IS_GCC) - find_program(LCOV_EXE NAMES lcov) - find_program(GENHTML_EXE NAMES genhtml) - target_compile_options(${_target} PUBLIC "--coverage") - get_target_property(LF ${_target} LINK_FLAGS) - string(APPEND LF " --coverage") - set_target_properties(${_target} PROPERTIES LINK_FLAGS ${LF}) + if(ENABLE_CODE_COVERAGE) + if(CMAKE_CXX_COMPILER_IS_GCC) + target_compile_options(${_target} PUBLIC "--coverage") + get_target_property(LF ${_target} LINK_FLAGS) + string(APPEND LF " --coverage") + set_target_properties(${_target} PROPERTIES LINK_FLAGS ${LF}) - if(LCOV_EXE) - add_custom_target(coverage-${_target} - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - COMMAND ${LCOV_EXE} - --test-name - ${_target} - --output - "${_target}.lcov" - --capture - --directory - ${CMAKE_BINARY_DIR}) - add_dependencies(coverage-${_target} ${_target}) - - if(GENHTML_EXE) - add_custom_target(coverage-report-${_target} + if(LCOV_EXE) + add_custom_target(coverage-${_target} WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - COMMAND ${GENHTML_EXE} - --output-directory - "report-${_target}" - "${_target}.lcov") - add_dependencies(coverage-report-${_target} coverage-${_target}) + COMMAND ${LCOV_EXE} + --test-name + ${_target} + --output + "${_target}.lcov" + --capture + --directory + ${CMAKE_BINARY_DIR}) + add_dependencies(coverage-${_target} ${_target}) + + if(GENHTML_EXE) + add_custom_target(coverage-report-${_target} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + COMMAND ${GENHTML_EXE} + --output-directory + "report-${_target}" + "${_target}.lcov") + add_dependencies(coverage-report-${_target} coverage-${_target}) + endif() endif() + else() + message("Only GCC is supported for code coverage") endif() - else() - message("Only GCC is supported for code coverage") endif() endfunction()