cmake config_error ai_generated true

CMake Error: variable not visible in subdirectory scope

ID: cmake/subdirectory-scope-error

Also available as: JSON · Markdown
80%Fix Rate
84%Confidence
3Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3 active

Root Cause

CMake variable not propagated to subdirectory.

generic

Workarounds

  1. 90% success Use target properties instead of variables for propagation
  2. 88% success Set variable with PARENT_SCOPE in child: set(VAR value PARENT_SCOPE)

Dead Ends

Common approaches that don't work:

  1. Set all variables as CACHE 72% fail

    Pollutes cache, hard to override

  2. Use PARENT_SCOPE everywhere 68% fail

    Confusing variable flow