summaryrefslogtreecommitdiffstats
path: root/Modules/Platform/Darwin.cmake
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2012-09-21 17:18:49 (GMT)
committerBrad King <brad.king@kitware.com>2012-09-21 17:31:46 (GMT)
commit1786b121b40ca0a50a57f44e5e2edef7b9d270ed (patch)
tree89de8ef730d9ea2dc441b08f394fb261df209c9c /Modules/Platform/Darwin.cmake
parent242f673829d40456bd1bcf3f52e10171bccd6868 (diff)
downloadCMake-1786b121b40ca0a50a57f44e5e2edef7b9d270ed.zip
CMake-1786b121b40ca0a50a57f44e5e2edef7b9d270ed.tar.gz
CMake-1786b121b40ca0a50a57f44e5e2edef7b9d270ed.tar.bz2
OS X: Allow CMAKE_OSX_SYSROOT to be a logical SDK name
Xcode supports SDKROOT values that just name an SDK rather than specifying the full path to it. Recognize these values and handle them. For Xcode we just put the value directly in the generated project file. For Makefile generators we ask xcodebuild to provide the full path to the named SDK. Suggested-by: Jason DiCioccio <jd@ods.org>
Diffstat (limited to 'Modules/Platform/Darwin.cmake')
-rw-r--r--Modules/Platform/Darwin.cmake37
1 files changed, 35 insertions, 2 deletions
diff --git a/Modules/Platform/Darwin.cmake b/Modules/Platform/Darwin.cmake
index b160854..56f340d 100644
--- a/Modules/Platform/Darwin.cmake
+++ b/Modules/Platform/Darwin.cmake
@@ -97,7 +97,8 @@ endif()
# Environment variable set by the user overrides our default.
# Use the same environment variable that Xcode uses.
-if(NOT "x$ENV{SDKROOT}" STREQUAL "x" AND EXISTS "$ENV{SDKROOT}")
+if(NOT "x$ENV{SDKROOT}" STREQUAL "x" AND
+ (NOT "x$ENV{SDKROOT}" MATCHES "/" OR IS_DIRECTORY "$ENV{SDKROOT}"))
set(_CMAKE_OSX_SYSROOT_DEFAULT "$ENV{SDKROOT}")
else()
# Find installed SDKs in either Xcode-4.3+ or pre-4.3 SDKs directory.
@@ -127,9 +128,41 @@ else()
endif()
# Set cache variable - end user may change this during ccmake or cmake-gui configure.
-set(CMAKE_OSX_SYSROOT "${_CMAKE_OSX_SYSROOT_DEFAULT}" CACHE PATH
+# Choose the type based on the current value.
+set(_CMAKE_OSX_SYSROOT_TYPE STRING)
+foreach(v CMAKE_OSX_SYSROOT _CMAKE_OSX_SYSROOT_DEFAULT)
+ if("x${${v}}" MATCHES "/")
+ set(_CMAKE_OSX_SYSROOT_TYPE PATH)
+ break()
+ endif()
+endforeach()
+set(CMAKE_OSX_SYSROOT "${_CMAKE_OSX_SYSROOT_DEFAULT}" CACHE ${_CMAKE_OSX_SYSROOT_TYPE}
"The product will be built against the headers and libraries located inside the indicated SDK.")
+# Transform the cached value to something we can use.
+if(CMAKE_OSX_SYSROOT)
+ if("x${CMAKE_OSX_SYSROOT}" MATCHES "/")
+ # This is a path to the SDK. Make sure it exists.
+ if(NOT IS_DIRECTORY "${CMAKE_OSX_SYSROOT}")
+ message(WARNING "Ignoring CMAKE_OSX_SYSROOT value:\n ${CMAKE_OSX_SYSROOT}\n"
+ "because the directory does not exist.")
+ set(CMAKE_OSX_SYSROOT "")
+ endif()
+ elseif(NOT "${CMAKE_GENERATOR}" MATCHES "Xcode")
+ # For non-Xcode generators transform the sdk name into a path.
+ execute_process(
+ COMMAND xcodebuild -sdk ${CMAKE_OSX_SYSROOT} -version Path
+ OUTPUT_VARIABLE _stdout
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ ERROR_VARIABLE _stderr
+ RESULT_VARIABLE _failed
+ )
+ if(NOT _failed AND IS_DIRECTORY "${_stdout}")
+ set(CMAKE_OSX_SYSROOT "${_stdout}")
+ endif()
+ endif()
+endif()
+
#----------------------------------------------------------------------------
function(SanityCheckSDKAndDeployTarget _sdk_path _deploy)
if(_deploy STREQUAL "")