2013-10-15 19:17:36 +04:00
|
|
|
#.rst:
|
|
|
|
# CheckLanguage
|
|
|
|
# -------------
|
|
|
|
#
|
|
|
|
# Check if a language can be enabled
|
|
|
|
#
|
2012-02-08 19:48:34 +04:00
|
|
|
# Usage:
|
2013-10-15 19:17:36 +04:00
|
|
|
#
|
|
|
|
# ::
|
|
|
|
#
|
|
|
|
# check_language(<lang>)
|
|
|
|
#
|
2012-02-08 19:48:34 +04:00
|
|
|
# where <lang> is a language that may be passed to enable_language()
|
|
|
|
# such as "Fortran". If CMAKE_<lang>_COMPILER is already defined the
|
|
|
|
# check does nothing. Otherwise it tries enabling the language in a
|
|
|
|
# test project. The result is cached in CMAKE_<lang>_COMPILER as the
|
2013-10-15 19:17:36 +04:00
|
|
|
# compiler that was found, or NOTFOUND if the language cannot be
|
|
|
|
# enabled.
|
2012-02-08 19:48:34 +04:00
|
|
|
#
|
|
|
|
# Example:
|
2013-10-15 19:17:36 +04:00
|
|
|
#
|
|
|
|
# ::
|
|
|
|
#
|
|
|
|
# check_language(Fortran)
|
|
|
|
# if(CMAKE_Fortran_COMPILER)
|
|
|
|
# enable_language(Fortran)
|
|
|
|
# else()
|
|
|
|
# message(STATUS "No Fortran support")
|
|
|
|
# endif()
|
2012-02-08 19:48:34 +04:00
|
|
|
|
|
|
|
#=============================================================================
|
|
|
|
# Copyright 2009-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(check_language lang)
|
|
|
|
if(NOT DEFINED CMAKE_${lang}_COMPILER)
|
|
|
|
set(_desc "Looking for a ${lang} compiler")
|
|
|
|
message(STATUS ${_desc})
|
|
|
|
file(REMOVE_RECURSE ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Check${lang})
|
|
|
|
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Check${lang}/CMakeLists.txt"
|
2014-05-13 13:02:19 +04:00
|
|
|
"cmake_minimum_required(VERSION ${CMAKE_VERSION})
|
2012-02-08 19:48:34 +04:00
|
|
|
project(Check${lang} ${lang})
|
|
|
|
file(WRITE \"\${CMAKE_CURRENT_BINARY_DIR}/result.cmake\"
|
|
|
|
\"set(CMAKE_${lang}_COMPILER \\\"\${CMAKE_${lang}_COMPILER}\\\")\\n\"
|
|
|
|
)
|
|
|
|
")
|
|
|
|
execute_process(
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Check${lang}
|
|
|
|
COMMAND ${CMAKE_COMMAND} . -G ${CMAKE_GENERATOR}
|
|
|
|
OUTPUT_VARIABLE output
|
|
|
|
ERROR_VARIABLE output
|
|
|
|
RESULT_VARIABLE result
|
|
|
|
)
|
|
|
|
include(${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Check${lang}/result.cmake OPTIONAL)
|
|
|
|
if(CMAKE_${lang}_COMPILER AND "${result}" STREQUAL "0")
|
|
|
|
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
|
|
|
|
"${_desc} passed with the following output:\n"
|
|
|
|
"${output}\n")
|
|
|
|
else()
|
|
|
|
set(CMAKE_${lang}_COMPILER NOTFOUND)
|
|
|
|
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
|
|
|
|
"${_desc} failed with the following output:\n"
|
|
|
|
"${output}\n")
|
|
|
|
endif()
|
|
|
|
message(STATUS "${_desc} - ${CMAKE_${lang}_COMPILER}")
|
|
|
|
set(CMAKE_${lang}_COMPILER "${CMAKE_${lang}_COMPILER}" CACHE FILEPATH "${lang} compiler")
|
|
|
|
mark_as_advanced(CMAKE_${lang}_COMPILER)
|
|
|
|
endif()
|
|
|
|
endmacro()
|