[CMake] What's the best way to support additional compilers for an "official" CMake language such as Fortran

Brad King brad.king at kitware.com
Tue Jan 19 14:06:12 EST 2010


On 1/15/2010 5:58 PM, Alan W. Irwin wrote:
> The PLplot project has been supporting some additional Fortran
 > compilers

What compilers?

FYI, the Compiler/* and Platform/* modules have been refactored
a bit in CVS HEAD CMake.  The changes break compiler- and platform-
specific information down with more granularity, making it easier
to add new compilers.  We've added support for PathScale and PGI.

 > via files in cmake/modules/Platform in our source tree where we use
>
> set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules)
>
> This CMake_MODULE_PATH approach requires that we put a slightly modified
> version of CMakeFortranInformation.cmake in cmake/modules that searches
> ${CMAKE_MODULE_PATH}/Platform locations as well as
> ${CMAKE_ROOT}/Modules/Platform. That's pretty clumsy but this procedure has
> worked fine for CMake-2.6.x.

What change did you make to CMakeFortranInformation.cmake?  We should
be able to modify the CMake-provided version to do this.

> However, I am having trouble with the cmake-2.8.0 case. (I am getting
> strange errors that use g++ rather than gfortran as the Fortran linker for
> the static Fortran library case).

Static libraries don't link, they are archives, so I assume you mean
that linking an executable to a static library is using the C++ linker.

This is a feature of CMake 2.8.  CMake tracks the languages involved
in each target.  If any C++ is involved, either directly or through
a linked library, then it uses the C++ linker.  This is necessary to
initialize the C++ language runtime correctly.  If Fortran is involved
too then it uses the C++ linker and explicitly passes Fortran language
libraries.

 > My guess is I need to add additional
> Fortran support files in cmake/modules for the CMake-2.8.0 case. But that
> is clumsier still and requires that we immediately drop CMake-2.6.x
> support.

Create a language module directory for each version of CMake.

> Thus, I am wondering if there is a better procedure (or whether such a
> procedure could be implemented within CMake) to allow convenient CMake
> support for a project like PLplot to support additional Fortran compilers
> (or any additional compilers for a CMake-supported language like Fortran)
> without requiring our users patch their installed version of CMake.

The above-mentioned modification to CMakeFortranInformation.cmake should
handle this.

> Of course, the long-term solution to this problem is to contribute our files
> that support additional Fortran compilers to CMake. We would be happy to do
> that, but that probably involves considerable delay until they are accepted
> into an official CMake release

If you had started that process back when you wrote them for 2.6
then perhaps they would have been in 2.8.

> Fortran compilers (or C compilers or C++ compilers) they would like us to
> support, we would always need to independently test these files over at
> least one PLplot release cycle ourselves before contributing them to CMake.

Why?  CMake's tests exercise just about everything CMake knows
about the compilers.  I think direct contribution to CMake should
be done immediately.

-Brad


More information about the CMake mailing list