NotePublic/Software/Development/Tools/CMake/CMake_基本语法.md

114 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# CMake 基本语法
CMake 支持大写、小写、混合大小写的命令。
## 最小版本号
```sh
cmake_minimum_required(VERSION 2.8)
```
## 工程名
```sh
project(<Project Name>)
```
## Include 路径
*需要出现在 add_executable 和 add_library 等之前。*
```sh
include_directories(
<Path1>
<Path2>
...
<PathN>
)
```
## 添加库路径
*需要出现在 add_executable 和 add_library 等之前。*
```sh
link_directories(
<Path1>
<Path2>
...
<PathN>
)
```
## 添加库文件
*已经被废弃了,需要出现在 add_executable 和 add_library 等之前。*
```sh
link_libraries(
<Library1>
<Library2>
...
<LibraryN>
)
```
支持直接全路径的写法。
## 可执行文件目标和源码
```sh
add_executable(
<Executable Name>
<Source1>
<Source2>
...
<SourceN>
)
```
## 库文件目标和源码
```sh
add_library(
<Library>
<SHARED/STATIC>
<Source1>
<Source2>
...
<SourceN>
)
```
## 为目标添加库文件
*可添加的动态库或静态库,可以在 add_executable 和 add_library 等之后。*
```sh
target_link_libraries(
<Target Name>
<Library1>
<Library2>
...
<LibraryN>
)
```
## 添加依赖工程
```sh
add_dependencies(
<Target Name>
<Depend Target1>
<Depend Target2>
...
<Depend TargetN>
)
```
## 参考资料
[cmake手册详解](https://blog.csdn.net/chengde6896383/article/details/81330564)
[cmake 的link_libraries和target_link_libraries](https://blog.csdn.net/harryhare/article/details/89143410)
[【学习cmake】cmake如何使用链接库 link_directories, LINK_LIBRARIES, target_link_librariesFIND_PACKAGE实践篇2](https://blog.csdn.net/KYJL888/article/details/85109782)