CMake: How to determine debug or release mode
## How to determine debug or release mode
## 问题: CMake 中如何根据不同的编译模式来执行相应的操作?
CMake: How to determine debug or release mode
CMakeLists.txt中
- 设定编译模式: 调试模式或发布模式
- 根据不同的编译模式来执行不同的操作
```Cmake
# set(CMAKE_BUILD_TYPE "Debug")
set(CMAKE_BUILD_TYPE "Release")
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
message("Debug mode")
else (CMAKE_BUILD_TYPE STREQUAL "Release")
message("Release mode")
endif()
```
## 编译
```sh
cd build
cmake ..
```
![yubao_blog_cover](https://raw.githubusercontent.com/yubaoliu/assets/image/yubao_blog_cover.png)
No comments