CMake 可以生成配置文件吗?

2021-12-26 00:00:00 build cmake c++ configure autotools

我需要将配置文件从 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 3.0
  • CMake 2.8.12

相关文章