[CMake] How to prefix fortran source files with special compile flag?

Brad King brad.king at kitware.com
Mon Nov 2 17:30:54 EST 2009


Bill Hoffman wrote:
> Kelly (KT) Thompson wrote:
>> Hi,
>>
>> I am trying to use Intel ifort on Linux to compile source code that 
>> uses the extension .F95.  By default, ifort will not compile files 
>> with this extension.  To allow the compilation, the name of the source 
>> file must be preceded by -Tf (treat the next option as fortran 
>> source). While I know how to modify the Fortran flags, I don't know 
>> how to add the '-Tf' flag that is directly in front of the source file 
>> name (and after the -c).  Can anyone point me in the right direction?
>>
> 
> You could try this:
> 
> Edit
> /Modules/Platform/Linux-Intel-Fortran.cmake
> 
> And add this:
> 
>   SET(CMAKE_Fortran_COMPILE_OBJECT
>     "<CMAKE_Fortran_COMPILER> -o <OBJECT> <DEFINES> <FLAGS> -c -Tf 
> <SOURCE>")

FYI, I've investigated fixing this upstream.  CMake should make sure
the compiler knows to compile as Fortran for any extension CMake
recognizes.  For the Intel compiler, this means adding -Tf always.

Unfortunately it looks like -Tf implies -fixed too so it does not
work with free-format sources unless -free is also added.  We cannot
add -free automatically because some sources might be fixed.  The
solution ties into another item on my todo-list: we need a source
file property to mark every source as fixed or free format.  It can
default based on file extension.  The property would be used both
for adding "-fixed"/"-free" flags and to aid the dependency scanner
in identifying comments.

Summary: until the above is done we cannot add -Tf upstream :(

-Brad


More information about the CMake mailing list