CLion多个mian的方法
这个方法是网上看到的,在这里记录一下方便自己以后查看。
修改CMakeLists.txt的内容如下:
cmake_minimum_required(VERSION 3.20)
project(listmanagement)
set(CMAKE_CXX_STANDARD 14)
add_executable(listmanagement main.cpp)
# 官方提供了一种递归的方法
# 这样在运行框会多一个 CMakeCXXCompilerId,不过无伤大雅
file (GLOB_RECURSE 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 ()