CMake 可以生成配置文件吗? [英] Can CMake generate a configure file?

查看:55
本文介绍了CMake 可以生成配置文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将配置文件从 C++ 转换为 JS,我正在尝试在项目中使用 emscripten.Emscripten 自带一个叫做 emconfigure 的工具,它取代了 autoconf 配置,

I need the configure file to transpile from C++ to JS, I'm trying to use emscripten in a project. Emscripten comes with a tool called emconfigure, that replaces the autoconf configure,

但是我正在构建的项目使用 cmake 作为构建系统,目前(1 月 12 日)emscripten 仅支持 autoconf - 所以我通过生成配置并在 make 上做一个端口来绕过它,所以有一个从 cmake 创建配置文件的方法?我不是在谈论 make 文件……而是在谈论配置文件本身.

But the project I'm building uses cmake as build system and currently (Jan-12) emscripten has only support for autoconf - so I'm bypassing it by generating the configure and doing a port on the make, so there a way to create the configure file from the cmake ?? I'm not talking about the make files.. but the configure file itself.

推荐答案

是的,它可以:

configure_file(<input> <output>
               [COPYONLY] [ESCAPE_QUOTES] [@ONLY]
               [NEWLINE_STYLE [UNIX|DOS|WIN32|LF|CRLF] ])

示例.h.in

#ifndef EXAMPLE_H
#define EXAMPLE_H

/*
 * These values are automatically set according to their cmake variables.
 */
#define EXAMPLE "${EXAMPLE}"
#define VERSION "${VERSION}"
#define NUMBER  ${NUMBER}

#endif /* EXAMPLE_H */

在您的 cmake 文件中:

set(EXAMPLE "This is an example")
set(VERSION "1.0")
set(NUMBER 3)

configure_file(Example.h.in Example.h)

配置的Example.h:

#ifndef EXAMPLE_H
#define EXAMPLE_H

/*
 * These values are automatically set according to their cmake variables.
 */
#define EXAMPLE "This is an example"
#define VERSION "1.0"
#define NUMBER  3

#endif /* EXAMPLE_H */

文档:

这篇关于CMake 可以生成配置文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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