[patch][cmake] get host OS X version "10.X"

David Fang fang at csl.cornell.edu
Fri Feb 28 11:33:32 PST 2014


Hi,
 	I've been using this patch to get host OS X version for 
conditionalizing other cmake pieces on darwin version.  (For my nefarious 
purposes of keeping darwin8 alive.)
 	Any interest in this patch?

David

-- 
David Fang
http://www.csl.cornell.edu/~fang/
-------------- next part --------------
diff --git a/cmake/config-ix.cmake b/cmake/config-ix.cmake
index 5b945d1..7be8915 100755
--- a/cmake/config-ix.cmake
+++ b/cmake/config-ix.cmake
@@ -346,6 +346,12 @@ get_host_triple(LLVM_INFERRED_HOST_TRIPLE)
 set(LLVM_HOST_TRIPLE "${LLVM_INFERRED_HOST_TRIPLE}" CACHE STRING
     "Host on which LLVM binaries will run")
 
+if( APPLE )
+get_host_osx_version(LLVM_INFERRED_OSX_VERSION)
+set(LLVM_HOST_OSX_VERSION "${LLVM_INFERRED_OSX_VERSION}" CACHE STRING
+    "Host version of Mac OS X")
+endif( APPLE )
+
 # Determine the native architecture.
 string(TOLOWER "${LLVM_TARGET_ARCH}" LLVM_NATIVE_ARCH)
 if( LLVM_NATIVE_ARCH STREQUAL "host" )
diff --git a/cmake/modules/GetHostTriple.cmake b/cmake/modules/GetHostTriple.cmake
index 671a8ce..37caa10 100644
--- a/cmake/modules/GetHostTriple.cmake
+++ b/cmake/modules/GetHostTriple.cmake
@@ -28,3 +28,15 @@ function( get_host_triple var )
   set( ${var} ${value} PARENT_SCOPE )
   message(STATUS "Target triple: ${value}")
 endfunction( get_host_triple var )
+
+# Mac OS X only: get the host version, like "10.x"
+function( get_host_osx_version var )
+  if( APPLE )
+    execute_process(COMMAND sw_vers -productVersion COMMAND cut -d. -f1-2
+      RESULT_VARIABLE TT_RV
+      OUTPUT_VARIABLE value
+      OUTPUT_STRIP_TRAILING_WHITESPACE)
+    set( ${var} ${value} PARENT_SCOPE )
+    message(STATUS "Host OS X version: ${value}")
+  endif ( APPLE )
+endfunction( get_host_osx_version var )


More information about the llvm-commits mailing list