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

Unity packaging webgl uses IIS to solve the error

报错--解决core-js/modules/es.error.cause.js报错

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

AutoCAD C# 多段线小锐角检测

FPM tool installation

Linux Mysql 实现root用户不用密码登录

MySQL (I) - Installation

CAD secondary development +nettopologysuite+pgis reference multi version DLL

Yygh-6-wechat login

Slow content advertising: the long-term principle of brand growth
随机推荐
【Paper Reading-3D Detection】Fully Convolutional One-Stage 3D Object Detection on LiDAR Range Images
Object object to list collection
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
FPGA - 7系列 FPGA SelectIO -08- 高级逻辑资源之OSERDESE2
Lombok @equalsandhashcode annotation how to make objects The equals () method compares only some attributes
fpm工具安装
AutoCAD C # Polyline Small Sharp angle Detection
CAD二次开发+NetTopologySuite+PGIS 引用多版本DLL问题
Parsing ng template with let total in NZ Pagination
代码没写错,渲染页面不显示原因
Error reporting - resolve core JS / modules / es error. cause. JS error
How to open UMD, KMD log and dump diagrams in CAMX architecture
socke.io长连接实现推送、版本控制、实时活跃用户量统计
Deleting MySQL under Linux
Create a gson object that formats the time zone. JSON parsing time formatting zoneddatetime
Uni app wechat applet sharing function
High quality domestic stereo codec cjc8988, pin to pin replaces wm8988
Install redis on windows and permanently change the password, and integrate redis with the SSM framework
Socket. Io long Connection Push, version Control, Real - Time Active user volume Statistics
选拔赛题目代码