-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from cginternals/cppcheck_scripts
Add source check targets
- Loading branch information
Showing
11 changed files
with
218 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
# Function to register a target for clang-tidy | ||
function(perform_clang_tidy check_target target) | ||
set(includes "$<TARGET_PROPERTY:${target},INCLUDE_DIRECTORIES>") | ||
|
||
add_custom_target( | ||
${check_target} | ||
COMMAND | ||
${clang_tidy_EXECUTABLE} | ||
"$<$<BOOL:${CMAKE_EXPORT_COMPILE_COMMANDS}>:-p\t${PROJECT_BINARY_DIR}>" | ||
${ARGN} | ||
-checks=* | ||
"$<$<NOT:$<BOOL:${CMAKE_EXPORT_COMPILE_COMMANDS}>>:--\t$<$<BOOL:${includes}>:-I$<JOIN:${includes},\t-I>>>" | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||
) | ||
|
||
add_dependencies(${check_target} ${target}) | ||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
# Function to register a target for cppcheck | ||
function(perform_cppcheck check_target target) | ||
set(includes "$<TARGET_PROPERTY:${target},INCLUDE_DIRECTORIES>") | ||
|
||
add_custom_target( | ||
${check_target} | ||
COMMAND | ||
${cppcheck_EXECUTABLE} | ||
"$<$<BOOL:${includes}>:-I$<JOIN:${includes},\t-I>>" | ||
--check-config | ||
--enable=warning,performance,portability,information,missingInclude | ||
--quiet | ||
--std=c++11 | ||
--verbose | ||
--suppress=missingIncludeSystem | ||
${ARGN} | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||
) | ||
|
||
add_dependencies(${check_target} ${target}) | ||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
# Findclang_tidy results: | ||
# clang_tidy_FOUND | ||
# clang_tidy_EXECUTABLE | ||
|
||
include(FindPackageHandleStandardArgs) | ||
|
||
find_program(clang_tidy_EXECUTABLE | ||
NAMES | ||
clang-tidy-3.5 | ||
clang-tidy-3.6 | ||
clang-tidy-3.7 | ||
clang-tidy-3.8 | ||
clang-tidy-3.9 | ||
clang-tidy-4.0 | ||
PATHS | ||
"${CLANG_TIDY_DIR}" | ||
) | ||
|
||
find_package_handle_standard_args(clang_tidy | ||
FOUND_VAR | ||
clang_tidy_FOUND | ||
REQUIRED_VARS | ||
clang_tidy_EXECUTABLE | ||
) | ||
|
||
mark_as_advanced(clang_tidy_EXECUTABLE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
# Findcppcheck results: | ||
# cppcheck_FOUND | ||
# cppcheck_EXECUTABLE | ||
|
||
include(FindPackageHandleStandardArgs) | ||
|
||
find_program(cppcheck_EXECUTABLE | ||
NAMES | ||
cppcheck | ||
PATHS | ||
"${CPPCHECK_DIR}" | ||
) | ||
|
||
find_package_handle_standard_args(cppcheck | ||
FOUND_VAR | ||
cppcheck_FOUND | ||
REQUIRED_VARS | ||
cppcheck_EXECUTABLE | ||
) | ||
|
||
mark_as_advanced(cppcheck_EXECUTABLE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
|
||
include(${CMAKE_CURRENT_LIST_DIR}/Cppcheck.cmake) | ||
include(${CMAKE_CURRENT_LIST_DIR}/ClangTidy.cmake) | ||
|
||
set(OPTION_CPPCHECK_ENABLED Off) | ||
set(OPTION_CLANG_TIDY_ENABLED Off) | ||
|
||
# Function to register a target for enabled health checks | ||
function(perform_health_checks target) | ||
if(NOT TARGET check-all) | ||
add_custom_target(check-all) | ||
endif() | ||
|
||
add_custom_target(check-${target}) | ||
|
||
if (OPTION_CPPCHECK_ENABLED) | ||
perform_cppcheck(cppcheck-${target} ${target} ${ARGN}) | ||
add_dependencies(check-${target} cppcheck-${target}) | ||
endif() | ||
|
||
if (OPTION_CLANG_TIDY_ENABLED) | ||
perform_clang_tidy(clang-tidy-${target} ${target} ${ARGN}) | ||
add_dependencies(check-${target} clang-tidy-${target}) | ||
endif() | ||
|
||
add_dependencies(check-all check-${target}) | ||
endfunction() | ||
|
||
# Enable or disable cppcheck for health checks | ||
function(enable_cppcheck status) | ||
if(NOT ${status}) | ||
set(OPTION_CPPCHECK_ENABLED ${status} PARENT_SCOPE) | ||
message(STATUS "Check cppcheck skipped: Manually disabled") | ||
|
||
return() | ||
endif() | ||
|
||
find_package(cppcheck) | ||
|
||
if(NOT cppcheck_FOUND) | ||
set(OPTION_CPPCHECK_ENABLED Off PARENT_SCOPE) | ||
message(STATUS "Check cppcheck skipped: cppcheck not found") | ||
|
||
return() | ||
endif() | ||
|
||
set(OPTION_CPPCHECK_ENABLED ${status} PARENT_SCOPE) | ||
message(STATUS "Check cppcheck") | ||
endfunction() | ||
|
||
# Enable or disable clang-tidy for health checks | ||
function(enable_clang_tidy status) | ||
if(NOT ${status}) | ||
set(OPTION_CLANG_TIDY_ENABLED ${status} PARENT_SCOPE) | ||
message(STATUS "Check clang-tidy skipped: Manually disabled") | ||
|
||
return() | ||
endif() | ||
|
||
find_package(clang_tidy) | ||
|
||
if(NOT clang_tidy_FOUND) | ||
set(OPTION_CLANG_TIDY_ENABLED Off PARENT_SCOPE) | ||
message(STATUS "Check clang-tidy skipped: clang-tidy not found") | ||
|
||
return() | ||
endif() | ||
|
||
set(OPTION_CLANG_TIDY_ENABLED ${status} PARENT_SCOPE) | ||
message(STATUS "Check clang-tidy") | ||
|
||
if(${CMAKE_VERSION} VERSION_GREATER "3.5" AND NOT CMAKE_EXPORT_COMPILE_COMMANDS) | ||
message(STATUS "clang-tidy makes use of the compile commands database. Make sure to configure CMake with -DCMAKE_EXPORT_COMPILE_COMMANDS=ON") | ||
endif() | ||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters