19

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,

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.

einpoklum
  • 118,144
  • 57
  • 340
  • 684
canesin
  • 1,967
  • 2
  • 18
  • 30
  • By the way you want to translate the language. Can you be more specific? – Neox Jan 16 '12 at 23:29
  • 1
    This question is unclear. CMake cannot generate a script called configure in the way that autoconf does - it works differently to do a similar job. But it can do configuration operations upon files in the source tree. What language translation is being done? What has emscripte got to do with anything? – mabraham Dec 22 '14 at 17:51

4 Answers4

33

Yes, it can:

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

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 */

In your cmake file:

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

configure_file(Example.h.in Example.h)

Configured 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 */

Documentation:

salehjg
  • 49
  • 1
  • 9
ollo
  • 24,797
  • 14
  • 106
  • 155
  • CMake will undef if the variable evaluates to false. e.g. if the number is 0, it wont define it. Is there anyway to fix that? I'm just using ifndef to resolve it. – miguel.martin Feb 18 '16 at 07:42
  • 1
    Are you using `#cmakedefine` or plain `#define`? The latter shouldn't do this. If it doesn't work either, you can add a `#ifnedf ... #define ...` into the template file. – ollo Mar 06 '16 at 17:51
  • Very helpful². Thanks! – karliwson Oct 14 '16 at 03:22
  • I know this is an older post, but just as an addition, it may be worth noting that in the above example, Example.h will be generated in the binary build directory, not the same directory as where Example.h.in was located. So, ${CMAKE_CURRENT_SOURCE_DIR}/Example.h could be used to put the generated file back where the input template file was found. – Ashley Duncan Jun 15 '22 at 05:12
0

yes cmake generates you the files you need to build the project depending on your target platform. however you need to write the CMakelist.txt's files for CMake by yourself or you have to get them from someone else. if emscripten has them and you have cmake installed, go to the root of your cource directory and launch cmake to see a list of arguments you can use

stefan
  • 1
0

In fact, do not generate a "set", but you can use functions that do everything he does, as is the case of vereficação data types, vereficar headers and more.

Well, I'll go down a link to my project that contains all those functions. I suggest that a study of it, anything send me an email or something to take your questions.

Here

Check too the /deps/cmake folder to view the functions created by us.

0xC0000022L
  • 20,597
  • 9
  • 86
  • 152
Bruno Alano
  • 643
  • 1
  • 11
  • 21
-13

Cmake is a build system. It generates Makefiles. Look here for more information on that. But to answer your question briefly no, you cannot generate configure files with cmake.

Neox
  • 2,000
  • 13
  • 12