macOS: Revert "Resolve compiler in /usr/bin to that reported by Xcode xcrun"

Revert commit 1f085e11e4 (OS X: Resolve compiler in /usr/bin to that
reported by Xcode xcrun, 2015-01-03, v3.2.0-rc1~126^2~1).  The compilers
in Xcode cannot be used by build systems that do not add an `-isysroot`
flag.

Issue: #19180
This commit is contained in:
Brad King
2024-11-06 08:08:08 -05:00
parent 9eb530842c
commit 77fcee9204
2 changed files with 21 additions and 15 deletions

View File

@@ -0,0 +1,13 @@
apple-compiler-selection
------------------------
* On macOS with :ref:`Ninja Generators` and :ref:`Makefile Generators`, when
a compiler is found in ``/usr/bin``, it is now used as-is and is no longer
mapped to the corresponding compiler inside Xcode. The mapping was
introduced by CMake 3.2 to allow build trees to continue to work with their
original compiler even when ``xcode-select`` switches to a different
Xcode installation. However, the compilers inside Xcode cannot be used
without explicit ``-isysroot`` flags and are therefore not suitable for
passing to arbitrary third-party build systems. Furthermore, the mapping
behavior can override user-specified compiler paths. Therefore, this
behavior has been reverted.

View File

@@ -84,7 +84,7 @@ macro(_cmake_find_compiler lang)
unset(_languages)
# Look for a make tool provided by Xcode
if(CMAKE_HOST_APPLE)
if(CMAKE_${lang}_COMPILER STREQUAL "CMAKE_${lang}_COMPILER-NOTFOUND" AND 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")
@@ -95,20 +95,13 @@ macro(_cmake_find_compiler lang)
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 IN LISTS 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()
foreach(comp IN LISTS CMAKE_${lang}_COMPILER_LIST)
_query_xcrun("${comp}" RESULT_VAR xcrun_result)
if(xcrun_result)
set_property(CACHE CMAKE_${lang}_COMPILER PROPERTY VALUE "${xcrun_result}")
break()
endif()
endforeach()
endif()
endmacro()