Skip to content

Fix #15240 (CI: use target commands instead of directory-level commands in CMake) - #9049

Closed
danmar wants to merge 1 commit into
cppcheck-opensource:mainfrom
cppchecksolutions:fix-15240
Closed

danmar wants to merge 1 commit into
cppcheck-opensource:mainfrom
cppchecksolutions:fix-15240

Conversation

@danmar

@danmar danmar commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

Newer CMake (seen on the macos-15 runner image 20261118.0550.1) reports add_compile_options(), add_definitions(), add_compile_definitions() and add_link_options() as non-target directives, and -Werror=dev makes the configure step fail:

CMake Error (non-target-directive) at cmake/compileroptions.cmake:50 (add_compile_options):
  Use of non-target directives is not recommended.  Consider
  target_compile_options instead.

Example: build_cmake_boost (macos-15) in https://github.com/cppcheck-opensource/cppcheck/actions/runs/44524782726

The global compile options, compile definitions and link options are now collected in CPPCHECK_COMPILE_OPTIONS, CPPCHECK_COMPILE_DEFINITIONS and CPPCHECK_LINK_OPTIONS. cppcheck_apply_global_options() is called at the end of the top-level CMakeLists.txt. It goes through all directories and prepends the lists to the target properties of every built target, so they still come before the target-specific options like before. This is the same approach as cppcheck-opensource/simplecpp#763, except that the options are prepended instead of being applied per target, because cppcheck has many targets in subdirectories with their own target_compile_options().

Verification: with CMake 4.2.3 / GCC 15 the generated flags.make, link.txt and compile_commands.json are byte-identical before and after this change for three configurations (Debug + GUI/GUI tests/triage/warnings-as-errors/check-internal/FILESDIR/glibcxx-debug, Release + ASan/UBSan, RelWithDebInfo + shared libs/TSan). The Clang/AppleClang/MSVC branches are covered by CI.

🤖 Generated with Claude Code

…ds in CMake)

Newer CMake reports add_compile_options(), add_definitions(),
add_compile_definitions() and add_link_options() as non-target
directives, and -Werror=dev makes the configure step fail. This is seen
on the macos-15 runners.

Collect the global compile options, compile definitions and link options
in CPPCHECK_COMPILE_OPTIONS, CPPCHECK_COMPILE_DEFINITIONS and
CPPCHECK_LINK_OPTIONS. cppcheck_apply_global_options() prepends them to
the target properties of all built targets, so they still come before
the target-specific options. The generated compiler and linker command
lines are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@danmar danmar added the ai-assisted contains code which was written with the assistance of AI - please review extra carefully label Nov 19, 2026
@danmar danmar closed this Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-assisted contains code which was written with the assistance of AI - please review extra carefully

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant