Add warning message in CMakeDependentOption

Hi all,

I think, it would be great to add a warning message into CMakeDependentOption.cmake.

For example, if CMakeLists.txt defines:

cmake_dependent_option(USE_A "description" ON "USE_B" OFF)

but users pass -DUSE_B=OFF -DUSE_A=ON, the current behavior is to silently force USE_A to be OFF. A warning message will make it more visible to users, like:

CMake Warning at CMakeDependentOption.cmake:XX (message):
  Option USE_B was explicitly set to ON, but its dependency condition
  "USE_A" is NOT met.  Forcing USE_B to OFF.

Thank you for considering this suggestion.

Best regards,
SY

One example implementation could be:

--- CMakeDependentOption.cmake	2026-07-17 13:14:31.917565738 +0800
+++ CMakeDependentOption.cmake	2026-07-17 13:13:03.835053126 +0800
@@ -238,6 +238,16 @@
     else()
       if(${option} MATCHES "^${option}$")
       else()
+        get_property(_CDO_OPTION_TYPE CACHE ${option} PROPERTY TYPE)
+        if(NOT "${_CDO_OPTION_TYPE}" STREQUAL "INTERNAL"
+           AND NOT "${${option}}" STREQUAL "${force}")
+          message(WARNING 
+            "Option ${option} was explicitly set to ${${option}}, "
+            "but its dependency condition \"${depends}\" is NOT met. "
+            "Forcing ${option} to ${force}."
+          )
+        endif()
+        unset(_CDO_OPTION_TYPE)
         set(${option} "${${option}}" CACHE INTERNAL "${doc}")
       endif()
       set(${option} ${force})

@Growl1234 warning once as the overridden value is converted to INTERNAL seems reasonable, so long as we also have a way to suppress the warning. Please open an issue to propose the feature and discuss the details, and link it from here.

Thank you, I’ve just opened one with the same content.

I see CMake Issue 27960, thanks.