Skip to content

Commit 001a751

Browse files
committed
removing static analysis
1 parent b95092e commit 001a751

File tree

4 files changed

+68
-6
lines changed

4 files changed

+68
-6
lines changed

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,17 @@
22
cmake_install.cmake
33
Makefile
44
build
5+
CMakeLists.txt.user
6+
CMakeCache.txt
7+
CMakeFiles
8+
CMakeScripts
9+
Testing
10+
Makefile
11+
cmake_install.cmake
12+
install_manifest.txt
13+
compile_commands.json
14+
CTestTestfile.cmake
15+
_deps
16+
CMakeUserPresets.json
17+
lib
18+
tests/modbus_basic_tests

.gitmodules

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
[submodule "examples/libmodbus_tests/-f"]
2-
path = examples/libmodbus_tests/-f
3-
url = git@github.com:stephane/libmodbus.git
41
[submodule "examples/libmodbus_tests/libmodbus"]
52
path = examples/libmodbus_tests/libmodbus
63
url = git@github.com:stephane/libmodbus.git
74
[submodule "examples/pymodbus_tests/pymodbus"]
85
path = examples/pymodbus_tests/pymodbus
96
url = git@github.com:riptideio/pymodbus.git
10-
[submodule "tests/cmake/CMakeStaticAnalysis"]
11-
path = tests/CMakeStaticAnalysis
12-
url = git@github.com:snhobbs/CMakeStaticAnalysis.git
137
[submodule "lib/CppUtilities"]
148
path = external/CppUtilities
159
url = git@github.com:snhobbs/CppUtilities

CMakeLists.txt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,60 @@
11
cmake_minimum_required(VERSION 3.15.0)
22

33
project(ModbusBasic)
4+
5+
# Enable testing
46
enable_testing()
7+
8+
# Set up GoogleTest as a subdirectory. It assumes you have googletest located in external/googletest.
9+
# This will build GoogleTest inside the build directory as well.
510
add_subdirectory(external/googletest)
11+
12+
# Add the tests subdirectory.
13+
# This assumes that you have a 'tests' directory in your project, where your test code resides.
614
add_subdirectory(tests)
15+
16+
# Optional: Set CMake build type (Release, Debug, etc.)
17+
set(CMAKE_BUILD_TYPE Release) # You can also set it to Debug, RelWithDebInfo, etc.
18+
19+
# Optional: Define output directories for binaries and libraries (useful for keeping everything in the build folder)
20+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
21+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
22+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
23+
24+
# Function to detect changed source files using `git diff`
25+
function(GetChangedFiles changed_files)
26+
# Detect changed files that are tracked in the git repository (only .cpp, .h files)
27+
execute_process(
28+
COMMAND git diff --name-only HEAD~1 HEAD -- '*.cpp' '*.h'
29+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
30+
OUTPUT_VARIABLE changed_files
31+
OUTPUT_STRIP_TRAILING_WHITESPACE
32+
)
33+
# Split the output into a list of changed files
34+
string(REPLACE "\n" ";" changed_files "${changed_files}")
35+
list(REMOVE_ITEM changed_files "") # Remove empty items
36+
endfunction()
37+
38+
# Run static analysis only on the changed files
39+
function(RunStaticAnalysisOnChangedFiles)
40+
GetChangedFiles(changed_files)
41+
42+
if(changed_files)
43+
message(STATUS "Running static analysis on the following files: ${changed_files}")
44+
# Run tools like cpplint, cppcheck, etc. only on the changed files
45+
cpplint("${CMAKE_SOURCE_DIR}" "${changed_files}" cpplint)
46+
Cppcheck("${CMAKE_SOURCE_DIR}" "${changed_files}" cppcheck)
47+
flint("${CMAKE_SOURCE_DIR}" "${changed_files}" flint)
48+
flawfinder("${CMAKE_SOURCE_DIR}" "${changed_files}" flawfinder)
49+
cppclean("${CMAKE_SOURCE_DIR}" "${changed_files}" cppclean)
50+
clangcheck("${CMAKE_SOURCE_DIR}" "${changed_files}" clang-check)
51+
else()
52+
message(STATUS "No changes detected, skipping static analysis.")
53+
endif()
54+
endfunction()
55+
56+
# Add a target for static analysis
57+
add_custom_target(StaticAnalysis
58+
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/run_static_analysis.cmake
59+
COMMENT "Running Static Analysis on changed files..."
60+
)
File renamed without changes.

0 commit comments

Comments
 (0)