将项目根 CMakeLists.txt 文件替换为如下内容
cmake_minimum_required(VERSION 3.21)
project(C__Workplace)
set(CMAKE_CXX_STANDARD 14) # 前三行不用改
# 递归遍历所有的 c 文件
file (GLOB_RECURSE files *.c)
# 将所有的 c 文件单独生成可执行文件
foreach (file ${files})
string(REGEX REPLACE ".+/(.+)\\..*" "\\1" exe ${file})
add_executable (${exe} ${file})
message (\ \ \ \ --\ src/${exe}.cpp\ will\ be\ compiled\ to\ bin/${exe})
endforeach ()
设置 -> 构建、执行、部署 -> CMake -> 在编辑 CMakeLists.txt 或 其它 CMake 配置文件时重新加载 CMake 项目 ☑