当前位置:网站首页>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
边栏推荐
- Migrate Oracle database from windows system to Linux Oracle RAC cluster environment (4) -- modify the scanip of Oracle11g RAC cluster
- leecode学习笔记-机器人走到终点的最短路径
- 一线城市软件测试工资——你拖后腿了吗
- 【STL源码剖析】配置器(待补充)
- Getting started with unityshader - Surface Shader
- 怎么开户打新债 开户是安全的吗
- Sumati gamefi ecological overview, element design in the magical world
- Once beego failed to find bee after passing the go get command Exe's pit
- PSQL column to row
- Migrate Oracle database from windows system to Linux Oracle RAC cluster environment (3) -- set the database to archive mode
猜你喜欢

qt打包exe文件,解决“无法定位程序输入点_ZdaPvj于动态链接库Qt5Cored.dll”

Are programmers from Huawei, Alibaba and other large manufacturers really easy to find?

Can automate - 10k, can automate - 20K, do you understand automated testing?

Leetcode 210: curriculum II (topological sorting)

jwt

记一次beego通过go get命令后找不到bee.exe的坑

Lizuofan, co-founder of nonconvex: Taking quantification as his lifelong career

Lihongyi, machine learning 6 Convolutional neural network

How transformers Roberta adds tokens

Is it out of reach to enter Ali as a tester? Here may be the answer you want
随机推荐
Post competition summary of kaggle patent matching competition
Intranet learning notes (6)
DSPACE的性能渲染问题
Charles packet capturing tool
AOSP ~ default attribute value
ACM. HJ75 公共子串计算 ●●
Centos7.3 modifying MySQL default password_ Explain centos7 modifying the password of the specified user in MySQL
Transformers Roberta如何添加tokens
[day 26] given the ascending array nums of n elements, find a function to find the subscript of target in nums | learn binary search
vim的Dirvish中文文档
Uncaught Error: [About] is not a <Route> component. All component children of <Routes> must be a <Ro
I've been doing software testing for two years. I'd like to give some advice to girls who are still hesitating
分布式事务解决方案和代码落地
Folding screen will become an important weapon for domestic mobile phones to share the apple market
UnityShader入门精要——表面着色器
Sumati gamefi ecological overview, element design in the magical world
Leecode learning notes - the shortest path for a robot to reach its destination
npm包发布详细教程
高数 | 精通中值定理 解题套路汇总
Practice and Thinking on process memory