修改CMakeLists.txt文件为
project(Your Project Name)
set(CMAKE_CXX_STANDARD 11)
# 遍历项目二级目录下所有的 .cpp 文件
file (GLOB files */*.cpp)
foreach (file ${files})
string(REGEX REPLACE ".+/(.+)/(.+)\\..*" "\\1-\\2" exe ${file})
add_executable (${exe} ${file})
endforeach ()
# 遍历项目根目录下所有的 .cpp 文件
file (GLOB files *.cpp)
foreach (file ${files})
string(REGEX REPLACE ".+/(.+)\\..*" "\\1" exe ${file})
add_executable (${exe} ${file})
endforeach ()
效果
新建CPP文件的main函数也会有运行按钮