summaryrefslogtreecommitdiff
path: root/Modules/CMakeDetermineCompiler.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/CMakeDetermineCompiler.cmake')
-rw-r--r--Modules/CMakeDetermineCompiler.cmake75
1 files changed, 55 insertions, 20 deletions
diff --git a/Modules/CMakeDetermineCompiler.cmake b/Modules/CMakeDetermineCompiler.cmake
index f522c4408..c37adaee1 100644
--- a/Modules/CMakeDetermineCompiler.cmake
+++ b/Modules/CMakeDetermineCompiler.cmake
@@ -1,16 +1,6 @@
+# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
+# file Copyright.txt or https://cmake.org/licensing for details.
-#=============================================================================
-# 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.
@@ -65,21 +55,66 @@ macro(_cmake_find_compiler lang)
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)
+ set_property(CACHE CMAKE_${lang}_COMPILER PROPERTY VALUE "${CMAKE_${lang}_COMPILER_INIT}")
endif()
unset(_${lang}_COMPILER_HINTS)
unset(_languages)
# Look for a make tool provided by Xcode
- if(CMAKE_${lang}_COMPILER STREQUAL "CMAKE_${lang}_COMPILER-NOTFOUND" AND CMAKE_HOST_APPLE)
- foreach(comp ${CMAKE_${lang}_COMPILER_LIST})
- execute_process(COMMAND xcrun --find ${comp}
+ if(CMAKE_HOST_APPLE)
+ macro(_query_xcrun compiler_name result_var_keyword result_var)
+ if(NOT "x${result_var_keyword}" STREQUAL "xRESULT_VAR")
+ message(FATAL_ERROR "Bad arguments to macro")
+ endif()
+ execute_process(COMMAND xcrun --find ${compiler_name}
OUTPUT_VARIABLE _xcrun_out OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_VARIABLE _xcrun_err)
- if(_xcrun_out)
- set_property(CACHE CMAKE_${lang}_COMPILER PROPERTY VALUE "${_xcrun_out}")
- break()
+ set("${result_var}" "${_xcrun_out}")
+ endmacro()
+
+ set(xcrun_result)
+ if (CMAKE_${lang}_COMPILER MATCHES "^/usr/bin/(.+)$")
+ _query_xcrun("${CMAKE_MATCH_1}" RESULT_VAR xcrun_result)
+ elseif (CMAKE_${lang}_COMPILER STREQUAL "CMAKE_${lang}_COMPILER-NOTFOUND")
+ foreach(comp ${CMAKE_${lang}_COMPILER_LIST})
+ _query_xcrun("${comp}" RESULT_VAR xcrun_result)
+ if(xcrun_result)
+ break()
+ endif()
+ endforeach()
+ endif()
+ if (xcrun_result)
+ set_property(CACHE CMAKE_${lang}_COMPILER PROPERTY VALUE "${xcrun_result}")
+ endif()
+ endif()
+endmacro()
+
+macro(_cmake_find_compiler_path lang)
+ if(CMAKE_${lang}_COMPILER)
+ # we only get here if CMAKE_${lang}_COMPILER was specified using -D or a pre-made CMakeCache.txt
+ # (e.g. via ctest) or set in CMAKE_TOOLCHAIN_FILE
+ # if CMAKE_${lang}_COMPILER is a list of length 2, use the first item as
+ # CMAKE_${lang}_COMPILER and the 2nd one as CMAKE_${lang}_COMPILER_ARG1
+ list(LENGTH CMAKE_${lang}_COMPILER _CMAKE_${lang}_COMPILER_LIST_LENGTH)
+ if("${_CMAKE_${lang}_COMPILER_LIST_LENGTH}" EQUAL 2)
+ list(GET CMAKE_${lang}_COMPILER 1 CMAKE_${lang}_COMPILER_ARG1)
+ list(GET CMAKE_${lang}_COMPILER 0 CMAKE_${lang}_COMPILER)
+ endif()
+ unset(_CMAKE_${lang}_COMPILER_LIST_LENGTH)
+
+ # find the compiler in the PATH if necessary
+ get_filename_component(_CMAKE_USER_${lang}_COMPILER_PATH "${CMAKE_${lang}_COMPILER}" PATH)
+ if(NOT _CMAKE_USER_${lang}_COMPILER_PATH)
+ find_program(CMAKE_${lang}_COMPILER_WITH_PATH NAMES ${CMAKE_${lang}_COMPILER})
+ if(CMAKE_${lang}_COMPILER_WITH_PATH)
+ set(CMAKE_${lang}_COMPILER ${CMAKE_${lang}_COMPILER_WITH_PATH})
+ get_property(_CMAKE_${lang}_COMPILER_CACHED CACHE CMAKE_${lang}_COMPILER PROPERTY TYPE)
+ if(_CMAKE_${lang}_COMPILER_CACHED)
+ set(CMAKE_${lang}_COMPILER "${CMAKE_${lang}_COMPILER}" CACHE STRING "${lang} compiler" FORCE)
+ endif()
+ unset(_CMAKE_${lang}_COMPILER_CACHED)
endif()
- endforeach()
+ unset(CMAKE_${lang}_COMPILER_WITH_PATH CACHE)
+ endif()
endif()
endmacro()