summaryrefslogtreecommitdiffstats
path: root/Modules/CMakeDetermineCompiler.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/CMakeDetermineCompiler.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/CMakeDetermineCompiler.cmake')
-rw-r--r--Modules/CMakeDetermineCompiler.cmake66
1 files changed, 66 insertions, 0 deletions
diff --git a/Modules/CMakeDetermineCompiler.cmake b/Modules/CMakeDetermineCompiler.cmake
new file mode 100644
index 0000000..55d554b
--- /dev/null
+++ b/Modules/CMakeDetermineCompiler.cmake
@@ -0,0 +1,66 @@
+
+#=============================================================================
+# Copyright 2004-2012 Kitware, Inc.
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+macro(_cmake_find_compiler lang)
+ # Use already-enabled languages for reference.
+ get_property(_languages GLOBAL PROPERTY ENABLED_LANGUAGES)
+ list(REMOVE_ITEM _languages "${lang}")
+
+ if(CMAKE_${lang}_COMPILER_INIT)
+ # Search only for the specified compiler.
+ set(CMAKE_${lang}_COMPILER_LIST "${CMAKE_${lang}_COMPILER_INIT}")
+ else()
+ # Re-order the compiler list with preferred vendors first.
+ set(_${lang}_COMPILER_LIST "${CMAKE_${lang}_COMPILER_LIST}")
+ set(CMAKE_${lang}_COMPILER_LIST "")
+ # Prefer vendors of compilers from reference languages.
+ foreach(l ${_languages})
+ list(APPEND CMAKE_${lang}_COMPILER_LIST
+ ${_${lang}_COMPILER_NAMES_${CMAKE_${l}_COMPILER_ID}})
+ endforeach()
+ # Append the rest of the list and remove duplicates.
+ list(APPEND CMAKE_${lang}_COMPILER_LIST ${_${lang}_COMPILER_LIST})
+ unset(_${lang}_COMPILER_LIST)
+ list(REMOVE_DUPLICATES CMAKE_${lang}_COMPILER_LIST)
+ endif()
+
+ # Look for directories containing compilers of reference languages.
+ set(_${lang}_COMPILER_HINTS)
+ foreach(l ${_languages})
+ if(CMAKE_${l}_COMPILER AND IS_ABSOLUTE "${CMAKE_${l}_COMPILER}")
+ get_filename_component(_hint "${CMAKE_${l}_COMPILER}" PATH)
+ if(IS_DIRECTORY "${_hint}")
+ list(APPEND _${lang}_COMPILER_HINTS "${_hint}")
+ endif()
+ unset(_hint)
+ endif()
+ endforeach()
+
+ # Find the compiler.
+ if(_${lang}_COMPILER_HINTS)
+ # Prefer directories containing compilers of reference languages.
+ list(REMOVE_DUPLICATES _${lang}_COMPILER_HINTS)
+ find_program(CMAKE_${lang}_COMPILER
+ NAMES ${CMAKE_${lang}_COMPILER_LIST}
+ PATHS ${_${lang}_COMPILER_HINTS}
+ NO_DEFAULT_PATH
+ DOC "${lang} compiler")
+ endif()
+ find_program(CMAKE_${lang}_COMPILER NAMES ${CMAKE_${lang}_COMPILER_LIST} DOC "${lang} compiler")
+ if(CMAKE_${lang}_COMPILER_INIT AND NOT CMAKE_${lang}_COMPILER)
+ set(CMAKE_${lang}_COMPILER "${CMAKE_${lang}_COMPILER_INIT}" CACHE FILEPATH "${lang} compiler" FORCE)
+ endif()
+ unset(_${lang}_COMPILER_HINTS)
+ unset(_languages)
+endmacro()