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.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →