From 8c4f100a56619bf115115d0bcaa322c422f0c44f Mon Sep 17 00:00:00 2001 From: Melven Roehrig-Zoellner Date: Sun, 3 Apr 2016 23:01:22 +0200 Subject: Fortran: Fix platform id detection on mingw-w64 On mingw-w64 the GNU Fortran compiler does not define `__MINGW32__` or any similar indicator. Fix `CMAKE_Fortran_PLATFORM_ID` detection in this case by falling back to preprocessing a `.c` source file even when the compiler id is already detected. --- Modules/CMakeDetermineFortranCompiler.cmake | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Modules/CMakeDetermineFortranCompiler.cmake b/Modules/CMakeDetermineFortranCompiler.cmake index 1baca29..4f2a70c 100644 --- a/Modules/CMakeDetermineFortranCompiler.cmake +++ b/Modules/CMakeDetermineFortranCompiler.cmake @@ -209,6 +209,21 @@ if(NOT CMAKE_Fortran_COMPILER_ID_RUN) endif() endif() + # Fall back for GNU MINGW, which is not always detected correctly + # (__MINGW32__ is defined for the C language, but perhaps not for Fortran!) + if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU" AND NOT CMAKE_Fortran_PLATFORM_ID) + execute_process(COMMAND ${CMAKE_Fortran_COMPILER} ${CMAKE_Fortran_COMPILER_ID_FLAGS_LIST} -E "${CMAKE_ROOT}/Modules/CMakeTestGNU.c" + OUTPUT_VARIABLE CMAKE_COMPILER_OUTPUT RESULT_VARIABLE CMAKE_COMPILER_RETURN) + if(NOT CMAKE_COMPILER_RETURN) + if(CMAKE_COMPILER_OUTPUT MATCHES "THIS_IS_MINGW") + set(CMAKE_Fortran_PLATFORM_ID "MinGW") + endif() + if(CMAKE_COMPILER_OUTPUT MATCHES "THIS_IS_CYGWIN") + set(CMAKE_Fortran_PLATFORM_ID "Cygwin") + endif() + endif() + endif() + # Set old compiler and platform id variables. if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU") set(CMAKE_COMPILER_IS_GNUG77 1) -- cgit v0.12