当前位置:网站首页>CMakeLists中的add_definitions()函数
CMakeLists中的add_definitions()函数
2022-06-24 23:43:00 【惊鸿一博】
引言
其实这个函数在安装一些库的时候,它的CMakeLists里面就有这样的函数。典型的就是opencv了。
opencv安装时候有一些指令也是针对这个函数的,比如安装命令(随便搜索的):
cmake ../opencv-3.4.1 -DWITH_GTK_2_X=ON -DCMAKE_INSTALL_PREFIX=/usr/local \
-DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/usr/local -DWITH_TBB=ON\
-DBUILD_NEW_PYTHON_SUPPORT=ON -DWITH_V4L=ON -DINSTALL_C_EXAMPLES=ON \
-DINSTALL_PYTHON_EXAMPLES=ON -DBUILD_EXAMPLES=ON -DWITH_OPENGL=ON \
-DENABLE_FAST_MATH=1 -DCUDA_FAST_MATH=1 -DWITH_CUBLAS=1 -DWITH_OPENMP=ON
其中-D后面的参数就是控制程序流向。
1.add_definitions()
官方解释. add_definitions — CMake 3.0.2 Documentation
2.应用
这种可以在我们更改别人代码做实验时使用,既不对其源码进行破坏,又可以添加自己的功能。之前都是在程序中进行#define,有了这个后可以直接在编译的时候进行选择。具体的,在工程CMakeLists.txt 中,使用add_definitions()函数控制代码的开启和关闭:
option(TEST_DEBUG "option for debug" OFF)
if (TEST_DEBUG)
add_definitions(-DTEST_DEBUG)
endif(TEST_DEBUG)
运行构建项目的时候可以添加参数控制宏的开启和关闭.
cmake -DTEST_DEBUG=1 .. #打开
cmake -DTEST_DEBUG=0 .. #关闭
在源码中就可以使用:
#ifdef TEST_DEBUG
...
...
#else
...
#endif
边栏推荐
- Charles 抓包工具
- left join on和 join on的区别
- LINQ query (3)
- 目录权限错误导致 Oracle 11g rac 集群数据库无法启动的问题
- 3年测试经验,连简历上真正需要什么都没搞明白,张口就要20k?
- PE文件基础结构梳理
- Software testing weekly (issue 77): giving up once will breed the habit of giving up, and the problems that could have been solved will become insoluble.
- yarn : 无法加载文件 C:\Users\xxx\AppData\Roaming\npm\yarn.ps1,因为在此系统上禁止运行脚本
- 请问polarDB数据库可以通过mysql进行数据源连接吗
- Is it out of reach to enter Ali as a tester? Here may be the answer you want
猜你喜欢

Distributed transaction solutions and code implementation

How transformers Roberta adds tokens

Test / development programmers, 30, do you feel confused? And where to go

Rod and Schwartz cooperated with ZhongGuanCun pan Lianyuan Institute to carry out 6G technology research and early verification

软件测试周刊(第77期):只要放弃一次,就会滋生放弃的习性, 原本可以解决的问题也会变得无法解决。

Leecode learning notes - the shortest path for a robot to reach its destination

折叠屏将成国产手机分食苹果市场的重要武器

left join on和 join on的区别

Advanced mathematics | proficient in mean value theorem problem solving routines summary

random list随机生成不重复数
随机推荐
vie的刷新机制
目录权限错误导致 Oracle 11g rac 集群数据库无法启动的问题
ACL access control of squid proxy server
Jetson nano from introduction to practice (cases: opencv configuration, face detection, QR code detection)
AI服装生成,帮你完成服装设计的最后一步
Is it out of reach to enter Ali as a tester? Here may be the answer you want
AOSP ~ WIFI架构总览
保险也能拼购?个人可以凑够人数组团购买医疗保险的4大风险
Uncaught Error: [About] is not a <Route> component. All component children of <Routes> must be a <Ro
Yarn: unable to load file c:\users\xxx\appdata\roaming\npm\yarn PS1 because running scripts is prohibited on this system
UnityShader入门精要——表面着色器
记一次beego通过go get命令后找不到bee.exe的坑
Processon producer process (customized)
F - spices (linear basis)
Advanced mathematics | proficient in mean value theorem problem solving routines summary
Lihongyi, machine learning 6 Convolutional neural network
ProcessOn制作ER过程(自定义)
ida中交叉引用的解析
PyTorch学习笔记(七)------------------ Vision Transformer
LINQ query (3)