CMake生成config.h喜欢从Autoconf [英] CMake generate config.h like from Autoconf

查看:2112
本文介绍了CMake生成config.h喜欢从Autoconf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Autotools时,通常在宏中指定 AC_CONFIG_HEADERS 宏,生成 config.h c $ c> configure.ac 像这样:

When using the Autotools it's common to generate a config.h file by specifying the AC_CONFIG_HEADERS macro in configure.ac like this:

AC_CONFIG_HEADERS([config.h])

当使用CMake时,它的相应等价物是什么?

What is the respective equivalent for this when using CMake?

推荐答案

您必须创建一个类似 config.h.in 的文件。像

You have to create a file similar to config.h.in. Something like

#cmakedefine HAVE_FEATURE_A @Feature_A_FOUND@
#cmakedefine HAVE_FEATURE_B @Feature_B_FOUND@
#cmakedefine HAVE_FEATURE_BITS @B_BITSIZE@

然后您必须声明变量 Feature_A_FOUND Feature_B_FOUND B_BITSIZE 并调用

Then you have to declare the variables Feature_A_FOUND, Feature_B_FOUND, B_BITSIZE in your CMake code and call

configure_file(config.h.in config.h)

这将导致一个config.h文件类似于来自autotools的文件。如果未找到变量或将其设置为false,则该行将被注释。否则将插入该值。假设 Feature_A_FOUND = A-NOTFOUND ¸ Feature_B_FOUND = / usr / lib / b B_BITSIZE = 64 ,这将导致

which will result in a config.h file similar to the one from the autotools. If a variable is not found or is set to false, the line will be commented. Otherwise the value will be inserted. Assume Feature_A_FOUND=A-NOTFOUND¸ Feature_B_FOUND=/usr/lib/b, B_BITSIZE=64, which will result in

/* #undef HAVE_FEATURE_A @Feature_A_FOUND@ */
#define HAVE_FEATURE_B /usr/lib/b
#define HAVE_FEATURE_BITS 64

可能HAVE_FEATURE_B更好地定义为#cmakedefine01 ,根据变量的值,结果为0或1.

Probably HAVE_FEATURE_B would be better defined as #cmakedefine01 which results in 0 or 1 depending on the value of the variable.

可以创建由Autotools生成的每个config.h文件,因为CMake更灵活。但它需要更多的工作,你不能自动获得一个config.h,但你必须自己写.in文件。

In general it is possible to create every config.h file generated by Autotools as CMake is more flexible. But it requires more work and you cannot automatically get a config.h, but you have to write the .in file yourself.

文档:
https://cmake.org/cmake/help/v3.6/command/configure_file。 html

这篇关于CMake生成config.h喜欢从Autoconf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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