Clion在一个cmake项目中运行多个main函数

# 遍历项目根目录下所有的 .cpp 文件
file (GLOB files *.cpp */*.cpp)
foreach (file ${files})
    string(REGEX REPLACE ".+/(.+)\\..*" "\\1" exe ${file})
    add_executable (${exe} ${file})
    message (\ \ \ \ --\ src/${exe}.cpp\ will\ be\ compiled\ to\ bin/${exe})
endforeach ()

将这几行配置加到cmakelists,如果有多层目录,修改file (GLOB files *.cpp */*.cpp)即可。
image

posted @ 2023-02-12 12:48  奔跑的蛋挞  阅读(175)  评论(0)    收藏  举报