cmake 如何只编译 生成.o_1.2 CMake基础:hello-headers

本文介绍了如何使用CMake管理工程文件目录,将头文件和源文件分别放在不同文件夹。讲解了CMake的目录路径变量如CMAKE_SOURCE_DIR和CMAKE_CURRENT_BINARY_DIR,以及源文件变量和如何添加包含目录。通过示例展示了构建过程,包括标准输出和详细输出,帮助理解CMakeList.txt的编写方法。
摘要由CSDN通过智能技术生成

本节demo地址:https://github.com/ttroy50/cmake-examples/tree/master/01-basic/B-hello-headers

1 简介

还是一个hello cmake示例,将头文件和源文件放在不同的文件夹来组织工程文件目录。

B-hello-headers$ tree.├── CMakeLists.txt├── include│   └── Hello.h└── src    ├── Hello.cpp    └── main.cpp

CMakeList.txt:

# Set the minimum version of CMake that can be used# To find the cmake version run# $ cmake --versioncmake_minimum_required(VERSION 3.5)# Set the project nameproject (hello_headers)# Create a sources variable with a link to all cpp files to compileset(SOURCES    src/Hello.cpp    src/main.cpp)# Add an executable with the above sourcesadd_executable(hello_headers ${SOURCES})# Set the directories that should be included in the build command for this target# when running g++ these will be included as -I/directory/path/target_include_directories(hello_headers    PRIVATE         ${PROJECT_SOURCE_DIR}/include)

2 Concepts

这个地方的Concept翻译成概念觉得不妥,Concept的英英解释:an abstract or general idea inferred or derived from specific instances。应该取general idea inferred or derived from specific instances。根据内容把这个地方翻译成什么比较合适嘞,希望大家在评论里各抒己见。

2.1 目录路径(Directory Paths)

CMake语法指定了一些变量,这些变量可以用来帮助您在项目或源树中找到有用的目录。常用的如下所示:

  • CMAKE_SOURCE_DIR 源文件根目录
  • CMAKE_CURRENT_SOURCE_DIR 如果使用子项目和目录,则使用当前源目录
  • PROJECT_SOURCE_DIR 当前cmake项目的源目录
  • CMAKE_BINARY_DIR 根二进制/构建目录,运行cmake命令的目录
  • <
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值