# CMake Error: add_executable cannot create target "myapp" because no source files were specified.

- **ID:** `cmake/add-executable-no-sources`
- **Domain:** cmake
- **Category:** config_error
- **Verification:** ai_generated
- **Fix Rate:** 95%

## Root Cause

The add_executable command was called without any source file arguments, either due to a missing variable expansion or an empty list.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.10 | active | — | — |
| 3.16 | active | — | — |
| 3.22 | active | — | — |
| 3.26 | active | — | — |

## Workarounds

1. **Check the variable that holds source files: message(STATUS "SOURCES=${SOURCES}") before add_executable. Ensure it is not empty. For example, if SOURCES is set via file(GLOB ...), verify the glob pattern matches files.** (95% success)
   ```
   Check the variable that holds source files: message(STATUS "SOURCES=${SOURCES}") before add_executable. Ensure it is not empty. For example, if SOURCES is set via file(GLOB ...), verify the glob pattern matches files.
   ```
2. **Explicitly list source files in add_executable: add_executable(myapp main.cpp utils.cpp). Avoid using empty variables.** (90% success)
   ```
   Explicitly list source files in add_executable: add_executable(myapp main.cpp utils.cpp). Avoid using empty variables.
   ```
3. **If using a macro or function, ensure arguments are passed correctly: function(my_add_executable name) add_executable(${name} ${ARGN}) endfunction(). Call with at least one source.** (85% success)
   ```
   If using a macro or function, ensure arguments are passed correctly: function(my_add_executable name) add_executable(${name} ${ARGN}) endfunction(). Call with at least one source.
   ```

## Dead Ends

- **Adding a dummy source file like 'main.cpp' without checking if it exists** — If the file does not exist, CMake will later fail with 'Cannot find source file'. The root cause (empty variable) remains unaddressed. (80% fail)
- **Removing the add_executable call entirely and relying on add_library** — The project needs an executable target; removing it breaks the build logic, and the error shifts to missing target. (90% fail)
- **Setting CMAKE_MINIMUM_REQUIRED to a lower version** — The error is not version-dependent; it is a syntax/argument error that is caught at parse time regardless of CMake version. (95% fail)
