OS X: Resolve compiler in /usr/bin to that reported by Xcode xcrun
The compiler in the PATH on mac is a stub for a different delegate depending on the environment. Rather than requiring xcode-select to change the used Xcode globally, users should be able to choose the compiler per-session. That is possible with the DEVELOPER_DIR environment variable. However, the environment can change between running CMake and invoking the build. In such cases, CMake prefers to record the relevant paths from the environment and use them when invoking the build. That is not currently done for the compilers on APPLE, so the compiler used is not the one reported when running cmake: $ DEVELOPER_DIR=/Applications/Xcode2.app/Contents/Developer/ cc --version Apple LLVM version 6.0 (clang-600.0.51) (based on LLVM 3.5svn) Target: x86_64-apple-darwin13.4.0 Thread model: posix $ DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer/ cc --version Apple LLVM version 5.1 (clang-503.0.38) (based on LLVM 3.4svn) Target: x86_64-apple-darwin13.4.0 Thread model: posix Update that now by querying Xcode for the correct compiler path if the compiler located by ordinary means is located in /usr/bin.
This commit is contained in:
parent
85d3173590
commit
1f085e11e4
|
@ -71,7 +71,7 @@ macro(_cmake_find_compiler lang)
|
||||||
unset(_languages)
|
unset(_languages)
|
||||||
|
|
||||||
# Look for a make tool provided by Xcode
|
# Look for a make tool provided by Xcode
|
||||||
if(CMAKE_${lang}_COMPILER STREQUAL "CMAKE_${lang}_COMPILER-NOTFOUND" AND CMAKE_HOST_APPLE)
|
if(CMAKE_HOST_APPLE)
|
||||||
macro(_query_xcrun compiler_name result_var_keyword result_var)
|
macro(_query_xcrun compiler_name result_var_keyword result_var)
|
||||||
if(NOT "x${result_var_keyword}" STREQUAL "xRESULT_VAR")
|
if(NOT "x${result_var_keyword}" STREQUAL "xRESULT_VAR")
|
||||||
message(FATAL_ERROR "Bad arguments to macro")
|
message(FATAL_ERROR "Bad arguments to macro")
|
||||||
|
@ -81,14 +81,22 @@ macro(_cmake_find_compiler lang)
|
||||||
ERROR_VARIABLE _xcrun_err)
|
ERROR_VARIABLE _xcrun_err)
|
||||||
set("${result_var}" "${_xcrun_out}")
|
set("${result_var}" "${_xcrun_out}")
|
||||||
endmacro()
|
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})
|
foreach(comp ${CMAKE_${lang}_COMPILER_LIST})
|
||||||
_query_xcrun("${comp}" RESULT_VAR _xcrun_result)
|
_query_xcrun("${comp}" RESULT_VAR xcrun_result)
|
||||||
if(_xcrun_result)
|
if(xcrun_result)
|
||||||
set_property(CACHE CMAKE_${lang}_COMPILER PROPERTY VALUE "${_xcrun_result}")
|
|
||||||
break()
|
break()
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
endif()
|
endif()
|
||||||
|
if (xcrun_result)
|
||||||
|
set_property(CACHE CMAKE_${lang}_COMPILER PROPERTY VALUE "${xcrun_result}")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
macro(_cmake_find_compiler_path lang)
|
macro(_cmake_find_compiler_path lang)
|
||||||
|
|
Loading…
Reference in New Issue