[CMake] CMake Using a C Preprocessor for Fortran Source Files

Alan W. Irwin irwin at beluga.phys.uvic.ca
Wed Nov 2 16:38:09 EDT 2011


On 2011-11-02 19:27-0000 Schuchard, Matthew wrote:

> If it matters, these source files will always be built on Linux, so that allows for some flexibility in solutions.

For that case, I find fortran preprocessing for gfortran works correctly if I do
the following:

set_source_files_properties(fortran_source.f PROPERTIES COMPILE_FLAGS -cpp)

This solution was based on documentation from "info gfortran" which
states the following:

"Many Fortran compilers including GNU Fortran allow passing the source
code through a C preprocessor (CPP; sometimes also called the Fortran
preprocessor, FPP) to allow for conditional compilation. In the case of
GNU Fortran, this is the GNU C Preprocessor in the traditional mode. On
systems with case-preserving file names, the preprocessor is
automatically invoked if the filename extension is .F', .FOR',
.FTN', .fpp', .FPP', .F90', .F95', .F03' or .F08'. To manually
invoke the preprocessor on any file, use -cpp', to disable
preprocessing on files where the preprocessor is run automatically, use
-nocpp'."

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state
implementation for stellar interiors (freeeos.sf.net); the Time
Ephemerides project (timeephem.sf.net); PLplot scientific plotting
software package (plplot.sf.net); the libLASi project
(unifont.org/lasi); the Loads of Linux Links project (loll.sf.net);
and the Linux Brochure Project (lbproject.sf.net).
__________________________

Linux-powered Science
__________________________


More information about the CMake mailing list