[CMake] Fortran MinGW on Windows

Andreas Mohr andi at lisas.de
Wed Jun 12 15:38:42 EDT 2013


Hi,

On Wed, Jun 12, 2013 at 12:00:05PM -0400, cmake-request at cmake.org wrote:
> Date: Wed, 12 Jun 2013 04:55:20 +0000
> From: "Leek, Jim" <leek2 at llnl.gov>
> Subject: Re: [CMake] Fortran MinGW on Windows
> To: "Leek, Jim" <leek2 at llnl.gov>, Brad King <brad.king at kitware.com>
> Cc: "'cmake at cmake.org'" <cmake at cmake.org>
> Message-ID:
> 	<6B554E87D42BA74AB76EC1D40C57A0DA4CE6E32D at PRDEXMBX-04.the-lab.llnl.gov>
> 	
> Content-Type: text/plain; charset="us-ascii"
> 
> This is a follow-up post to document the eventual solution to this issue.
> 
> The problem turned out to be where I decided to put enable_language(Fortran).  This project is largely C++, but has a few optional Fortran libraries.  I did not want Fortran to be required if the user does not want to use the libraries that require Fortran.  Therefore I had the CMakeLists.txt files divided like this:
> 
> In the main CMakeLists.txt file, the user can choose to use a Fortran library, MARS in this case:
> if (USE_MARS)
>   include_directories ("${PROJECT_SOURCE_DIR}/External/MARS")
>   add_subdirectory (External/MARS) 
>   set (EXTRA_LIBS ${EXTRA_LIBS} mars)
>   add_definitions(-DHAVE_MARS)
> endif (USE_MARS)
> 
> Then I had another CmakeLists.txt file in External/MARS that builds the MARS library with Fortran:
> enable_language(Fortran)

You do know about /usr/share/cmake-2.8/Modules/CheckLanguage.cmake ,
right? ;-)

Potentially useful pseudo code:

include(CheckLanguage)
check_language_function_stuff(Fortran)
set(PROJ_WANT_FORTRAN_PARTS_default_setting OFF)
if(have_fortran)
  set(PROJ_WANT_FORTRAN_PARTS_default_setting ON)
endif(have_fortran)
option(PROJ_WANT_FORTRAN_PARTS "Build Fortran stuff?" ${PROJ_WANT_FORTRAN_PARTS_default_setting})
if(PROJ_WANT_FORTRAN_PARTS)
  grab_fortran_stuff()
endif(PROJ_WANT_FORTRAN_PARTS)

Admittedly totally not quite overly related to what you were asking,
and cobbled together in 35.8 seconds, but... :)

Andreas Mohr


More information about the CMake mailing list