cmake
configuration_error
ai_generated
true
CMake Error: The source directory /path/to/sub does not contain a CMakeLists.txt file.
ID: cmake/add-subdirectory-not-found
92%Fix Rate
90%Confidence
3Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3 | active | — | — | — |
Root Cause
add_subdirectory() points to a directory that lacks a CMakeLists.txt. Missing submodule, typo, or wrong path.
genericWorkarounds
-
95% success Initialize git submodules if the directory is a submodule
git submodule update --init --recursive
Sources: https://cmake.org/cmake/help/latest/command/find_package.html
-
90% success Check for typos in the directory path in CMakeLists.txt
# Verify: ls -la path/to/subdirectory/CMakeLists.txt
-
82% success Guard with if(EXISTS) for optional subdirectories
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/optional_sub/CMakeLists.txt) add_subdirectory(optional_sub) endif()
Dead Ends
Common approaches that don't work:
-
Create an empty CMakeLists.txt in the subdirectory
82% fail
An empty file silences the error but the subdirectory's targets will not be defined, causing link errors later.
-
Use EXCLUDE_FROM_ALL option to skip the directory
78% fail
EXCLUDE_FROM_ALL only skips default build; it does not skip configuration. CMake still needs the file to exist.