1 # - Check if a language can be enabled
3 # check_language(<lang>)
4 # where <lang> is a language that may be passed to enable_language()
5 # such as "Fortran". If CMAKE_<lang>_COMPILER is already defined the
6 # check does nothing. Otherwise it tries enabling the language in a
7 # test project. The result is cached in CMAKE_<lang>_COMPILER as the
8 # compiler that was found, or NOTFOUND if the language cannot be enabled.
11 # check_language(Fortran)
12 # if(CMAKE_Fortran_COMPILER)
13 # enable_language(Fortran)
15 # message(STATUS "No Fortran support")
18 #=============================================================================
19 # Copyright 2009-2012 Kitware, Inc.
21 # Distributed under the OSI-approved BSD License (the "License");
22 # see accompanying file Copyright.txt for details.
24 # This software is distributed WITHOUT ANY WARRANTY; without even the
25 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
26 # See the License for more information.
27 #=============================================================================
28 # (To distribute this file outside of CMake, substitute the full
29 # License text for the above reference.)
31 macro(check_language lang)
32 if(NOT DEFINED CMAKE_${lang}_COMPILER)
33 set(_desc "Looking for a ${lang} compiler")
34 message(STATUS ${_desc})
35 file(REMOVE_RECURSE ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Check${lang})
36 file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Check${lang}/CMakeLists.txt"
37 "cmake_minimum_required(VERSION 2.8)
38 project(Check${lang} ${lang})
39 file(WRITE \"\${CMAKE_CURRENT_BINARY_DIR}/result.cmake\"
40 \"set(CMAKE_${lang}_COMPILER \\\"\${CMAKE_${lang}_COMPILER}\\\")\\n\"
44 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Check${lang}
45 COMMAND ${CMAKE_COMMAND} . -G ${CMAKE_GENERATOR}
46 OUTPUT_VARIABLE output
48 RESULT_VARIABLE result
50 include(${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Check${lang}/result.cmake OPTIONAL)
51 if(CMAKE_${lang}_COMPILER AND "${result}" STREQUAL "0")
52 file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
53 "${_desc} passed with the following output:\n"
56 set(CMAKE_${lang}_COMPILER NOTFOUND)
57 file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
58 "${_desc} failed with the following output:\n"
61 message(STATUS "${_desc} - ${CMAKE_${lang}_COMPILER}")
62 set(CMAKE_${lang}_COMPILER "${CMAKE_${lang}_COMPILER}" CACHE FILEPATH "${lang} compiler")
63 mark_as_advanced(CMAKE_${lang}_COMPILER)