当前位置:网站首页>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
边栏推荐
- FPGA - 7系列 FPGA SelectIO -09- 高级逻辑资源之IO_FIFO
- ROS rviz_satellite功能包可视化GNSS轨迹,卫星地图的使用
- Freeswitch uses Mod_ Shot module plays mp3
- Iframe switching in Web Automation
- Build your jmeter+jenkins+ant
- 【星海出品】 运维巡检合集
- Is it safe to open a stock account? How to open a stock account?
- 移动广告发展动向:撬动存量,精细营销
- AutoCAD C# 多段線小銳角檢測
- Select trigger event from easyUI drop-down box
猜你喜欢

FPGA - 7 Series FPGA selectio -08- oserdese2 of advanced logic resources

FPGA - 7系列 FPGA SelectIO -07- 高级逻辑资源之ISERDESE2

AutoCAD C# 多段线小锐角检测

选拔赛题目代码

Online facing such an online world, the only limitation is our imagination

eyebeam高级设置

Freeswitch uses Mod_ Shot module plays mp3

fpm工具安装

移动广告发展动向:撬动存量,精细营销

freeswitch使用mod_shout模块播放mp3
随机推荐
Working principle of es9023 audio decoding chip
代码没写错,渲染页面不显示原因
语音增强-频谱映射
Introduction to openscap
小程序页面设置100%高度还是留白怎么办?
Tryout title code
Caused by: com. fasterxml. jackson. databind. exc.InvalidDefinitionException: Cannot construct instance
【网络教程】IPtables官方教程--学习笔记1
CAD secondary development +nettopologysuite+pgis reference multi version DLL
MySQL (I) - Installation
MySQL(一)——安装
@The reason why the Autowired annotation is empty
Floating and positioning
Speech enhancement - spectrum mapping
socke.io长连接实现推送、版本控制、实时活跃用户量统计
Xcode13.3.1 error reported after pod install
搭建你jmeter+jenkins+ant
UPC -- expression evaluation
socke. IO long connection enables push, version control, and real-time active user statistics
Caused by: com. fasterxml. jackson. databind. Exc.invalidformatexception: exception resolution