[CMake] Bad flags being passed to NAG Fortran compiler
Alan W. Irwin
irwin at beluga.phys.uvic.ca
Mon Feb 18 03:24:12 EST 2013
Hi Neil:
I have no experience with the NAG Fortran compiler, but just to
get the discussion rolling, I think I can guess at the answer to
your principal question below.
On 2013-02-17 17:13-0700 Neil Carlson wrote:
> When building a shared library using the NAG Fortran compiler, cmake is
> invoking
> the compiler with the "-fPIC" option. This is wrong. The correct option
> is "-PIC".
> I've found I can get things to work if I add the following two lines to my
> CMakeLists.txt
> file (probably not the right way to fix things):
>
> set(CMAKE_Fortran_COMPILE_OPTIONS_PIC "-PIC")
> set(CMAKE_SHARED_LIBRARY_Fortran_FLAGS "-PIC")
>
> Several questions (I'm *very* new to cmake, so apologies if they're stupid):
> 1) I've found the file Modules/Platform/Linux-NAG-Fortran.cmake. Is that
> where
> compiler-specific settings like this belong? And are the above two
> lines the
> correct thing to add to that file?
There appear to be two places that set up NAG flags for CMake-2.8.10.2:
Modules/Compiler/NAG-Fortran.cmake
Modules/Platform/Linux-NAG-Fortran.cmake (which you mentioned above) and
My best guess is the former is where you set NAG-related flags that are
platform independent like those above. For example, that file already contains
set(CMAKE_SHARED_LIBRARY_Fortran_FLAGS "-PIC")
so I don't think you have to set that variable at all!
I would also try setting
set(CMAKE_Fortran_COMPILE_OPTIONS_PIC "-PIC")
in Modules/Compiler/NAG-Fortran.cmake as well to see if that
completely satisfies your needs.
Note the only place CMAKE_Fortran_COMPILE_OPTIONS_PIC is set now is in
Modules/CMakeFortranInformation.cmake. There it just sets that value
to the equivalent _C_ variable, but I don't know what C compiler is
used with NAG (which is strictly a Fortran compiler as far as I know)
which is why I suggested setting CMAKE_Fortran_COMPILE_OPTIONS_PIC
above rather than CMAKE_C_COMPILE_OPTIONS_PIC which likely would screw up
the C case.
In sum, I am just guessing based on patterns used for other
compilers/platforms. You really should do some experiments to
see what gives the correct results, but the experiment I
would start with is insert
set(CMAKE_Fortran_COMPILE_OPTIONS_PIC "-PIC")
in Modules/Compiler/NAG-Fortran.cmake.
If that guess is incorrect, the Fortran expert here, Brad King, will hopefully
correct me.
Alan
__________________________
Alan W. Irwin
Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).
Programming affiliations with the FreeEOS equation-of-state
implementation for stellar interiors (freeeos.sf.net); the Time
Ephemerides project (timeephem.sf.net); PLplot scientific plotting
software package (plplot.sf.net); the libLASi project
(unifont.org/lasi); the Loads of Linux Links project (loll.sf.net);
and the Linux Brochure Project (lbproject.sf.net).
__________________________
Linux-powered Science
__________________________
More information about the CMake
mailing list