As good as cmake is claimed to be, its documentation seems to leave a lot to be desired (unless I’m totally failing at understanding the basics).
I’m trying to write a cmake file for a set of fortran programs which also depend on some other libraries (which are already compiled for my system, but I will want to make a cmake file for these libraries too).
A lot of the commands which I’ve found in examples online don’t appear in the official docs, which is a bit disconcerting.. for example, http://www.vtk.org/Wiki/CMakeForFortranExample contains the line
get_filename_component (Fortran_COMPILER_NAME ${CMAKE_Fortran_COMPILER} NAME)
yet when I include this in my own CMakeLists.txt I get an error
Missing variable is:
CMAKE_fortran_COMPILER
What am I missing?!
Edit: current CMakeLists.txt
cmake_minimum_required(VERSION 2.6)
enable_language(fortran)
project(fortranTest)
get_filename_component (Fortran_COMPILER_NAME ${CMAKE_Fortran_COMPILER} NAME)
Edit 2
I still haven’t worked out how to include dependent libraries.
The language names are case sensitive. As posted, I get:
However, by changing the file to (note it is
Fortranand notfortraninenable_language():You get:
Which, if permitted to finish, would work as expected. However, there are better ways to identify the compiler for the purposes of determining compiler flags. The method used in the cited example only works on systems where the compiler is not wrapped, which means systems that don’t invoke the compiler through something like
mpif90orftnon Cray. A better method is to check:The list of possible names can be found by inspecting the file in the CMake Module directory
Modules/CMakeFortranCompilerId.F.in