Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake: generate header using custom tool output

Tags:

cmake

I'm porting some obscure library from autotools to cmake.

The library in question compiles custom tool that outputs header into stdout, and this header is used later in the project.

How can I port that to cmake?

I can compile "header generator" using

add_executable(generator generator.c)

But how can I run it and redirect its output to header file using cmake? I'll also need dependency handling of course... (i.e. if generator.c changes, generator must be recompiled and header must be regenerated).

like image 497
SigTerm Avatar asked May 04 '12 07:05

SigTerm


People also ask

How to generate header file in CMake?

To generate the header file we need to create a custom_command which will run the command to generate the header file, when the file it is based on has changed. The following shows how to use the hypothetical generatewordlistheader command to create wordlist. h everytime wordlist. txt changes.

What is CMake generator?

A CMake Generator is responsible for writing the input files for a native build system. Exactly one of the CMake Generators must be selected for a build tree to determine what native build system is to be used.


1 Answers

Found it: "How can I generate a source file during the build?"

like image 175
SigTerm Avatar answered Sep 30 '22 11:09

SigTerm