当前位置:网站首页>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
边栏推荐
- Example of MVVM framework based on kotlin+jetpack
- 选拔赛题目代码
- 语音增强-频谱映射
- 4. use MySQL shell to install and deploy Mgr clusters | explain Mgr in simple terms
- Configure redis from 0
- Some habits of it veterans in the workplace
- Students who do not understand the code can also send their own token. The current universal dividend model can be divided into BSC and any generation B
- 报错--解决core-js/modules/es.error.cause.js报错
- Paper recommendation: efficientnetv2 - get smaller models and faster training speed through NAS, scaling and fused mbconv
- OpenGL API learning (2008) client server client server
猜你喜欢
Promotion intégrale et ordre des octets de fin de taille
Some habits of it veterans in the workplace
慢内容广告:品牌增长的长线主义
整型提升和大小端字节序
代码没写错,渲染页面不显示原因
death_ satan/hyperf-validate
移动广告发展动向:撬动存量,精细营销
链表(三)——反转链表
High quality domestic stereo codec cjc8988, pin to pin replaces wm8988
How to open UMD, KMD log and dump diagrams in CAMX architecture
随机推荐
4~20ma input /0~5v output i/v conversion circuit
Exception handling (I) -- null pointer and array index out of bounds
Tryout title code
Lombok @equalsandhashcode annotation how to make objects The equals () method compares only some attributes
微信小程序编译页面空白bug的原因
三极管驱动无刷电机
重载,重写的区别,抽象类,接口的区别
KMP string
Some habits of it veterans in the workplace
lombok @EqualsAndHashCode 注解如何让对象.equals()方法只比较部分属性
浮动与定位
Freeswitch uses Mod_ Shot module plays mp3
SQL and list de duplication
ThreadLocal
AttributeError: 'callable_iterator' object has no attribute 'next'
Linux MySQL implements root user login without password
@The reason why the Autowired annotation is empty
AutoCAD C polyline small acute angle detection
UPC -- expression evaluation
socke. IO long connection enables push, version control, and real-time active user statistics