可以创建多个main文件

  1. 修改文件cmakelists.txtimage.png
  2. 前三行不用变,后边需要修改为如下
    image.png

    1
    2
    3
    4
    5
    6
    7
    8
    9
    # 遍历项目根目录下所有的 .cpp 文件
    file (GLOB_RECURSE files *.cpp)

    #将所有的cpp文件单独生成可执行文件
    foreach (file ${files})
    string(REGEX REPLACE ".+/(.+)\\..*" "\\1" exe ${file})
    add_executable (${exe} ${file})
    message (\ \ \ \ --\ ${file}\ will\ be\ compiled\ to\ bin/${exe})
    endforeach ()
  3. 创建选择这个
    image.png

  4. 取消勾选这个
    image.png