Imported Upstream version 2.8.10.2
[platform/upstream/cmake.git] / Modules / CMakeDetermineCompiler.cmake
1
2 #=============================================================================
3 # Copyright 2004-2012 Kitware, Inc.
4 #
5 # Distributed under the OSI-approved BSD License (the "License");
6 # see accompanying file Copyright.txt for details.
7 #
8 # This software is distributed WITHOUT ANY WARRANTY; without even the
9 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 # See the License for more information.
11 #=============================================================================
12 # (To distribute this file outside of CMake, substitute the full
13 #  License text for the above reference.)
14
15 macro(_cmake_find_compiler lang)
16   # Use already-enabled languages for reference.
17   get_property(_languages GLOBAL PROPERTY ENABLED_LANGUAGES)
18   list(REMOVE_ITEM _languages "${lang}")
19
20   if(CMAKE_${lang}_COMPILER_INIT)
21     # Search only for the specified compiler.
22     set(CMAKE_${lang}_COMPILER_LIST "${CMAKE_${lang}_COMPILER_INIT}")
23   else()
24     # Re-order the compiler list with preferred vendors first.
25     set(_${lang}_COMPILER_LIST "${CMAKE_${lang}_COMPILER_LIST}")
26     set(CMAKE_${lang}_COMPILER_LIST "")
27     # Prefer vendors of compilers from reference languages.
28     foreach(l ${_languages})
29       list(APPEND CMAKE_${lang}_COMPILER_LIST
30         ${_${lang}_COMPILER_NAMES_${CMAKE_${l}_COMPILER_ID}})
31     endforeach()
32     # Prefer vendors based on the platform.
33     list(APPEND CMAKE_${lang}_COMPILER_LIST ${CMAKE_${lang}_COMPILER_NAMES})
34     # Append the rest of the list and remove duplicates.
35     list(APPEND CMAKE_${lang}_COMPILER_LIST ${_${lang}_COMPILER_LIST})
36     unset(_${lang}_COMPILER_LIST)
37     list(REMOVE_DUPLICATES CMAKE_${lang}_COMPILER_LIST)
38     if(CMAKE_${lang}_COMPILER_EXCLUDE)
39       list(REMOVE_ITEM CMAKE_${lang}_COMPILER_LIST
40         ${CMAKE_${lang}_COMPILER_EXCLUDE})
41     endif()
42   endif()
43
44   # Look for directories containing compilers of reference languages.
45   set(_${lang}_COMPILER_HINTS)
46   foreach(l ${_languages})
47     if(CMAKE_${l}_COMPILER AND IS_ABSOLUTE "${CMAKE_${l}_COMPILER}")
48       get_filename_component(_hint "${CMAKE_${l}_COMPILER}" PATH)
49       if(IS_DIRECTORY "${_hint}")
50         list(APPEND _${lang}_COMPILER_HINTS "${_hint}")
51       endif()
52       unset(_hint)
53     endif()
54   endforeach()
55
56   # Find the compiler.
57   if(_${lang}_COMPILER_HINTS)
58     # Prefer directories containing compilers of reference languages.
59     list(REMOVE_DUPLICATES _${lang}_COMPILER_HINTS)
60     find_program(CMAKE_${lang}_COMPILER
61       NAMES ${CMAKE_${lang}_COMPILER_LIST}
62       PATHS ${_${lang}_COMPILER_HINTS}
63       NO_DEFAULT_PATH
64       DOC "${lang} compiler")
65   endif()
66   find_program(CMAKE_${lang}_COMPILER NAMES ${CMAKE_${lang}_COMPILER_LIST} DOC "${lang} compiler")
67   if(CMAKE_${lang}_COMPILER_INIT AND NOT CMAKE_${lang}_COMPILER)
68     set(CMAKE_${lang}_COMPILER "${CMAKE_${lang}_COMPILER_INIT}" CACHE FILEPATH "${lang} compiler" FORCE)
69   endif()
70   unset(_${lang}_COMPILER_HINTS)
71   unset(_languages)
72 endmacro()