[CMake] Can't set CMAKE_Fortran_FLAGS ?

Bill Hoffman bill.hoffman at kitware.com
Thu May 1 13:24:43 EDT 2008


Convey Christian J NPRI wrote:
>> setenv FC /usr/bin/f77
>> setenv FFLAGS "-fno-backslash"
>> cmake
>>
>> Setting the compiler before the project command is not a good idea.
> 
> Thanks Bill, that did the trick.
> 
> Is there any plan to change this so that I can set these details inside a CMakeLists.txt file?  Doing is via environmental variables seems contrary to CMake's idiom.
> 

You can set them inside if you want, but be careful and surround them 
with if statements.  Also as Dave mentioned a set will not change the 
cache unless you force it.  If you force things from your cmakelist 
files, then people running ccmake, or cmake-gui can not change the 
values as each time cmake is run it will clobber the user value with the 
one from the cmakelist file.  You can change the defaults by using 
CMAKE_USER_MAKE_RULES_OVERRIDE.  If your project needs a flag to build, 
then you can add it like this:

if(CMAKE_Fortran_COMPILER MATCHES g77)
   set(CMAKE_Fortran_FLAGS "-fno-backslash ${CMAKE_Fortran_FLAGS}")
endif(CMAKE_Fortran_COMPILER MATCHES g77)

-Bill



More information about the CMake mailing list