How it works

The command configure_file can copy files and replace their contents with variable values. In our example, we used configure_file to both modify the contents of our template file and copy it to a location where it could then be compiled into our executable. Let us look at our invocation of configure_file:

configure_file(print_info.c.in print_info.c @ONLY)

The first argument is the name of the scaffold: print_info.c.in. CMake assumes that the input file is located relative to the root directory of the project; that is, in ${CMAKE_CURRENT_SOURCE_DIR}/print_info.c.in. The second argument is the name of the configured file, which we chose to be print_info.c. The output file is assumed to be located relative to the project build directory; ...

Get CMake Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.