mirror of
https://github.com/open62541/open62541.git
synced 2025-06-03 04:00:21 +00:00
CMake: add static analyzer during build process (by option)
This commit is contained in:
parent
269d1ffbdc
commit
648498145b
@ -3,6 +3,8 @@ Language: Cpp
|
||||
BasedOnStyle: llvm
|
||||
IndentWidth: 4
|
||||
ColumnLimit: 120
|
||||
ForEachMacros: [ foreach, LIST_FOREACH, LIST_FOREACH_SAFE ]
|
||||
SpacesBeforeTrailingComments: 2
|
||||
#SpaceBeforeRangeBasedForLoopColon: false
|
||||
#ForEachMacros: [ foreach, LIST_FOREACH, LIST_FOREACH_SAFE ]
|
||||
DisableFormat: false
|
||||
|
||||
|
3
.clang-tidy
Normal file
3
.clang-tidy
Normal file
@ -0,0 +1,3 @@
|
||||
Checks: 'cert-*,performance-*,readability-*,-readability-braces-around-statements'
|
||||
WarningsAsErrors: 'cert-*,performance-*,readability-*,-readability-braces-around-statements'
|
||||
FormatStyle: file
|
@ -279,6 +279,11 @@ mark_as_advanced(UA_DEBUG_DUMP_PKGS)
|
||||
option(UA_ENABLE_HARDENING "Enable Hardening measures (e.g. Stack-Protectors and Fortify)" ON)
|
||||
mark_as_advanced(UA_ENABLE_HARDENING)
|
||||
|
||||
if(CMAKE_VERSION VERSION_GREATER 3.6)
|
||||
set(UA_ENABLE_STATIC_ANALYZER "OFF" CACHE STRING "Enable installed static analyzer during build process (off/minimal/reduced/full)")
|
||||
SET_PROPERTY(CACHE UA_ENABLE_STATIC_ANALYZER PROPERTY STRINGS "OFF" "MINIMAL" "REDUCED" "FULL")
|
||||
endif()
|
||||
|
||||
# Build Targets
|
||||
option(UA_BUILD_EXAMPLES "Build example servers and clients" OFF)
|
||||
option(UA_BUILD_TOOLS "Build OPC UA shell tools" OFF)
|
||||
@ -350,6 +355,12 @@ if(UA_ENABLE_MULTITHREADING)
|
||||
MESSAGE(WARNING "UA_ENABLE_MULTITHREADING is enabled. The feature is under development and marked as EXPERIMENTAL")
|
||||
endif()
|
||||
|
||||
########################
|
||||
# Linting during build #
|
||||
########################
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
include(linting_build)
|
||||
|
||||
######################
|
||||
# External Libraries #
|
||||
######################
|
||||
@ -1055,43 +1066,10 @@ if(UA_BUILD_TOOLS)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
############################
|
||||
# Linting run (clang-tidy) #
|
||||
############################
|
||||
|
||||
find_package(ClangTools)
|
||||
add_custom_target(lint ${CLANG_TIDY_PROGRAM}
|
||||
${lib_sources}
|
||||
-checks=cert-*,performance-*,readability-*,-readability-braces-around-statements
|
||||
-warnings-as-errors=cert-*,performance-*,readability-*,-readability-braces-around-statements
|
||||
--
|
||||
-std=c99
|
||||
-I${PROJECT_SOURCE_DIR}/include
|
||||
-I${PROJECT_SOURCE_DIR}/plugins
|
||||
-I${PROJECT_SOURCE_DIR}/deps
|
||||
-I${PROJECT_SOURCE_DIR}/src
|
||||
-I${PROJECT_SOURCE_DIR}/src/server
|
||||
-I${PROJECT_SOURCE_DIR}/src/client
|
||||
-I${PROJECT_BINARY_DIR}/src_generated
|
||||
DEPENDS ${lib_sources}
|
||||
COMMENT "Run clang-tidy on the library")
|
||||
add_dependencies(lint open62541)
|
||||
|
||||
add_custom_target(cpplint cpplint
|
||||
${lib_sources}
|
||||
${internal_headers}
|
||||
${default_plugin_headers}
|
||||
${default_plugin_sources}
|
||||
${ua_architecture_headers}
|
||||
${ua_architecture_sources}
|
||||
DEPENDS ${lib_sources}
|
||||
${internal_headers}
|
||||
${default_plugin_headers}
|
||||
${default_plugin_sources}
|
||||
${ua_architecture_headers}
|
||||
${ua_architecture_sources}
|
||||
|
||||
COMMENT "Run cpplint code style checker on the library")
|
||||
########################
|
||||
# Linting as target #
|
||||
########################
|
||||
include(linting_target)
|
||||
|
||||
##########################
|
||||
# Installation #
|
||||
@ -1250,7 +1228,7 @@ set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "_CmakePredifinedTargets"
|
||||
|
||||
set_target_properties(open62541 PROPERTIES FOLDER "open62541/lib")
|
||||
set_target_properties(open62541-object PROPERTIES FOLDER "open62541/lib")
|
||||
set_target_properties(lint PROPERTIES FOLDER "CodeAnalysis")
|
||||
set_target_properties(clang-tidy PROPERTIES FOLDER "CodeAnalysis")
|
||||
if (UA_ENABLE_AMALGAMATION)
|
||||
set_target_properties(open62541-amalgamation-header PROPERTIES FOLDER "open62541/lib")
|
||||
set_target_properties(open62541-amalgamation-source PROPERTIES FOLDER "open62541/lib")
|
||||
|
@ -13,4 +13,8 @@ filter=-build/include
|
||||
filter=-build/header_guard
|
||||
filter=-readability/alt_tokens
|
||||
filter=-runtime/indentation_namespace
|
||||
filter=-whitespace/comments
|
||||
filter=-whitespace/blank_line
|
||||
filter=-readability/braces
|
||||
exclude_files=deps/*
|
||||
exclude_files=build/*
|
||||
|
3
cppcheck-suppressions.txt
Normal file
3
cppcheck-suppressions.txt
Normal file
@ -0,0 +1,3 @@
|
||||
missingIncludeSystem
|
||||
unusedFunction
|
||||
*:build
|
53
tools/cmake/linting_build.cmake
Normal file
53
tools/cmake/linting_build.cmake
Normal file
@ -0,0 +1,53 @@
|
||||
if(UA_ENABLE_STATIC_ANALYZER STREQUAL MINIMAL OR UA_ENABLE_STATIC_ANALYZER STREQUAL REDUCED OR UA_ENABLE_STATIC_ANALYZER STREQUAL FULL)
|
||||
# cpplint just gives warnings about coding style
|
||||
find_program(CPPLINT_EXE NAMES "cpplint")
|
||||
if(CPPLINT_EXE)
|
||||
set(CMAKE_C_CPPLINT "${CPPLINT_EXE};--quiet")
|
||||
set(CMAKE_CXX_CPPLINT "${CPPLINT_EXE};--quiet")
|
||||
endif()
|
||||
endif()
|
||||
if(UA_ENABLE_STATIC_ANALYZER STREQUAL REDUCED OR UA_ENABLE_STATIC_ANALYZER STREQUAL FULL)
|
||||
# clang-tidy has certain warnings as errors
|
||||
find_program(CLANG_TIDY_EXE NAMES "clang-tidy")
|
||||
if(CLANG_TIDY_EXE)
|
||||
set(CMAKE_C_CLANG_TIDY "${CLANG_TIDY_EXE};-p=compile_commands.json")
|
||||
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXE};-p=compile_commands.json")
|
||||
endif()
|
||||
elseif(UA_ENABLE_STATIC_ANALYZER STREQUAL FULL)
|
||||
# cppcheck provides just warnings but checks "all" (for now) - huge CPU impact
|
||||
find_program(CPPCHECK_EXE NAMES "cppcheck")
|
||||
if(CPPCHECK_EXE)
|
||||
set(CMAKE_C_CPPCHECK "${CPPCHECK_EXE};--project=compile_commands.json;--enable=all;--inconclusive;--inline-suppr;\
|
||||
--suppressions-list=${PROJECT_SOURCE_DIR}/cppcheck-suppressions.txt;-D__GNUC__;-i ${PROJECT_SOURCE_DIR}/build")
|
||||
set(CMAKE_CXX_CPPCHECK "${CPPCHECK_EXE};--project=compile_commands.json;--enable=all;--inconclusive;--inline-suppr;\
|
||||
--suppressions-list=${PROJECT_SOURCE_DIR}/cppcheck-suppressions.txt;-D__GNUC__;-i ${PROJECT_SOURCE_DIR}/build")
|
||||
endif()
|
||||
|
||||
# "include what you use" requires additional configuration - ignore for now
|
||||
find_program(IWYU_EXE NAMES "iwyu")
|
||||
if(IWYU_EXE)
|
||||
#set(CMAKE_C_INCLUDE_WHAT_YOU_USE "${IWYU_EXE}")
|
||||
#set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE "${IWYU_EXE}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# adds new target "clangformat" to enforce clang-format rules
|
||||
find_program(CLANG_FORMAT_EXE NAMES "clang-format")
|
||||
if(CLANG_FORMAT_EXE)
|
||||
file(GLOB_RECURSE FILES_TO_FORMAT
|
||||
${PROJECT_SOURCE_DIR}/arch/*.c
|
||||
${PROJECT_SOURCE_DIR}/plugins/*.c
|
||||
${PROJECT_SOURCE_DIR}/src/*.c
|
||||
${PROJECT_SOURCE_DIR}/arch/*.h
|
||||
${PROJECT_SOURCE_DIR}/include/*.h
|
||||
${PROJECT_SOURCE_DIR}/plugins/*.h
|
||||
${PROJECT_SOURCE_DIR}/src/*.h
|
||||
)
|
||||
add_custom_target(
|
||||
clangformat COMMAND ${CLANG_FORMAT_EXE}
|
||||
-style=file
|
||||
-i
|
||||
${FILES_TO_FORMAT}
|
||||
)
|
||||
endif()
|
||||
|
30
tools/cmake/linting_target.cmake
Normal file
30
tools/cmake/linting_target.cmake
Normal file
@ -0,0 +1,30 @@
|
||||
find_package(ClangTools)
|
||||
add_custom_target(clang-tidy ${CLANG_TIDY_PROGRAM}
|
||||
${lib_sources}
|
||||
-p=compile_commands.json
|
||||
--
|
||||
-I${PROJECT_SOURCE_DIR}/include
|
||||
-I${PROJECT_SOURCE_DIR}/plugins
|
||||
-I${PROJECT_SOURCE_DIR}/deps
|
||||
-I${PROJECT_SOURCE_DIR}/src
|
||||
-I${PROJECT_SOURCE_DIR}/src/server
|
||||
-I${PROJECT_SOURCE_DIR}/src/client
|
||||
-I${PROJECT_BINARY_DIR}/src_generated
|
||||
DEPENDS ${lib_sources}
|
||||
COMMENT "Run clang-tidy on the library")
|
||||
add_dependencies(clang-tidy open62541)
|
||||
|
||||
add_custom_target(cpplint cpplint
|
||||
${lib_sources}
|
||||
${internal_headers}
|
||||
${default_plugin_headers}
|
||||
${default_plugin_sources}
|
||||
${ua_architecture_headers}
|
||||
${ua_architecture_sources}
|
||||
DEPENDS ${lib_sources}
|
||||
${internal_headers}
|
||||
${default_plugin_headers}
|
||||
${default_plugin_sources}
|
||||
${ua_architecture_headers}
|
||||
${ua_architecture_sources}
|
||||
COMMENT "Run cpplint code style checker on the library")
|
@ -161,6 +161,12 @@ if ! [ -z ${ANALYZE+x} ]; then
|
||||
make -j
|
||||
cd .. && rm build -rf
|
||||
|
||||
#mkdir -p build && cd build
|
||||
#cmake -DUA_ENABLE_STATIC_ANALYZER=REDUCED ..
|
||||
## previous clang-format to reduce to non-trivial warnings
|
||||
#make clangformat
|
||||
#make
|
||||
#cd .. && rm build -rf
|
||||
else
|
||||
cppcheck --template "{file}({line}): {severity} ({id}): {message}" \
|
||||
--enable=style --force --std=c++11 -j 8 \
|
||||
|
Loading…
Reference in New Issue
Block a user