ecmwf / fckit

A Fortran toolkit for interoperating Fortran with C/C++
https://confluence.ecmwf.int/display/fckit
Apache License 2.0
29 stars 15 forks source link

Add possibility to exclude defines that would be passed to fypp #23

Closed wdeconinck closed 1 year ago

wdeconinck commented 1 year ago

The CMake function fckit_target_preprocess_fypp automatically adds all definitions to fypp for preprocessing. One issue reported by Ioan was encountered with the valid definition -D_POSIX_C_SOURCE=200809L:

error: exception at evaluating '200809L' in definition for '_POSIX_C_SOURCE' [FyppFatalError]
error: unexpected EOF while parsing (<string>, line 1) [SyntaxError]

Internal to fypp (in Python) there occurs a eval('200809L') which triggers a Python exception as follows:

>>> eval('200809L')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 1
    200809L
          ^SyntaxError: invalid decimal 

and this causes the fypp preprocessing to fail. To work around we introduce two mechanisms to remove this definition from being passed to the fypp preprocessor: 1) An extra argument FYPP_ARGS_EXCLUDE arg1 [arg2]... to the fckit_target_preprocess_fypp function 2) A general FCKIT_FYPP_ARGS_EXCLUDE list which can be added to e.g. a toolchain or CMake command-line.

The arguments or list elements described can be regular expressions as understood by bash and shall not contain a comma. By default we already add the regex -D[[:space:]]?.*=([0-9])+L which captures the -D_POSIX_C_SOURCE=200809L argument reported in this issue.