How to fix CMake Error: Cannot find source file: *.cpp
Problem:
You are trying to build your CMake-based project using a CMakeLists.txt like
CMakeLists.example.txt
cmake_minimum_required(VERSION 3.10)
project(my_project)
add_executable(my_project *.cpp)Solution
You can’t use the glob pattern *.cpp directly in add_executable(). You need to use file(GLOB ...) in order to set a variable, which you can then use in add_executable():
cmake_fix_example.txt
cmake_minimum_required(VERSION 3.10)
project(my_project)
file(GLOB SRC_FILES *.cpp)
add_executable(my_project ${SRC_FILES})Check out similar posts by category:
CMake
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow