[CMake] FortranCInterface broken when cross-compiling

D. Barbier bouzim at gmail.com
Mon Mar 5 07:24:01 EST 2012


Hello,

I am trying to cross-compile a project containing C, C++ and Fortran
source files with mingw64 on a Debian host (Linux) with CMake 2.8.7:
  $ cat CMakeLists.txt
  cmake_minimum_required(VERSION 2.8)
  project ( FOO CXX C Fortran )
  include ( FortranCInterface )
  FortranCInterface_HEADER ( FC.h )
  $ cat toolchain-x86_64-w64-mingw32.cmake
  SET(CMAKE_SYSTEM_NAME Windows)
  SET(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
  SET(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)
  SET(CMAKE_Fortran_COMPILER x86_64-w64-mingw32-gfortran)
  SET(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres)
  $ mkdir build && cd build
  $ cmake -DCMAKE_TOOLCHAIN_FILE=../toolchain-x86_64-w64-mingw32.cmake ..
  -- The CXX compiler identification is GNU
  -- The C compiler identification is GNU
  -- The Fortran compiler identification is GNU
  -- Check for working CXX compiler: /usr/bin/x86_64-w64-mingw32-g++
  -- Check for working CXX compiler: /usr/bin/x86_64-w64-mingw32-g++ -- works
  -- Detecting CXX compiler ABI info
  -- Detecting CXX compiler ABI info - done
  -- Check for working C compiler: /usr/bin/x86_64-w64-mingw32-gcc
  -- Check for working C compiler: /usr/bin/x86_64-w64-mingw32-gcc -- works
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - done
  -- Check for working Fortran compiler: /usr/bin/x86_64-w64-mingw32-gfortran
  -- Check for working Fortran compiler:
/usr/bin/x86_64-w64-mingw32-gfortran  -- works
  -- Detecting Fortran compiler ABI info
  -- Detecting Fortran compiler ABI info - done
  -- Checking whether /usr/bin/x86_64-w64-mingw32-gfortran supports Fortran 90
  -- Checking whether /usr/bin/x86_64-w64-mingw32-gfortran supports
Fortran 90 -- yes
  -- Detecting Fortran/C Interface
  -- Detecting Fortran/C Interface - Failed to load sample executable
  -- Configuring done
  -- Generating done
  -- Build files have been written to: /tmp/test-cmake/build

This fails because
/usr/share/cmake-2.8/Modules/FortranCInterface/Detect.cmake builds a
FortranCInterface.exe program with try_compile(), and later
find_program() does not find it because it looks for FortranCInterface
instead of FortranCInterface.exe.
It works after replacing
  find_program(FortranCInterface_EXE
    NAMES FortranCInterface
    PATHS ${FortranCInterface_BINARY_DIR} ${FortranCInterface_BINARY_DIR}/Debug
    NO_DEFAULT_PATH
    )
by
  find_program(FortranCInterface_EXE
    NAMES FortranCInterface${CMAKE_EXECUTABLE_SUFFIX}
    PATHS ${FortranCInterface_BINARY_DIR} ${FortranCInterface_BINARY_DIR}/Debug
    NO_DEFAULT_PATH
    )
in /usr/share/cmake-2.8/Modules/FortranCInterface/Detect.cmake; but
maybe find_file could be used instead?

Denis


More information about the CMake mailing list