cmake
path_handling
ai_generated
true
CMake Error: The source directory does not exist — spaces in project path
ID: cmake/space-in-path-build-failure
88%Fix Rate
90%Confidence
4Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3 | active | — | — | — |
Root Cause
CMake build fails when project path contains spaces because generated Makefiles do not quote paths properly.
genericWorkarounds
-
93% success Move or symlink the project to a path without spaces
ln -s '/home/user/My Projects/app' /home/user/app-build && cmake -S /home/user/app-build -B build
Sources: https://cmake.org/cmake/help/latest/manual/cmake.1.html
-
90% success Use Ninja generator instead of Make — Ninja handles spaces in paths correctly
cmake -S . -B build -G Ninja # Ninja properly escapes spaces in generated build files
Sources: https://cmake.org/cmake/help/latest/generator/Ninja.html
Dead Ends
Common approaches that don't work:
-
Quote the path in CMakeLists.txt only
70% fail
CMake may quote it correctly in CMakeLists but the generated Makefile may not propagate quotes to all shell commands
-
Replace spaces with underscores in cmake -S argument
95% fail
This changes the actual path; cmake cannot find the source directory at the modified path