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

Schuchard, Matthew Matthew.Schuchard at gtri.gatech.edu
Wed Nov 2 15:27:30 EDT 2011


Hi, I have three questions about CMake's use of a C Preprocessor for Fortran Source Files.  I have scoured the CMake help documentation and googled extensively but have not found any solutions that worked for my specific situations.

1. What is the default C Preprocessor CMake uses for Fortran files?

I have looked through the CMakeCache.txt generated from the top level build directory for the location of the C Preprocessor.  Normally I use a C Preprocessor located at /lib/cpp to preprocess Fortran files.  I was wondering if CMake has some built in preprocessor or will it search for a preprocessor, in a similar manner to finding gcc on the system if its location is unspecified.  These Fortran files in question have no actual C/C++ code in them, just preprocessor and #include statements, so I only specify "Fortran" in my project name.  It must be using some C preprocessor though because my Fortran files are being preprocessed mostly correctly.

2. How do I retain C preprocessed Fortran source files while building?

I noticed that the easy solution to retaining C preprocessed C source files, as provided in two locations I googled, is to perform a "make foo.i" which is revealed with a "make help" in the build directory to provide potential targets.  When I perform a "make help," the only source file specific targets provided are the .o targets.  I have also noticed a specific CMake function prototype written in 2009 which would run a specified FPP executable (in my case /lib/gcc) and output preprocessed files to be built, but it did not seem to succeed in my implementation (http://www.cmake.org/pipermail/cmake/2009-November/033359.html).

3. How do I provide arguments to the C preprocessor?

Specifically, I need to give it the "-P -traditional" arguments when it preprocesses my Fortran files.  Otherwise, comments with line numbers are retained in my source files which my compiler (ABSoft 95 11.1) will fail on.  I could not find anything in the CMake documentation on how to do this, and my best guess is that it would be a similar implementation as http://www.cmake.org/pipermail/cmake/2010-July/038312.html, which I did successfully implement to provide flags for my RANLIB and AR library builders.  I have also tried a add_custom_command similar to http://www.cmake.org/pipermail/cmake/2009-June/029909.html but with /lib/cpp instead of m4.

If it matters, these source files will always be built on Linux, so that allows for some flexibility in solutions.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20111102/a20eee40/attachment.htm>


More information about the CMake mailing list