Fypp with Meson

Hi, I was wondering if anyone could share or point me to an example meson.build that uses fypp for preprocessing some of the source files.

1 Like

The original discussion regarding generated Fortran files in meson can be found here:

The summary is that only configure_file, but not the generator can produce Fortran sources that are correctly processed for module dependencies. To use fypp as a preprocessor you have to preprocess in the configure step rather than in the build step with

fypp = find_program('fypp')
foreach src: srcs_fypp
  srcs += configure_file(
    input: src,
    output: '@BASENAME@.f90',
    command: [fypp, '-n', '@INPUT@', '@OUTPUT@'],

The main drawback of preprocessing in the configure step is that meson will reconfigure the build each time a fypp source file is modified.

Hi, you can use the generator function in Meson. For example,

fypp = find_program('fypp')
fypp_flag = '-DVAR=your_extra_fypp_flag'
gen_f90_file = generator(
    fypp, output: '@BASENAME@.f90',
    arguments: ['@INPUT@', '@EXTRA_ARGS@', '@OUTPUT@']

and generate .f90 file through

fypp_src = gen_f90_file.process(
    extra_flags: fypp_flag

Thanks @awvwgk for the summary of that issue thread. I had seen it but wasn’t sure if things had changed since then.

I want the dep scanning to work properly and do not want to have to reconfigure every time a fypp source file is modified since part of my compilation takes several minutes. I guess I can keep Meson ignorant of fypp and run fypp before building to avoid this. Or would you recommend another approach?

Edit: the files that take long to compile I am not modifying and they don’t need fypp

Thanks @han190 for the generator example.

Reaching out to upstream meson and trying to implement a general custom preprocessing model is always an option here and would actually be a serious step forward, because no other high-level build system has such support as far as I know.

Generally, supporting fypp is quite painful with high-level build systems. Even with CMake where you can perform the custom preprocessing at build time, you will always trigger a complete rebuild of all files for a reconfiguration step (change of any CMakeLists.txt or similar). I don’t really want to suggest CMake over meson here, but using fypp is one of the few things that is easier (but not perfect) in CMake than in meson.

Almost feels like preprocessing is ignored in build systems like it is ignored in the Fortran standard :wink:.