Skip to content

Fortran: Add Fortran_PREPROCESS property

Peter Hill requested to merge ZedThree/cmake:feature/fortran-preprocess into master

Add a Fortran_PREPROCESS target/source file property as described in #18870 (closed) to control whether or not Fortran files should always/never be preprocessed.

As this is my first dive into the CMake source, I essentially just copy-pasted the code to handle Fortran_FORMAT.

EDIT: Design questions posted in original description have been moved to #18870 (comment 742515).

Original Description Design Questions

Some issues:

  1. Some compilers (NAG, PGI and SunPro) don't have an option to never preprocess files. Two problems with this:
    • If the target property is set to ALWAYS and then a particular source file is set to NEVER, what should be done? Does CMake just ignore the target property in favour of the source file property? In which case, I guess this isn't a problem.
    • If the source file extension is uppercase, most compilers will preprocess it, and for these compilers not doing that won't be possible. One possible fix would be to make a copy of the file with a lowercase extension and compile that.
  2. No compilers except HP have an explicit option to use the default preprocessing behaviour. That is, aside from HP, it is not possible to select a native BY_EXTENSION flag. This could be handled internally by CMake, by checking the file extension and assuming that uppercase means ALWAYS and lowercase means NEVER, but this could cause issues on case insensitive filesystems.
  3. I've not touched the files cmGlobalXCodeGenerator.cxx or cmLocalVisualStudio7Generator.cxx as I wasn't sure exactly what compiler these are supposed to target.
  4. Default behaviour from CMake is unchanged. It was suggested by @ben.boeckel in #18870 (closed) that the default should be ALWAYS. Where best to set this? My first thought would be in cmOutputConverter::GetFortranPreprocess to return FortranPreprocessAlways by default

Fixes: #18870 (closed)
Topic-rename: fortran-preprocess-property

Edited by Brad King

Merge request reports