CMAKE_CXX_CPPCHECK - scope leak

Hello,

I am using CMake 4.1.0 with the following generators :

  • Unix Makefiles on Linux
  • MSYS Makefiles on Windows

These are used to build a C++ project. My filetree looks like this :

Toplevel:
    - CMakeLists.txt
    Subdir1 :
        - CMakeLists.txt
    Subdir2 :
        - CMakeLists.txt

I enabled cppcheck analysis on Subdir1 with the following

# following is defined in toplevel CMakeLists.txt
set(CPPCHECK_COMMON_OPTIONS --check-level=exhaustive;--inline-suppr;--quiet;--error-exitcode=1; CACHE INTERNAL "Common cppcheck options, required by all components.")
set(CPPCHECK_DEFAULT_CHECKS --enable=warning,performance,portability CACHE INTERNAL "Default additional checks to use in cppcheck.")

macro(enable_cppcheck_cxx)
    if(NOT CPPCHECK_DISABLE)
        set(CMAKE_CXX_CPPCHECK ${CPPCHECK} ${CPPCHECK_OPTIONS})
    else()
        message(NOTICE "CPPCHECK (CXX) will be disabled in ${CMAKE_CURRENT_SOURCE_DIR}.")
    endif()
endmacro()

# following is defined in  Subdir1/CMakeLists.txt
set(CPPCHECK_OPTIONS
    ${CPPCHECK_COMMON_OPTIONS}
    ${CPPCHECK_DEFAULT_CHECKS}
    -D__GNUC__
)

mycompany_enable_cppcheck_cxx()

Using Unix Makefiles generator on Linux, all goes well, cppcheck is run only on Subdir1.
But for some reason on MSYS Makefiles generator on Windows, cppcheck is run on both Subdir1 and Subdir2, which i don’t want to.

This seems to be some variable scope leak that occurs only on windows (haven’t tested other generators).

I haven’t found any documentation on this, is this a known behavior ? How can i fix this ?

Thank you,
Mathias