add source files automatically

    
file(GLOB_RECURSE SOURCES "src/*.cpp")

# Add the main executable
add_executable(${PROJECT_NAME} ${SOURCES})

# automatically adds new source files, without this whenever new cpp files are added, you still have to run cmake to regenerate
foreach(_source ${SOURCES})
    set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${_source})
endforeach()

    

edit this page