MantisBT - CMake
View Issue Details
0009195CMakeModulespublic2009-06-22 16:242009-07-29 16:44
Will Dicharry 
Brad King 
normalfeatureN/A
closedfixed 
CMake-2-6 
 
0009195: Find module for linking mixed Fortran/C code
When linking a Fortran library from C/C++ code, it is necessary to link the Fortran run-time libraries. Attached is a find module that attempts to do this in a portable way by compiling a simple test verbosely and scraping the output for -L and -l flags. The module has been tested on the following OS/Compiler combinations:
- Linux/GNU
- Linux/Intel
- Linux/PGI
- AIX/VisualAge
No tags attached.
? FindFortran.cmake (3,691) 2009-06-22 16:24
https://public.kitware.com/Bug/file/2339/FindFortran.cmake
Issue History
2009-06-22 16:24Will DicharryNew Issue
2009-06-22 16:24Will DicharryFile Added: FindFortran.cmake
2009-06-22 16:45Brad KingStatusnew => assigned
2009-06-22 16:45Brad KingAssigned To => Brad King
2009-07-23 10:15Brad KingNote Added: 0016951
2009-07-23 10:19Brad KingNote Added: 0016952
2009-07-23 10:20Brad KingNote Added: 0016953
2009-07-29 16:44Brad KingNote Added: 0017014
2009-07-29 16:44Brad KingStatusassigned => closed
2009-07-29 16:44Brad KingResolutionopen => fixed

Notes
(0016951)
Brad King   
2009-07-23 10:15   
I've implemented automatic detection of implicit link libraries and search directories for C, C++, and Fortran compilers. There is a new undocumented, internal-only module which does the parsing:

  Modules/CMakeParseImplicitLinkInfo.cmake

The results are stored in variables

  CMAKE_<LANG>_IMPLICIT_LINK_LIBRARIES
  CMAKE_<LANG>_IMPLICIT_LINK_DIRECTORIES

but they are not meant for user consumption. A future commit will make automatic use of them for mixed-language link line computation.

I've added a test file:

  Tests/CMakeTests/ImplicitLinkInfoTest.cmake.in

which hard-codes a bunch of examples from several platforms and tests that the parser works as expected.

I've tested this with GNU, MIPSpro, HP, VisualAge, SunPro.
(0016952)
Brad King   
2009-07-23 10:19   
Detection takes place during the "Detecting <lang> compiler ABI info" step.

In order to enable this for a new compiler, make sure that CMAKE_<LANG>_COMPILER_ID is computed correctly. Then add a module

  Modules/Compiler/<id>-<lang>.cmake

containing a line like

  SET(CMAKE_<lang>_VERBOSE_FLAG "-v")

The language <lang> can be one of "C", "CXX", or "Fortran".

The ABI detection code passes this flag to its test project and parses the compiler output to extract the link line.
(0016953)
Brad King   
2009-07-23 10:20   
Currently I do not have access to Intel or PGI compilers. Can you please test CVS HEAD CMake on these compilers?
(0017014)
Brad King   
2009-07-29 16:44   
I've committed support for Intel and PGI too.

CMake now automatically handles fortran libraries, so there is no need for users to find them.