'How to add cppcheck and clang-format inside cmake?
I have a project where I want to run cppcheck and clang-format using cmake when building the project. Here is my code and the output. What am I missing? The output does not run either the cppcheck and clang-format. Both programs are on my path.
CMakeLists.txt:
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
# set your relative path to the gcc compiler
SET(CMAKE_C_COMPILER "gcc")
project(eec_cmocka_example VERSION 1.0 LANGUAGES C)
include(cmake/cppcheck.cmake)
include(cmake/clang-format.cmake)
include(cmake/FetchCMocka.cmake)
file(GLOB_RECURSE TEST_SRC_FILES unit-tests/*.c)
file(GLOB_RECURSE SRC_FILES src/*.c)
add_executable(eec_cmocka_example main.c ${SRC_FILES} ${TEST_SRC_FILES})
target_compile_features(eec_cmocka_example PRIVATE c_std_99)
target_link_libraries(eec_cmocka_example PRIVATE cmocka-static)
enable_testing()
add_test(NAME eec_cmocka_example COMMAND eec_cmocka_example)
set_property(TARGET eec_cmocka_example PROPERTY LINK_FLAGS "${DEFAULT_LINK_FLAGS} -Wl,\
--wrap=get_rx_dali_flag,\
--wrap=set_led_frequency,\
--wrap=application_process")
cppcheck.cmake:
file(GLOB_RECURSE ALL_SOURCE_FILES src/*.c src/*.h)
add_custom_target(
cppcheck
ALL
COMMAND /usr/bin/cppcheck
--enable=warning,performance,portability,information,missingInclude
--suppress=missingIncludeSystem
--std=c99
--library=std.cfg
--template="[{severity}][{id}] {message} {callstack} \(On {file}:{line}\)"
--verbose
--quiet
${ALL_SOURCE_FILES}
)
clang-format.cmake:
file(GLOB_RECURSE ALL_SOURCE_FILES *.cpp *.h)
add_custom_target(
clangformat
ALL
COMMAND /usr/bin/clang-format
-style=Microsoft
-i
${ALL_SOURCE_FILES}
)
Output:
arda@arda-VirtualBox:~/Desktop/eec/UnitTesting_example/build$ make clangformat
Built target clangformat
arda@arda-VirtualBox:~/Desktop/eec/UnitTesting_example/build$ make cppcheck
Built target cppcheck
arda@arda-VirtualBox:~/Desktop/eec/UnitTesting_example/build$ make
[ 0%] Built target cppcheck
[ 0%] Built target clangformat
Consolidate compiler generated dependencies of target cmocka-static
[ 22%] Built target cmocka-static
Consolidate compiler generated dependencies of target eec_cmocka_example
[ 77%] Built target eec_cmocka_example
Consolidate compiler generated dependencies of target cmocka
[100%] Built target cmocka
arda@arda-VirtualBox:~/Desktop/eec/UnitTesting_example/build$
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
