Skip to content
Latchkey

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.cpp

Common causes

How to fix it

Correct the source path

  1. Fix the typo or update the path to the file that exists.
  2. For generated files, mark them GENERATED or add the custom command first.
cmake
add_executable(app src/main.cpp)   # corrected from mian.cpp

How to prevent it

  • Keep source lists in sync with the filesystem and declare generated sources with their producing commands before use.

Frequently asked questions

What causes ""Cannot find source file""?
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.
How do I fix "Cannot find source file"?
Correct the source path

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card