diff --git a/CMakeLists.txt b/CMakeLists.txt index d97ae04..8a21658 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,72 +17,6 @@ if( NOT CMAKE_BUILD_TYPE ) endif() message( STATUS "Build type: ${CMAKE_BUILD_TYPE}" ) -option( SONAR "The coverage target will produce SonarQube reports instead of console / HTML" OFF ) - -if( CMAKE_BUILD_TYPE MATCHES Coverage ) - if( CMAKE_CXX_COMPILER_ID MATCHES GNU ) - find_program( GCOV NAMES gcov ) - if( GCOV ) - message( STATUS "Found gcov: ${GCOV}" ) - else() - message( ERROR "Not found gcov: install it" ) - endif() - - if( SONAR ) - find_program( GCOVR NAMES gcovr ) - if( GCOVR ) - message( STATUS "Found gcovr: ${GCOVR}" ) - else() - message( ERROR "Not found gcovr: install it" ) - endif() - else() - find_program( LCOV NAMES lcov ) - if( LCOV ) - message( STATUS "Found lcov: ${LCOV}" ) - else() - message( ERROR "Not found lcov: install it" ) - endif() - - find_program( GENHTML NAMES genhtml ) - if( GENHTML ) - message( STATUS "Found genhtml: ${GENHTML}" ) - else() - message( ERROR "Not found genhtml: install it" ) - endif() - endif() - - elseif( CMAKE_CXX_COMPILER_ID MATCHES Clang ) - - find_program( LLVM_COV NAMES llvm-cov ) - if( LLVM_COV ) - message( STATUS "Found llvm-cov: ${LLVM_COV}" ) - else() - message( ERROR "Not found llvm-cov: install it" ) - endif() - - find_program( LLVM_PROFDATA NAMES llvm-profdata ) - if( LLVM_PROFDATA ) - message( STATUS "Found llvm-profdata: ${LLVM_PROFDATA}" ) - else() - message( ERROR "Not found llvm-profdata: install it" ) - endif() - endif() - - find_package( Catch2 3.0.0 REQUIRED ) - if( Catch2_FOUND ) - message( STATUS "Found Catch2: ${Catch2_VERSION}" ) - endif() - -else() - - find_package( Catch2 3.0.0 QUIET ) - if( Catch2_FOUND ) - message( STATUS "Found Catch2: ${Catch2_VERSION}" ) - else() - message( STATUS "Not found Catch2: unittest target disabled" ) - endif() -endif() - find_package( Clang REQUIRED ) message( STATUS "LLVM version: ${LLVM_PACKAGE_VERSION}" ) @@ -102,10 +36,15 @@ list( APPEND CMAKE_MODULE_PATH "${FETCHCONTENT_BASE_DIR}/cmake-utils-src" ) +set( COVERAGE_GLOBAL_ONLY ON ) + include( ClangBuildAnalyzer ) -include( StaticTools ) +include( Coverage ) include( Sanitizers ) +include( StaticTools ) add_subdirectory( "${CMAKE_SOURCE_DIR}/icon" ) add_subdirectory( "${CMAKE_SOURCE_DIR}/src" ) add_subdirectory( "${CMAKE_SOURCE_DIR}/test" ) + +coverage_global() diff --git a/cmake/Coverage.cmake b/cmake/Coverage.cmake deleted file mode 100644 index bdcea4b..0000000 --- a/cmake/Coverage.cmake +++ /dev/null @@ -1,81 +0,0 @@ -set(${PROJECT_NAME}_coverage "" CACHE STRING "Coverage report type.") -set_property(CACHE ${PROJECT_NAME}_coverage PROPERTY STRINGS html xml lcov-html) - -if(${PROJECT_NAME}_coverage) - if(MSVC) - message(FATAL_ERROR "${PROJECT_NAME}_coverage not supported yet for MSVC") - else() - add_compile_options(--coverage) - add_link_options(--coverage) - endif() -endif() - -set(gcovr_coverage_types html xml) -set(lcov_coverage_types lcov-html) -set(coverage_targets ExperimentalCoverage ContinuousCoverage NightlyCoverage) -set(COVERAGE_EXTRA_FLAGS "${COVERAGE_EXTRA_FLAGS} -b" - CACHE STRING "Extra command line flags to pass to the coverage tool" FORCE) - -if(${PROJECT_NAME}_coverage IN_LIST gcovr_coverage_types) - find_program(gcovr_command gcovr) - mark_as_advanced(gcovr_command) - foreach(coverage_target IN LISTS coverage_targets) - set(gcovr_options - --root="${PROJECT_SOURCE_DIR}" - --exclude-directories="external" - --exclude-directories="tests" - --exclude=".*_test\.cpp" - --exclude=".*_benchmark\.cpp" - --object-directory="${PROJECT_BINARY_DIR}" - ) - add_custom_command(TARGET ${coverage_target} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E make_directory coverage - COMMAND ${gcovr_command} ${gcovr_options} - COMMAND ${gcovr_command} ${gcovr_options} - --branches - COMMAND ${gcovr_command} ${gcovr_options} - $<$:--xml> - $<$:--html-details> - $<$:--html-title=${PROJECT_NAME}> - --output=coverage/index.${${PROJECT_NAME}_coverage} - --print-summary - COMMENT "Generating gcovr-${${PROJECT_NAME}_coverage} report") - endforeach() -elseif(${PROJECT_NAME}_coverage IN_LIST lcov_coverage_types) - find_program(lcov_command lcov) - find_program(genhtml_command genhtml) - mark_as_advanced(lcov_command genhtml_command) - foreach(coverage_target IN LISTS coverage_targets) - set(lcov_options - --output-file=coverage.info - --rc=lcov_branch_coverage=1 - ) - add_custom_command(TARGET ${coverage_target} POST_BUILD - COMMAND ${lcov_command} ${lcov_options} - --quiet - --capture - --directory="${PROJECT_BINARY_DIR}" - --base-directory="${PROJECT_SOURCE_DIR}" - --no-external - COMMAND ${lcov_command} ${lcov_options} - --quiet - --remove=coverage.info - "*/external/*" - "*/tests/*" - "*_test.cpp" - "*_benchmark.cpp" - COMMAND ${lcov_command} ${lcov_options} - --list=coverage.info - COMMAND ${lcov_command} ${lcov_options} - --summary=coverage.info - COMMAND ${genhtml_command} coverage.info - --quiet - --output-directory=coverage - --title=${PROJECT_NAME} - --branch-coverage - --demangle-cpp - COMMENT "Generating ${${PROJECT_NAME}_coverage} report") - endforeach() -elseif(NOT ${PROJECT_NAME}_coverage STREQUAL "") - message(FATAL_ERROR "${PROJECT_NAME}_coverage=${${PROJECT_NAME}_coverage} not supported yet") -endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8c95e89..002595d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,89 +1,116 @@ -add_library(${PROJECT_NAME} STATIC) - -target_sources( - ${PROJECT_NAME} - PRIVATE "${CMAKE_SOURCE_DIR}/src/domain/core/types.cpp" - "${CMAKE_SOURCE_DIR}/src/domain/core/guard.cpp" - "${CMAKE_SOURCE_DIR}/src/domain/cfg/element/element.cpp" - "${CMAKE_SOURCE_DIR}/src/domain/cfg/block/block.cpp" - "${CMAKE_SOURCE_DIR}/src/domain/cfg/block/builder.cpp" - "${CMAKE_SOURCE_DIR}/src/domain/cfg/scope/scope.cpp" - "${CMAKE_SOURCE_DIR}/src/domain/cfg/scope/builder.cpp" - "${CMAKE_SOURCE_DIR}/src/domain/cfg/cfg.cpp" - "${CMAKE_SOURCE_DIR}/src/domain/cfg/cfg.cpp" - "${CMAKE_SOURCE_DIR}/src/domain/cfg/builder.cpp") - -target_compile_definitions( - ${PROJECT_NAME} PRIVATE # $<$:DEBUG> ${LLVM_DEFINITIONS} - # ${CLANG_DEFINITIONS} -) - -target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) - -target_compile_options( - ${PROJECT_NAME} - PRIVATE - $<$:-O0> - $<$,$>:-Wall> - $<$,$>:-Wextra> - # $<$,$>:-Weffc++> - $<$,$>:-fexceptions> - $<$,$>:--coverage> - $<$,$>:-fprofile-instr-generate> - $<$,$>:-fcoverage-mapping>) - -target_include_directories( - ${PROJECT_NAME} - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} - # ${LLVM_INCLUDE_DIRS} - ${CLANG_INCLUDE_DIRS}) - -target_link_libraries( - ${PROJECT_NAME} - $<$,$>:-lgcov> - # -ldl -ltinfo -lpthread clang clangAST clangAnalysis clangBasic clangDriver - # clangEdit clangIndex clangFrontend clangFrontendTool clangLex clangParse - # clangSema clangEdit clangASTMatchers clangRewrite clangRewriteFrontend - # clangStaticAnalyzerFrontend clangStaticAnalyzerCheckers - # clangStaticAnalyzerCore clangSerialization clangToolingCore clangTooling -) - -target_link_options( - ${PROJECT_NAME} PRIVATE - $<$,$>:-fprofile-instr-generate> -) - -set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "raisin") - -file(GLOB_RECURSE ${PROJECT_NAME}_HEADERS "*.hpp") +add_library( raisin SHARED ) + +target_sources( raisin + PRIVATE + "${CMAKE_SOURCE_DIR}/src/domain/core/types.cpp" + "${CMAKE_SOURCE_DIR}/src/domain/core/guard.cpp" + "${CMAKE_SOURCE_DIR}/src/domain/cfg/element/element.cpp" + "${CMAKE_SOURCE_DIR}/src/domain/cfg/block/block.cpp" + "${CMAKE_SOURCE_DIR}/src/domain/cfg/block/builder.cpp" + "${CMAKE_SOURCE_DIR}/src/domain/cfg/scope/scope.cpp" + "${CMAKE_SOURCE_DIR}/src/domain/cfg/scope/builder.cpp" + "${CMAKE_SOURCE_DIR}/src/domain/cfg/cfg.cpp" + "${CMAKE_SOURCE_DIR}/src/domain/cfg/cfg.cpp" + "${CMAKE_SOURCE_DIR}/src/domain/cfg/builder.cpp" + ) + +target_compile_definitions( raisin + PRIVATE +# $<$:DEBUG> ${LLVM_DEFINITIONS} +# ${CLANG_DEFINITIONS} + ) + +target_compile_features( raisin + PRIVATE + cxx_std_17 + ) + +target_compile_options( raisin + PRIVATE + $<$,$>:-Wall> + $<$,$>:-Wextra> +# $<$,$>:-Weffc++> + $<$,$>:-fexceptions> + ) + +target_include_directories( raisin + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} +# ${LLVM_INCLUDE_DIRS} + ${CLANG_INCLUDE_DIRS} + ) + +#target_link_libraries( raisin +# -ldl +# -ltinfo +# -lpthread +# clang +# clangAST +# clangAnalysis +# clangBasic +# clangDriver +# clangEdit +# clangIndex +# clangFrontend +# clangFrontendTool +# clangLex +# clangParse +# clangSema +# clangEdit +# clangASTMatchers +# clangRewrite +# clangRewriteFrontend +# clangStaticAnalyzerFrontend +# clangStaticAnalyzerCheckers +# clangStaticAnalyzerCore +# clangSerialization +# clangToolingCore +# clangTooling +# ) + +file( GLOB_RECURSE RAISIN_HEADERS "*.hpp" ) static_analysis_lizard( - TARGET - ${PROJECT_NAME} - ADDITIONAL_FILES - ${${PROJECT_NAME}_HEADERS} - ARGS - --languages - cpp - --sort - cyclomatic_complexity) + TARGET raisin + ADDITIONAL_FILES + ${RAISIN_HEADERS} + ARGS + --languages cpp + --sort cyclomatic_complexity + ) static_analysis_iwyu( - TARGET ${PROJECT_NAME} ARGS --std=c++17 # Useless with -p ? - # -p="${CMAKE_BINARY_DIR}" # Outdated iwyu version. - -Xiwyu --no_comments) - -static_analysis_tidy(TARGET ${PROJECT_NAME} ARGS -p="${CMAKE_BINARY_DIR}" - -checks=*) - -static_analysis_format(TARGET ${PROJECT_NAME} ADDITIONAL_FILES - ${${PROJECT_NAME}_HEADERS} ARGS) + TARGET raisin + ARGS + --std=c++17 # Useless with -p ? +# -p="${CMAKE_BINARY_DIR}" # Outdated iwyu version. + -Xiwyu + --no_comments + ) + +static_analysis_tidy( + TARGET raisin + ARGS + -p="${CMAKE_BINARY_DIR}" + -checks=* + ) + +static_analysis_format( + TARGET raisin + ADDITIONAL_FILES + ${RAISIN_HEADERS} + ARGS + ) static_analysis_cppcheck( - TARGET ${PROJECT_NAME} ADDITIONAL_FILES ${${PROJECT_NAME}_HEADERS} ARGS - # --enable=all - -v) + TARGET raisin + ADDITIONAL_FILES + ${RAISIN_HEADERS} + ARGS +# --enable=all + -v + ) -enable_clang_build_analyzer(TARGET ${PROJECT_NAME}) +enable_clang_build_analyzer( TARGET raisin ) -enable_sanitizers(TARGET ${PROJECT_NAME}) +enable_sanitizers( TARGET raisin ) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index aba45b2..634796e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -8,109 +8,9 @@ add_custom_target( check USES_TERMINAL COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure COMMENT "Running tests" - DEPENDS unittest + DEPENDS raisin_unittest ) -add_test( NAME Unittest - COMMAND $ --use-colour=yes +add_test( NAME RaisinUnittest + COMMAND $ --use-colour=yes ) - -if( CMAKE_BUILD_TYPE MATCHES Coverage ) - if( CMAKE_CXX_COMPILER_ID MATCHES GNU ) - if( SONAR ) - - add_custom_target( coverage - COMMAND $ - -r sonarqube - -o "${CMAKE_CURRENT_BINARY_DIR}/unit/sonarqube_report.xml" - COMMAND ${GCOVR} - --sonarqube "${CMAKE_CURRENT_BINARY_DIR}/coverage.xml" - -r "${CMAKE_SOURCE_DIR}" - -e "${CMAKE_SOURCE_DIR}/test" - -f "${CMAKE_SOURCE_DIR}/src" - --exclude-unreachable-branches - --exclude-throw-branches - -s - COMMENT "Run unit tests, perform code coverage, generate sonarqube report" - ) - - else() - - add_custom_target( coverage -# COMMAND ${CMAKE_COMMAND} -E env bash -c -# "${CMAKE_CTEST_COMMAND} --output-on-failure Unittest ;:;" - COMMAND $ - COMMAND ${LCOV} -c - -d "${CMAKE_BINARY_DIR}/src/CMakeFiles/${PROJECT_NAME}.dir" - -o "${CMAKE_CURRENT_BINARY_DIR}/coverage.tmp.info" - --rc lcov_branch_coverage=1 - COMMAND ${LCOV} -r - "${CMAKE_CURRENT_BINARY_DIR}/coverage.tmp.info" -# '${CMAKE_CURRENT_BINARY_DIR}/unittest_autogen/*' - '/usr/*' - -o "${CMAKE_CURRENT_BINARY_DIR}/coverage.info" - --rc lcov_branch_coverage=1 - -q - COMMAND ${GENHTML} - "${CMAKE_CURRENT_BINARY_DIR}/coverage.info" - -o "${CMAKE_CURRENT_BINARY_DIR}/coverage" - --branch-coverage - --function-coverage - COMMAND ${LCOV} - -l "${CMAKE_CURRENT_BINARY_DIR}/coverage.info" - --rc lcov_branch_coverage=1 - COMMENT "Run unit tests, perform code coverage, generate lcov report" - ) - - endif() - elseif( CMAKE_CXX_COMPILER_ID MATCHES Clang ) - if( SONAR ) - -#[[ - # llvm-cov reports seems to be false and incomplete on sonarcloud. - # Prefer the GCC version. - add_custom_target( coverage_sonar - COMMAND LLVM_PROFILE_FILE=${CMAKE_CURRENT_BINARY_DIR}/coverage.profraw - $ - -r sonarqube - -o "${CMAKE_CURRENT_BINARY_DIR}/unit/sonarqube_report.xml" - COMMAND ${LLVM_PROFDATA} merge - -sparse "${CMAKE_CURRENT_BINARY_DIR}/coverage.profraw" - -o "${CMAKE_CURRENT_BINARY_DIR}/coverage.profdata" - COMMAND ${LLVM_COV} show $ - -instr-profile="${CMAKE_CURRENT_BINARY_DIR}/coverage.profdata" - -show-line-counts - -show-expansions - -show-regions - -format="text" -# -ignore-filename-regex='${CMAKE_SOURCE_DIR}/test/*' - > ${CMAKE_CURRENT_BINARY_DIR}/coverage.txt - COMMENT "Run unit tests, perform code coverage, generate sonarqube report" - ) -#]] - - else() - - add_custom_target( coverage - COMMAND LLVM_PROFILE_FILE=${CMAKE_CURRENT_BINARY_DIR}/coverage.profraw - $ - COMMAND ${LLVM_PROFDATA} merge - -sparse "${CMAKE_CURRENT_BINARY_DIR}/coverage.profraw" - -o "${CMAKE_CURRENT_BINARY_DIR}/coverage.profdata" - COMMAND ${LLVM_COV} report $ - -instr-profile="${CMAKE_CURRENT_BINARY_DIR}/coverage.profdata" -# -ignore-filename-regex='${CMAKE_SOURCE_DIR}/test/*' - COMMAND ${LLVM_COV} show $ - -instr-profile="${CMAKE_CURRENT_BINARY_DIR}/coverage.profdata" - -output-dir="${CMAKE_CURRENT_BINARY_DIR}/coverage" - -show-line-counts - -show-expansions - -show-regions - -format="html" -# -ignore-filename-regex='${CMAKE_SOURCE_DIR}/test/*' - COMMENT "Run unit tests, perform code coverage, generate llvm-cov report" - ) - - endif() - endif() -endif() diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index 8eaf7aa..55c8afe 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -1,45 +1,71 @@ -if(Catch2_FOUND) - add_executable(unittest EXCLUDE_FROM_ALL) +if( Catch2_FOUND ) + add_executable( raisin_unittest EXCLUDE_FROM_ALL ) - target_sources( - unittest - PRIVATE # "${CMAKE_CURRENT_SOURCE_DIR}/domain/cfg/test_cfg_builder.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/domain/core/result.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/domain/core/guard.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/domain/core/aggregator.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/domain/cfg/block/builder.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/domain/cfg/scope/builder.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/domain/cfg/builder.cpp") + target_sources( + raisin_unittest + PRIVATE +# "${CMAKE_CURRENT_SOURCE_DIR}/domain/cfg/test_cfg_builder.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/domain/core/result.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/domain/core/guard.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/domain/core/aggregator.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/domain/cfg/block/builder.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/domain/cfg/scope/builder.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/domain/cfg/builder.cpp" + ) - target_compile_definitions(unittest PRIVATE UNITTEST $<$:DEBUG>) + target_compile_definitions( raisin_unittest + PRIVATE UNITTEST + $<$:DEBUG> + ) - target_compile_features(unittest PRIVATE cxx_std_17) + target_compile_features( raisin_unittest + PRIVATE + cxx_std_17 + ) - target_compile_options( - unittest - PRIVATE $<$:-O0> - $<$,$>:-Wall> - $<$,$>:-Wextra> - # $<$,$>:-Weffc++> - $<$,$>:-fexceptions>) + target_compile_options( raisin_unittest + PRIVATE + $<$:-O0> + $<$,$>:-Wall> + $<$,$>:-Wextra> +# $<$,$>:-Weffc++> + $<$,$>:-fexceptions> + ) - target_include_directories(unittest PRIVATE "${CMAKE_SOURCE_DIR}/src") + target_include_directories( raisin_unittest + PRIVATE + "${CMAKE_SOURCE_DIR}/src" + ) - target_link_libraries(unittest Catch2::Catch2WithMain ${PROJECT_NAME}) + target_link_libraries( raisin_unittest + Catch2::Catch2WithMain + raisin + ) - set_target_properties(unittest PROPERTIES OUTPUT_NAME "unittest") + file(GLOB_RECURSE RAISIN_UNITTEST_HEADERS "*.hpp") - file(GLOB_RECURSE UNITTEST_HEADERS "*.hpp") + coverage( + TARGET_TO_RUN raisin_unittest + TARGETS_TO_COVER raisin + ) - static_analysis_iwyu( - TARGET unittest ARGS --std=c++17 # Useless with -p ? - # -p="${CMAKE_BINARY_DIR}" # Outdated iwyu version. - -Xiwyu --no_comments) + static_analysis_iwyu( + TARGET raisin_unittest + ARGS + --std=c++17 # Useless with -p ? +# -p="${CMAKE_BINARY_DIR}" # Outdated iwyu version. + -Xiwyu + --no_comments + ) - static_analysis_format(TARGET unittest ADDITIONAL_FILES ${UNITTEST_HEADERS} - ARGS) + static_analysis_format( + TARGET raisin_unittest + ADDITIONAL_FILES + ${RAISIN_UNITTEST_HEADERS} + ARGS + ) - enable_clang_build_analyzer(TARGET unittest) + enable_clang_build_analyzer( TARGET raisin_unittest ) - enable_sanitizers(TARGET unittest) + enable_sanitizers( TARGET raisin_unittest ) endif()