Skip to content

Commit e515fdd

Browse files
danmarclaude
andcommitted
Fix #15240 (CI: use target commands instead of directory-level commands 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>
1 parent 68bf94a commit e515fdd

5 files changed

Lines changed: 145 additions & 116 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,6 @@ add_subdirectory(gui) # Graphical application
116116
add_subdirectory(tools)
117117
add_subdirectory(man)
118118

119+
cppcheck_apply_global_options(${CMAKE_SOURCE_DIR})
120+
119121
include(cmake/clang_tidy.cmake)

‎cmake/compilerDefinitions.cmake‎

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
if(MSVC)
2-
# add_compile_definitions() requires CMake 3.12
3-
42
# Visual Studio only sets _DEBUG
5-
add_compile_definitions($<$<CONFIG:Debug>:DEBUG>)
3+
list(APPEND CPPCHECK_COMPILE_DEFINITIONS $<$<CONFIG:Debug>:DEBUG>)
64

7-
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
8-
add_definitions(-DWIN32_LEAN_MEAN)
5+
list(APPEND CPPCHECK_COMPILE_DEFINITIONS _CRT_SECURE_NO_WARNINGS)
6+
list(APPEND CPPCHECK_COMPILE_DEFINITIONS WIN32_LEAN_MEAN)
97
endif()
108

119
# libstdc++-specific flags
1210
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR (NOT USE_LIBCXX AND CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
1311
if(CPPCHK_GLIBCXX_DEBUG AND CMAKE_BUILD_TYPE STREQUAL "Debug")
14-
add_definitions(-D_GLIBCXX_DEBUG)
12+
list(APPEND CPPCHECK_COMPILE_DEFINITIONS _GLIBCXX_DEBUG)
1513
endif()
1614
endif()
1715

@@ -22,59 +20,59 @@ if ((USE_LIBCXX AND CMAKE_CXX_COMPILER_ID MATCHES "Clang") OR CMAKE_CXX_COMPILER
2220
# TODO: determine proper version for AppleClang - current value is based on the oldest version avaialble in CI
2321
if((CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 18) OR
2422
(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 17))
25-
add_definitions(-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG)
23+
list(APPEND CPPCHECK_COMPILE_DEFINITIONS _LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG)
2624
else()
27-
add_definitions(-D_LIBCPP_ENABLE_ASSERTIONS=1)
25+
list(APPEND CPPCHECK_COMPILE_DEFINITIONS _LIBCPP_ENABLE_ASSERTIONS=1)
2826
endif()
2927
# TODO: also add _LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS?
3028
else()
3129
# TODO: check if this can be enabled again for Clang - also done in Makefile
32-
add_definitions(-D_GLIBCXX_DEBUG)
30+
list(APPEND CPPCHECK_COMPILE_DEFINITIONS _GLIBCXX_DEBUG)
3331
endif()
3432

35-
add_definitions(-D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES)
33+
list(APPEND CPPCHECK_COMPILE_DEFINITIONS _LIBCPP_REMOVE_TRANSITIVE_INCLUDES)
3634
endif()
3735

3836
if(HAVE_RULES)
39-
add_definitions(-DHAVE_RULES)
37+
list(APPEND CPPCHECK_COMPILE_DEFINITIONS HAVE_RULES)
4038
endif()
4139

4240
if(Boost_FOUND)
43-
add_definitions(-DHAVE_BOOST)
41+
list(APPEND CPPCHECK_COMPILE_DEFINITIONS HAVE_BOOST)
4442
if(USE_BOOST_INT128)
45-
add_definitions(-DHAVE_BOOST_INT128)
43+
list(APPEND CPPCHECK_COMPILE_DEFINITIONS HAVE_BOOST_INT128)
4644
endif()
4745
endif()
4846

4947
if(ENABLE_CHECK_INTERNAL)
50-
add_definitions(-DCHECK_INTERNAL)
48+
list(APPEND CPPCHECK_COMPILE_DEFINITIONS CHECK_INTERNAL)
5149
endif()
5250

5351
if(DISALLOW_THREAD_EXECUTOR)
54-
add_definitions(-DDISALLOW_THREAD_EXECUTOR)
52+
list(APPEND CPPCHECK_COMPILE_DEFINITIONS DISALLOW_THREAD_EXECUTOR)
5553
endif()
5654

5755
if(DISALLOW_PROCESS_EXECUTOR)
58-
add_definitions(-DDISALLOW_PROCESS_EXECUTOR)
56+
list(APPEND CPPCHECK_COMPILE_DEFINITIONS DISALLOW_PROCESS_EXECUTOR)
5957
endif()
6058

6159
if(NO_UNIX_SIGNAL_HANDLING)
62-
add_definitions(-DNO_UNIX_SIGNAL_HANDLING)
60+
list(APPEND CPPCHECK_COMPILE_DEFINITIONS NO_UNIX_SIGNAL_HANDLING)
6361
endif()
6462

6563
if(NO_UNIX_BACKTRACE_SUPPORT)
66-
add_definitions(-DNO_UNIX_BACKTRACE_SUPPORT)
64+
list(APPEND CPPCHECK_COMPILE_DEFINITIONS NO_UNIX_BACKTRACE_SUPPORT)
6765
endif()
6866

6967
if(NO_WINDOWS_SEH)
70-
add_definitions(-DNO_WINDOWS_SEH)
68+
list(APPEND CPPCHECK_COMPILE_DEFINITIONS NO_WINDOWS_SEH)
7169
endif()
7270

7371
if(NOT MSVC)
74-
add_definitions(-DHAVE_EXECINFO_H=${HAVE_EXECINFO_H})
72+
list(APPEND CPPCHECK_COMPILE_DEFINITIONS HAVE_EXECINFO_H=${HAVE_EXECINFO_H})
7573
endif()
7674

7775
if(FILESDIR_DEF)
7876
file(TO_CMAKE_PATH "${FILESDIR_DEF}" _filesdir)
79-
add_definitions(-DFILESDIR="${_filesdir}")
77+
list(APPEND CPPCHECK_COMPILE_DEFINITIONS FILESDIR="${_filesdir}")
8078
endif()

0 commit comments

Comments
 (0)