CMake可以生成配置文件吗?

can*_*sin 12 c++ build autotools configure cmake

我需要配置文件从C++转换为JS,我试图在项目中使用emscripten.Emscripte附带了一个名为emconfigure的工具,它取代了autoconf配置,

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

oll*_*llo 24

是的,它可以:

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

Example.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 */
Run Code Online (Sandbox Code Playgroud)

在您的cmake文件中:

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

configure_file(Example.h.in Example.h)
Run Code Online (Sandbox Code Playgroud)

配置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 */
Run Code Online (Sandbox Code Playgroud)

文档: