本节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命令的目录 <