summaryrefslogtreecommitdiffstats
path: root/Modules/CMakeDetermineFortranCompiler.cmake
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2012-08-02 15:08:55 (GMT)
committerBrad King <brad.king@kitware.com>2012-08-02 15:33:18 (GMT)
commit796e33734db09d80041872e4ce04e838146466df (patch)
treedb414641a3d38fa249240b561085b28861582190 /Modules/CMakeDetermineFortranCompiler.cmake
parentb708f1a2b9bc82ada6a22f6c63d9fb6ccedb2862 (diff)
downloadCMake-796e33734db09d80041872e4ce04e838146466df.zip
CMake-796e33734db09d80041872e4ce04e838146466df.tar.gz
CMake-796e33734db09d80041872e4ce04e838146466df.tar.bz2
Factor common code out of CMakeDetermine(ASM|C|CXX|Fortran)Compiler
The compiler candidate list selection and search code for C, C++, ASM, and Fortran languages was duplicated across four modules. To look for compilers adjacent to already-enabled languages the C and CXX modules each used _CMAKE_USER_(C|CXX)_COMPILER_PATH and the ASM module used _CMAKE_TOOLCHAIN_LOCATION. Since commit 4debb7ac (Bias Fortran compiler search with C/C++ compilers, 2009-09-09) CMake prefers Fortran compilers matching the vendor and directory of an enabled C or C++ compiler. Factor out the common functionality among the four languages into a new CMakeDetermineCompiler module. Generalize the Fortran implementation so that all languages may each use the vendor and directory of the other languages that have already been enabled. For now do not list any vendor-specific names for C, C++, or ASM so that only the directory preference is used for these languages (existing behavior).
Diffstat (limited to 'Modules/CMakeDetermineFortranCompiler.cmake')
-rw-r--r--Modules/CMakeDetermineFortranCompiler.cmake43
1 files changed, 6 insertions, 37 deletions
diff --git a/Modules/CMakeDetermineFortranCompiler.cmake b/Modules/CMakeDetermineFortranCompiler.cmake
index ade6d58..6d6990e 100644
--- a/Modules/CMakeDetermineFortranCompiler.cmake
+++ b/Modules/CMakeDetermineFortranCompiler.cmake
@@ -19,6 +19,8 @@
# the cmake variable CMAKE_GENERATOR_FC which can be defined by a generator
# as a default compiler
+INCLUDE(${CMAKE_ROOT}/Modules/CMakeDetermineCompiler.cmake)
+
IF(NOT CMAKE_Fortran_COMPILER)
# prefer the environment variable CC
IF($ENV{FC} MATCHES ".+")
@@ -40,9 +42,7 @@ IF(NOT CMAKE_Fortran_COMPILER)
ENDIF(CMAKE_GENERATOR_FC)
# finally list compilers to try
- IF(CMAKE_Fortran_COMPILER_INIT)
- SET(CMAKE_Fortran_COMPILER_LIST ${CMAKE_Fortran_COMPILER_INIT})
- ELSE(CMAKE_Fortran_COMPILER_INIT)
+ IF(NOT CMAKE_Fortran_COMPILER_INIT)
# Known compilers:
# f77/f90/f95: generic compiler names
# g77: GNU Fortran 77 compiler
@@ -77,41 +77,10 @@ IF(NOT CMAKE_Fortran_COMPILER)
SET(_Fortran_COMPILER_NAMES_PathScale pathf2003 pathf95 pathf90)
SET(_Fortran_COMPILER_NAMES_XL xlf)
SET(_Fortran_COMPILER_NAMES_VisualAge xlf95 xlf90 xlf)
-
- # Prefer vendors matching the C and C++ compilers.
- SET(CMAKE_Fortran_COMPILER_LIST
- ${_Fortran_COMPILER_NAMES_${CMAKE_C_COMPILER_ID}}
- ${_Fortran_COMPILER_NAMES_${CMAKE_CXX_COMPILER_ID}}
- ${CMAKE_Fortran_COMPILER_LIST})
- LIST(REMOVE_DUPLICATES CMAKE_Fortran_COMPILER_LIST)
- ENDIF(CMAKE_Fortran_COMPILER_INIT)
-
- # Look for directories containing the C and C++ compilers.
- SET(_Fortran_COMPILER_HINTS)
- FOREACH(lang C CXX)
- IF(CMAKE_${lang}_COMPILER AND IS_ABSOLUTE "${CMAKE_${lang}_COMPILER}")
- GET_FILENAME_COMPONENT(_hint "${CMAKE_${lang}_COMPILER}" PATH)
- IF(IS_DIRECTORY "${_hint}")
- LIST(APPEND _Fortran_COMPILER_HINTS "${_hint}")
- ENDIF()
- SET(_hint)
- ENDIF()
- ENDFOREACH()
-
- # Find the compiler.
- IF(_Fortran_COMPILER_HINTS)
- # Prefer directories containing C and C++ compilers.
- LIST(REMOVE_DUPLICATES _Fortran_COMPILER_HINTS)
- FIND_PROGRAM(CMAKE_Fortran_COMPILER
- NAMES ${CMAKE_Fortran_COMPILER_LIST}
- PATHS ${_Fortran_COMPILER_HINTS}
- NO_DEFAULT_PATH
- DOC "Fortran compiler")
ENDIF()
- FIND_PROGRAM(CMAKE_Fortran_COMPILER NAMES ${CMAKE_Fortran_COMPILER_LIST} DOC "Fortran compiler")
- IF(CMAKE_Fortran_COMPILER_INIT AND NOT CMAKE_Fortran_COMPILER)
- SET(CMAKE_Fortran_COMPILER "${CMAKE_Fortran_COMPILER_INIT}" CACHE FILEPATH "Fortran compiler" FORCE)
- ENDIF(CMAKE_Fortran_COMPILER_INIT AND NOT CMAKE_Fortran_COMPILER)
+
+ _cmake_find_compiler(Fortran)
+
ELSE(NOT CMAKE_Fortran_COMPILER)
# we only get here if CMAKE_Fortran_COMPILER was specified using -D or a pre-made CMakeCache.txt
# (e.g. via ctest) or set in CMAKE_TOOLCHAIN_FILE