[CMake] IBM Fortran and the C Preprocessor

Will Dicharry wdicharry at stellarscience.com
Wed Jun 24 10:15:08 EDT 2009


Brad King wrote:
> Will Dicharry wrote:
>> It appears that add_definitions() places -DWHATEVER in the compile 
>> command line on all Unix variants.  Unfortunately, IBM's Fortran 
>> compiler uses -D as a compile flag for something other than adding a 
>> preprocessor definition.  In order to pass a preprocessor definition, 
>> you have to use -WF,-DWHATEVER.
> 
> What version of CMake are you using?  This should work in 2.6.4 (and
> perhaps earlier 2.6.x but I don't remember).  There is a platform
> configuration variable called "CMAKE_Fortran_DEFINE_FLAG" which is
> set to "-WF,-D" for that compiler.
> 
> Add this to your project to see how the platform is set:
> 
> message("CMAKE_Fortran_DEFINE_FLAG=${CMAKE_Fortran_DEFINE_FLAG}")
> message("CMAKE_Fortran_COMPILER_ID=${CMAKE_Fortran_COMPILER_ID}")

It turns out this is a little stranger than I originally thought.  We
use a toolchain file to specify the compiler for the system we're on.
The toolchain file looks like this (the project is actually mixed
C/Fortran code so there's some C/C++ stuff in the actual toolchain file, 
but this simple toolchain with a simple Fortran exe reproduces the problem):

set( CMAKE_SYSTEM_NAME AIX )

set( CMAKE_Fortran_COMPILER mpxlf90 )

set( CMAKE_Fortran_FLAGS "-qfixed=72" CACHE STRING "" )

We do this because we need a quick way to choose our compiler (cmake
chooses GNU on this system by default, and we have to use an MPI wrapper 
compiler) and because we want those particular Fortran flags when the 
MPI wrapper compiler is being used.
When I use this toolchain file, the Fortran compiler ID is unknown (I 
failed to see this before, the C and CXX compiler IDs were correct).

However if I comment out the set CMAKE_Fortran_FLAGS line or if I skip
the toolchain file altogether and just pass
-DCMAKE_Fortran_COMPILER=mpxlf90 into the cmake command, the compiler ID
is VisualAge and everything works fine.

Am I misusing the toolchain file capability?

Thanks,
Will

-- 
Will Dicharry
Software Developer
Stellar Science Ltd Co
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3344 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090624/893eb9df/attachment.bin>


More information about the CMake mailing list