[CMake] adjusting CMAKE_Fortran_LINK_EXECUTABLE

Michael Hertling mhertling at online.de
Thu Mar 10 20:22:18 EST 2011


On 03/10/2011 03:07 PM, Brad King wrote:
> On 03/10/2011 03:48 AM, Ilias Miroslav wrote:
>> By default, the current CMAKE_Fortran_LINK_EXECUTABLE consists of several variables:
>>
>> "<CMAKE_Fortran_COMPILER>  <CMAKE_Fortran_LINK_FLAGS> <LINK_FLAGS> <FLAGS> <OBJECTS>  -o <TARGET> <LINK_LIBRARIES>"
> [snip]
>> selected variables only: "<LINK_FLAGS>  <OBJECTS>  -o <TARGET>  <LINK_LIBRARIES>"
> 
> The <FLAGS> are in there because there are cases where the compiler front-end
> needs to know what compilation flags were used to produce the object files
> to adjust the flags and libraries it passes to the underlying linker.
> 
>> The "-ffast-math"flag  works for compilation of fortran source codes,
>> but is unsuitable for g95-linking in this case.
> 
> Perhaps this change should be extended for executables too:
> 
>   http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=88bd3b52
> 
> Then -ffast-math could be added to the forbidden flag list for linking.
> 
> Meanwhile one can work around this problem by not putting -ffast-math
> in CMAKE_Fortran_FLAGS.  Instead add it to each target that needs it
> using the COMPILE_FLAGS target property.

Alternatively, if you use the Makefile generators only, you might set
one of the RULE_LAUNCH_LINK properties to a script which removes the
-ffast-math flag from the linker command line, e.g.:

#!/bin/sh
COMMAND=$1; shift
for i in $*; do
    [ "$i" != "-ffast-math" ] && COMMAND="$COMMAND $i"; shift
done
exec $COMMAND

In this way, you can use each flag as ever and have the link process
intercepted right before linking takes place in order to remove any
incriminated parameters.

Regards,

Michael


More information about the CMake mailing list