3

I want to create a CMake 3.15+ check target which will run cppcheck using the native CMake CXX_CPPCHECK target property. I've set up the binary paths correctly, I also have an ANALYSIS_SOURCES variable with the list of source files I want to run through. However, I don't understand how to create a target which would depend on ${ANALYSIS_SOURCES}. My make check doesn't do any work even though I see:

Built target cppcheck-analysis
Built target check

I've tried the following setup:

cmake_minimum_required(VERSION 3.15)
project(check_target)

add_custom_target(check)
set_target_properties(
  check PROPERTIES
  CXX_STANDARD 17
  CXX_STANDARD_REQUIRED ON
  COMPILE_FLAGS "${WARNING_FLAGS}"
)

set(ANALYSIS_SOURCES src/Main.cpp)

add_custom_target(cppcheck-analysis DEPENDS ${ANALYSIS_SOURCES})
set_target_properties(
  cppcheck-analysis PROPERTIES
  CXX_CPPCHECK "/usr/bin/cppcheck"
)

add_dependencies(check cppcheck-analysis)

I suspect I'm using the cppcheck-analysis DEPENDS argument incorrectly. What would be the right approach?

dm3
  • 2,038
  • 2
  • 17
  • 20
  • According to [this](https://stackoverflow.com/questions/2937128/cmake-add-custom-command-not-being-run) post, maybe try using `add_custom_command()` instead of `add_custom_target()` for the `cppcheck-analysis` target? – Developer Paul Aug 07 '19 at 02:52
  • [Related discussion on the CMake Discourse site](https://discourse.cmake.org/t/static-analyzers-as-seperate-targets/4074). – starball Jan 19 '23 at 02:17

0 Answers0