代码改变世界

Clion编译器中 建立多目录工程的 CMakeLists写法

2021-09-26 09:07  dreamboy2000  阅读(360)  评论(0编辑  收藏  举报

1、头文件 和 库文件 分目录放置
在这里插入图片描述

cmake_minimum_required(VERSION 3.15)
project(CompanySystem)
 
# Add header file include directories
include_directories(./include)
# Add block directories
set(SRC src/workerManger.cpp  src/employee.cpp  src/manager.cpp src/boss.cpp)
 
# Target
add_executable(CompanySystem main.cpp ${SRC} )
2、头文件与其对应源文件放置到同一个目录下

在这里插入图片描述

cmake_minimum_required(VERSION 3.15)
project(untitled1)
 
 
# Add header file include directories
include_directories(./employee ./manager ./worker ./workerManager ./boss)
# Add block directories
set(BOSS_SRC boss/boss.cpp)
set(EMPLOYEE_SRC employee/employee.cpp)
set(MANAGER_SRC manager/manager.cpp)
set(WM_SRC workerManager/workerManager.cpp)
# Target
add_executable(untitled1 main.cpp ${BOSS_SRC} ${EMPLOYEE_SRC} ${MANAGER_SRC} ${WM_SRC})