Getting ready

The files print_info.c.in and example.f90 are unchanged with respect to the previous recipe. In addition, we will use a Python script, configurator.py, which provides one function:

def configure_file(input_file, output_file, vars_dict):    with input_file.open('r') as f:        template = f.read()    for var in vars_dict:        template = template.replace('@' + var + '@', vars_dict[var])    with output_file.open('w') as f:        f.write(template)

This function reads an input file, goes over all of the keys of a vars_dict dictionary, replaces the pattern @key@ with its corresponding value, and writes the results to an output file. The key-value pairs will be provided by CMake.

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.