Skip to content

Commit

Permalink
[👷][#15] CMake : some refacto & use Coverage from cmake-utils
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaslepoix committed Oct 5, 2021
1 parent f19d2eb commit 9af5b07
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 364 deletions.
73 changes: 6 additions & 67 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}" )
Expand All @@ -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()
81 changes: 0 additions & 81 deletions cmake/Coverage.cmake

This file was deleted.

189 changes: 108 additions & 81 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 # $<$<CONFIG:Debug>:DEBUG> ${LLVM_DEFINITIONS}
# ${CLANG_DEFINITIONS}
)

target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)

target_compile_options(
${PROJECT_NAME}
PRIVATE
$<$<CONFIG:Coverage>:-O0>
$<$<OR:$<CONFIG:Coverage>,$<CONFIG:Debug>>:-Wall>
$<$<OR:$<CONFIG:Coverage>,$<CONFIG:Debug>>:-Wextra>
# $<$<OR:$<CONFIG:Coverage>,$<CONFIG:Debug>>:-Weffc++>
$<$<OR:$<CONFIG:Coverage>,$<CONFIG:Debug>>:-fexceptions>
$<$<AND:$<CONFIG:Coverage>,$<CXX_COMPILER_ID:GNU>>:--coverage>
$<$<AND:$<CONFIG:Coverage>,$<CXX_COMPILER_ID:Clang>>:-fprofile-instr-generate>
$<$<AND:$<CONFIG:Coverage>,$<CXX_COMPILER_ID:Clang>>:-fcoverage-mapping>)

target_include_directories(
${PROJECT_NAME}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
# ${LLVM_INCLUDE_DIRS}
${CLANG_INCLUDE_DIRS})

target_link_libraries(
${PROJECT_NAME}
$<$<AND:$<CONFIG:Coverage>,$<CXX_COMPILER_ID:GNU>>:-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
$<$<AND:$<CONFIG:Coverage>,$<CXX_COMPILER_ID:Clang>>:-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
# $<$<CONFIG:Debug>:DEBUG> ${LLVM_DEFINITIONS}
# ${CLANG_DEFINITIONS}
)

target_compile_features( raisin
PRIVATE
cxx_std_17
)

target_compile_options( raisin
PRIVATE
$<$<OR:$<CONFIG:Coverage>,$<CONFIG:Debug>>:-Wall>
$<$<OR:$<CONFIG:Coverage>,$<CONFIG:Debug>>:-Wextra>
# $<$<OR:$<CONFIG:Coverage>,$<CONFIG:Debug>>:-Weffc++>
$<$<OR:$<CONFIG:Coverage>,$<CONFIG:Debug>>:-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 )
Loading

0 comments on commit 9af5b07

Please sign in to comment.