当前位置:网站首页>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
边栏推荐
猜你喜欢

ROS rviz_satellite功能包可视化GNSS轨迹,卫星地图的使用

mac下安装多个版本php并且进行管理

慢内容广告:品牌增长的长线主义

Introduction to browser tools: think sky browser, team work browser

Boost the rising point | yolov5 combined with alpha IOU

AutoCAD C# 多段线自相交检测

eyebeam高级设置

Integer promotion and size side byte order

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

ROS rviz_ Satellite function package visualizes GNSS track and uses satellite map
随机推荐
阿里云短信服务(完整指南),短信发送功能实现。
4~20ma input /0~5v output i/v conversion circuit
Failed to start component [StandardEngine[Catalina]. StandardHost[localhost]]
Select trigger event from easyUI drop-down box
语音增强-频谱映射
Configure multiple database connections using the SSM framework
ROS rviz_ Satellite function package visualizes GNSS track and uses satellite map
Difficulty calculation of Ethereum classic
ImportError: cannot import name 'ensure_ dir_ Possible solutions for exists'
Shell script one click deployment (MySQL)
不会还有人只会用forEach遍历数组吧?
链表(三)——反转链表
Socket. Io long Connection Push, version Control, Real - Time Active user volume Statistics
慢内容广告:品牌增长的长线主义
Idea automatically adds comments when creating classes
搭建你jmeter+jenkins+ant
Scripting and programming languages
eyebeam高级设置
No one can only use foreach to traverse arrays, right?
创建格式化时间,格式化时区的gson对象。json解析时间格式化 ZonedDateTime