如何添加在cmake的宏的定义是什么? [英] How to add macro's definition in cmake?

查看:4587
本文介绍了如何添加在cmake的宏的定义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用MongoDB的客户端,并在我的C ++应用程序提升。因为MongoDB的客户端仍在使用Boost旧文件系统和我的C ++应用程序正在使用的文件系统版本3从升压1.47.0,他们发生冲突。

I am using Mongodb client and Boost in my C++ application. Because the Mongodb client is still using Boost old filesystem and my C++ application is using filesystem version 3 from boost 1.47.0, they conflict.

我找到了一种方法来解决这个问题汇编,即增加一个宏定义之前的所有包括与Boost头文件的语句在我的cpp文件:

I found a way to solve this compilation problem, namely add a macro definition before all include statements for the header files from Boost in my cpp files:

#define BOOST_FILESYSTEM_VERSION 2

但我想知道如何把上面的宏的定义放在我的CMake的项目文件。

But I want to know how to put the above macro's definition into my CMake project files.

推荐答案

在看看<一个href=\"http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command%3aadd_definitions\">add_definitions,这将您的定义添加到您的编译器命令行,如 -D 用gcc,或 / D 用MSVC。尝试是这样的:

Take a look at add_definitions, which will add your definitions to your compiler command line, e.g. -D with gcc, or /D with MSVC. Try something like:

add_definitions( -DBOOST_FILESYSTEM_VERSION=2 )

在你的情况,我肯定会使用 add_definition 方法去,但另一种可能看一看在<一个href=\"http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command%3aconfigure_file\">configure_file.然后您可以创建一个头文件模板,将充满cmake的值,包括这在你的源文件。如果你有很多很多的配置参数这是由CMake的决定,这非常有用。

In your case, I would definitely go with the add_definition method, but an alternative may to take a look at configure_file. Then you can create a header-file template, which will be filled with cmake-values and include this in your source files. This can be useful if you have many, many configurable parameters which are determined by CMake.

这篇关于如何添加在cmake的宏的定义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆