cmake
config_error
ai_generated
true
CMake Error: variable not visible in subdirectory scope
ID: cmake/subdirectory-scope-error
80%Fix Rate
84%Confidence
3Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3 | active | — | — | — |
Root Cause
CMake variable not propagated to subdirectory.
genericWorkarounds
-
90% success Use target properties instead of variables for propagation
-
88% success Set variable with PARENT_SCOPE in child: set(VAR value PARENT_SCOPE)
Dead Ends
Common approaches that don't work:
-
Set all variables as CACHE
72% fail
Pollutes cache, hard to override
-
Use PARENT_SCOPE everywhere
68% fail
Confusing variable flow