summaryrefslogtreecommitdiffstats
path: root/Modules/CMakeAddFortranSubdirectory.cmake
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2011-12-15 16:39:42 (GMT)
committerBrad King <brad.king@kitware.com>2012-02-09 13:34:14 (GMT)
commit414a780d1c22339e924ea3d880e54482f0d67898 (patch)
treef1d9cee38835664c8ee8eee0a895c2b40dbd597d /Modules/CMakeAddFortranSubdirectory.cmake
parent7e0d9f15d626c13b452bc213172cd54c24f5b41a (diff)
downloadCMake-414a780d1c22339e924ea3d880e54482f0d67898.zip
CMake-414a780d1c22339e924ea3d880e54482f0d67898.tar.gz
CMake-414a780d1c22339e924ea3d880e54482f0d67898.tar.bz2
CMakeAddFortranSubdirectory: Validate gfortran architecture
Verify that MINGW_GFORTRAN not only points to a MinGW gfortran but also one that compiles for the target architecture. This prevents using a 32-bit gfortran in a 64-bit MSVC build.
Diffstat (limited to 'Modules/CMakeAddFortranSubdirectory.cmake')
-rw-r--r--Modules/CMakeAddFortranSubdirectory.cmake26
1 files changed, 21 insertions, 5 deletions
diff --git a/Modules/CMakeAddFortranSubdirectory.cmake b/Modules/CMakeAddFortranSubdirectory.cmake
index d36738c..c846b55 100644
--- a/Modules/CMakeAddFortranSubdirectory.cmake
+++ b/Modules/CMakeAddFortranSubdirectory.cmake
@@ -57,12 +57,28 @@ function(_setup_mingw_config_and_build source_dir)
"Or set the cache variable MINGW_GFORTRAN to the full path. "
" This is required to build")
endif()
- execute_process(COMMAND ${MINGW_GFORTRAN} -v ERROR_VARIABLE out)
- if(NOT "${out}" MATCHES "Target:.*mingw32")
- message(FATAL_ERROR "Non-MinGW gfortran found: ${MINGW_GFORTRAN}\n"
- "output from -v [${out}]\n"
- "set MINGW_GFORTRAN to the path to MinGW fortran.")
+
+ # Validate the MinGW gfortran we found.
+ if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+ set(_mingw_target "Target:.*64.*mingw")
+ else()
+ set(_mingw_target "Target:.*mingw32")
endif()
+ execute_process(COMMAND "${MINGW_GFORTRAN}" -v
+ ERROR_VARIABLE out ERROR_STRIP_TRAILING_WHITESPACE)
+ if(NOT "${out}" MATCHES "${_mingw_target}")
+ string(REPLACE "\n" "\n " out " ${out}")
+ message(FATAL_ERROR
+ "MINGW_GFORTRAN is set to\n"
+ " ${MINGW_GFORTRAN}\n"
+ "which is not a MinGW gfortran for this architecture. "
+ "The output from -v does not match \"${_mingw_target}\":\n"
+ "${out}\n"
+ "Set MINGW_GFORTRAN to a proper MinGW gfortran for this architecture."
+ )
+ endif()
+
+ # Configure scripts to run MinGW tools with the proper PATH.
get_filename_component(MINGW_PATH ${MINGW_GFORTRAN} PATH)
file(TO_NATIVE_PATH "${MINGW_PATH}" MINGW_PATH)
string(REPLACE "\\" "\\\\" MINGW_PATH "${MINGW_PATH}")