# CMake Error: Cannot find source file: /path/to/src/main.cpp. Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .f08.

- **ID:** `cmake/target-sources-glob-missing`
- **Domain:** cmake
- **Category:** build_error
- **Verification:** ai_generated
- **Fix Rate:** 95%

## Root Cause

A source file listed in target_sources() or add_executable() does not exist at the specified path, often due to a typo, missing file, or incorrect use of generator expressions that resolve to an empty string.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| CMake 3.10 | active | — | — |
| CMake 3.18 | active | — | — |
| CMake 3.25 | active | — | — |

## Workarounds

1. **Correct the file path in the CMakeLists.txt, e.g., change `target_sources(mylib PRIVATE src/main.cpp)` to the actual path: `target_sources(mylib PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp)`.** (95% success)
   ```
   Correct the file path in the CMakeLists.txt, e.g., change `target_sources(mylib PRIVATE src/main.cpp)` to the actual path: `target_sources(mylib PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp)`.
   ```
2. **If the file is generated by a custom command, ensure the generation target runs before the compile step by adding `add_dependencies(mylib generator_target)`.** (85% success)
   ```
   If the file is generated by a custom command, ensure the generation target runs before the compile step by adding `add_dependencies(mylib generator_target)`.
   ```
3. **Use `configure_file()` to generate the missing source from a template if it is meant to be created at configure time.** (80% success)
   ```
   Use `configure_file()` to generate the missing source from a template if it is meant to be created at configure time.
   ```

## Dead Ends

- **Creating an empty source file at the missing path** — Adding the missing file as an empty file may bypass the error but will cause compilation failures due to missing code. (85% fail)
- **Commenting out the target_sources() call** — Removing the source file entry from target_sources() may allow the build to proceed but will exclude the file from compilation, leading to undefined symbols. (75% fail)
- **Replacing explicit source list with file(GLOB)** — Using file(GLOB) to automatically collect sources may mask the issue and lead to unpredictable builds if files are added or removed. (70% fail)
