当前位置:网站首页>Cmake passing related macros to source code
Cmake passing related macros to source code
2022-06-23 01:38:00 【summer_ sunrise】
problem
Sometimes we need to be based on Cmake Different parameters are passed in during compilation , Run our different branches of code , Used to support different scenarios , So how to solve ?
Solutions
1、 How to use Cmake The compile command of passes in parameters ?
cmake Provide The following mechanisms Pass variables :
-D <var>:<type>=<value>, -D <var>=<value>
Create or update a CMake CACHE entry.
When CMake is first run in an empty build tree, it creates a CMakeCache.txt file and populates it with customizable settings for the project. This option may be used to specify a setting that takes priority over the project’s default value. The option may be repeated for as many CACHE entries as desired.
If the : portion is given it must be one of the types specified by the set() command documentation for its CACHE signature. If the : portion is omitted the entry will be created with no type if it does not exist with a type already. If a command in the project sets the type to PATH or FILEPATH then the will be converted to an absolute path.
This option may also be given as a single argument: -D:= or -D=.
2、 If a preprocessing macro is passed to a program ?
cmake Provide the following mechanism :add_compile_definitions
Add preprocessor definitions to the compilation of source files.
add_compile_definitions( …)
Adds preprocessor definitions to the compiler command line.
Example
CmakeLists.txt
if(${TEST} STREQUAL on)
add_compile_definitions(TEST)
endif()
add_executable(cmake_demo main.cpp)
main.cpp
#include <iostream>
int main()
{
#ifdef TEST
std::cout << "TEST marco is define\n";
#else
std::cout << "TEST marco is not define\n";
#endif
return 0;
}
effect :
compile :cmake …/ -DTEST=on && make
function :./cmake_demo
Output :TEST marco is define
compile :cmake … && make
function :./cmake_demo
Output :TEST marco is not define
边栏推荐
- JS - single sign on
- Const defined variables and for of and for in in JS
- Pat class A - 1013 battle over cities
- 07 project cost management
- Template specialization template <>
- Random decoding NLP
- The road of architects starts from "storage selection"
- C language student achievement ranking system
- fatal: refusing to merge unrelated histories
- C#.NET万能数据库访问封装类(ACCESS、SQLServer、Oracle)
猜你喜欢

Detailed explanation of clip attribute parameters

B tree and b+ tree

E-R图

JS - single sign on

Use elk to save syslog, NetFlow logs and audit network interface traffic

A hundred lines of code to realize reliable delay queue based on redis

Sélecteur de hiérarchie
![[launch] redis Series 2: data persistence to improve availability](/img/f4/5bc7ca3e17c6656e71df515182842e.png)
[launch] redis Series 2: data persistence to improve availability
![[hdu] P6964 I love counting](/img/ff/f8e79d28758c9bd3019816c8f46723.png)
[hdu] P6964 I love counting

On AI and its future trend | community essay solicitation
随机推荐
关于打算做一个web的问题看板,需要使用哪些方面语言及数据库知识!
Add expiration time for localstorage
Pat class a 1016 phone bills (time difference)
JS to read the picture of the clipboard
Random decoding NLP
There are animation characters interacting with each other when the mouse slides in the web page
[template] KMP
Xiaobai operates win10 to expand Disk C (allocate disk D memory to Disk C) and the test is valid for many times
ERROR { err: YAMLException: end of the stream or a document separator is expected at line 6, colum
Add / get and delete cookies
Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster
Modulenotfounderror: no module named 'rospy', PIP could not find the installation package
On AI and its future trend | community essay solicitation
人民币的单位的大写
Installing MySQL for Linux
Binary String
[hdu] p2087 cut cloth strip
Data skew analysis of redis slice cluster
Prevent others from using the browser to debug
Detailed explanation of clip attribute parameters