当前位置:网站首页>CMAKE小知识
CMAKE小知识
2022-06-28 06:30:00 【panamera12】
1、cmake给CMakeLists.txt传递参数
命令行cmake -DTARGET_CPU:STRING=x86
然后,我们就可以在CMakeLists.txt中使用他帮助我们实现一些逻辑:
if(TARGET_CPU STREQUAL "x86")
#do something
else()
#do something
endif()
2、shell给CMakeLists.txt传递参数
a.sh
export TYPES_RELEASE_A20="A20"
export PROJECT_BUILD_TYPE=$1
CMakeLists.txt
if($ENV{PROJECT_BUILD_TYPE} STREQUAL $ENV{TYPES_DEBUG_X86} OR $ENV{PROJECT_BUILD_TYPE} STREQUAL $ENV{TYPES_DEBUG_NDK28})
add_definitions(-DAAA_HOST_BBB)
endif()
3、add_definitions的用法
add_definitions的功能和C/C++中的#define是一样的
比如我有如下两个文件,一个源文件main.cpp,一个CMakeLists.txt
源文件main.cpp
#include <iostream>
int main()
{
#ifdef TEST_IT_CMAKE
std::cout<<"in ifdef"<<std::endl;
#endif
std::cout<<"not in ifdef"<<std::endl;
}
cmake文件CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(optiontest)
add_executable(optiontest main.cpp)
option(TEST_IT_CMAKE "test" ON)
message(${TEST_IT_CMAKE})
if(TEST_IT_CMAKE)
message("itis" ${TEST_IT_CMAKE})
add_definitions(-DTEST_IT_CMAKE)
endif()
通过option设置一个变量,并通过add_definitions将其转换为#define TEST_IT_CMAKE
当变量为ON时,该程序的输出是
in ifdef
not in ifdef
当变量为OFF时,该程序的输出是
not in ifdef
边栏推荐
- Deleting MySQL under Linux
- Yolact++ Pytorch环境
- 4~20ma input /0~5v output i/v conversion circuit
- AttributeError: 'callable_ iterator' object has no attribute 'next'
- Slow content advertising: the long-term principle of brand growth
- easyui 重置多条件查询
- Idea generates entity classes from database tables
- CAD secondary development +nettopologysuite+pgis reference multi version DLL
- YYGH-BUG-02
- Idea automatically adds comments when creating classes
猜你喜欢

【Paper Reading-3D Detection】Fully Convolutional One-Stage 3D Object Detection on LiDAR Range Images

AutoCAD C# 多段线自相交检测

fpm工具安装

自定义 cube-ui 弹出框dialog支持多个且多种类型的input框

Unity packaging webgl uses IIS to solve the error

Tryout title code

Integer promotion and size side byte order

三极管驱动无刷电机

socke.io长连接实现推送、版本控制、实时活跃用户量统计

Eyebeam advanced settings
随机推荐
death_ satan/hyperf-validate
Object object to list collection
UPC -- expression evaluation
YYGH-BUG-02
AutoCAD C polyline self intersection detection
ROS rviz_satellite功能包可视化GNSS轨迹,卫星地图的使用
No one can only use foreach to traverse arrays, right?
eyebeam高级设置
Alibaba cloud SMS service (Complete Guide), SMS sending function implementation.
Linked list (I) - remove linked list elements
Online facing such an online world, the only limitation is our imagination
JDBC学习(一)——实现简单的CRUD操作
Freeswitch sets the maximum call duration
Example of MVVM framework based on kotlin+jetpack
微信小程序编译页面空白bug的原因
@The reason why the Autowired annotation is empty
Camx架构开UMD、KMD log以及dump图的方式
Is it safe to open a stock account? How to open a stock account?
MySQL common functions
阿里云短信服务(完整指南),短信发送功能实现。