CMake "Cannot find source file" in CI
A source named in add_executable() or add_library() is not where CMake looked. A typo, a deleted file, or a generated file not yet produced triggers it.
What this error means
Configure or generation fails with "Cannot find source file" naming the path, often after a rename or when a generated source is referenced too early.
cmake
CMake Error at CMakeLists.txt:4 (add_executable):
Cannot find source file:
src/mian.cppCommon causes
How to fix it
Correct the source path
- Fix the typo or update the path to the file that exists.
- For generated files, mark them GENERATED or add the custom command first.
cmake
add_executable(app src/main.cpp) # corrected from mian.cppHow to prevent it
- Keep source lists in sync with the filesystem and declare generated sources with their producing commands before use.
Related guides
CMake "source directory does not appear to contain CMakeLists.txt" in CIFix CMake "The source directory does not appear to contain CMakeLists.txt" in CI - CMake was pointed at the w…
CMake "Could not find a package configuration file provided by X" in CIFix CMake "Could not find a package configuration file provided by X" in CI - find_package(CONFIG) cannot loc…