[cfe-commits] r138892 - /cfe/trunk/lib/Driver/ToolChains.cpp

Chad Rosier mcrosier at apple.com
Wed Aug 31 13:56:25 PDT 2011


Author: mcrosier
Date: Wed Aug 31 15:56:25 2011
New Revision: 138892

URL: http://llvm.org/viewvc/llvm-project?rev=138892&view=rev
Log:
[driver] If no -miphoneos-version-min is specified on the command line *and*
IPHONEOS_DEPLOYMENT_TARGET if undefined, set -miphoneos-version-min based on 
isysroot.

Modified:
    cfe/trunk/lib/Driver/ToolChains.cpp

Modified: cfe/trunk/lib/Driver/ToolChains.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=138892&r1=138891&r2=138892&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains.cpp Wed Aug 31 15:56:25 2011
@@ -493,21 +493,6 @@
   Arg *iOSSimVersion = Args.getLastArg(
     options::OPT_mios_simulator_version_min_EQ);
 
-  // If no '-miphoneos-version-min' specified, see if we can set the default
-  // based on isysroot.
-  if (!iOSVersion) {
-    if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
-      StringRef first, second;
-      StringRef isysroot = A->getValue(Args);
-      llvm::tie(first, second) = isysroot.split(StringRef("SDKs/iPhoneOS"));
-      if (second != "") {
-        const Option *O = Opts.getOption(options::OPT_miphoneos_version_min_EQ);
-        iOSVersion = Args.MakeJoinedArg(0, O, second.substr(0,3));
-        Args.append(iOSVersion);
-      }
-    }
-  }
-
   // FIXME: HACK! When compiling for the simulator we don't get a
   // '-miphoneos-version-min' to help us know whether there is an ARC runtime
   // or not; try to parse a __IPHONE_OS_VERSION_MIN_REQUIRED
@@ -539,51 +524,62 @@
           << iOSSimVersion->getAsString(Args);
     iOSSimVersion = 0;
   } else if (!OSXVersion && !iOSVersion && !iOSSimVersion) {
-    // If not deployment target was specified on the command line, check for
+    // If no deployment target was specified on the command line, check for
     // environment defines.
-    const char *OSXTarget = ::getenv("MACOSX_DEPLOYMENT_TARGET");
-    const char *iOSTarget = ::getenv("IPHONEOS_DEPLOYMENT_TARGET");
-    const char *iOSSimTarget = ::getenv("IOS_SIMULATOR_DEPLOYMENT_TARGET");
-
-    // Ignore empty strings.
-    if (OSXTarget && OSXTarget[0] == '\0')
-      OSXTarget = 0;
-    if (iOSTarget && iOSTarget[0] == '\0')
-      iOSTarget = 0;
-    if (iOSSimTarget && iOSSimTarget[0] == '\0')
-      iOSSimTarget = 0;
+    StringRef OSXTarget;
+    StringRef iOSTarget;
+    StringRef iOSSimTarget;
+    if (char *env = ::getenv("MACOSX_DEPLOYMENT_TARGET"))
+      OSXTarget = env;
+    if (char *env = ::getenv("IPHONEOS_DEPLOYMENT_TARGET"))
+      iOSTarget = env;
+    if (char *env = ::getenv("IOS_SIMULATOR_DEPLOYMENT_TARGET"))
+      iOSSimTarget = env;
+
+    // If no '-miphoneos-version-min' specified on the command line and 
+    // IPHONEOS_DEPLOYMENT_TARGET is not defined, see if we can set the default
+    // based on isysroot.
+    if (iOSTarget.empty()) {
+      if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
+        StringRef first, second;
+        StringRef isysroot = A->getValue(Args);
+        llvm::tie(first, second) = isysroot.split(StringRef("SDKs/iPhoneOS"));
+        if (second != "")
+          iOSTarget = second.substr(0,3);
+      }
+    }
 
     // Handle conflicting deployment targets
     //
     // FIXME: Don't hardcode default here.
 
     // Do not allow conflicts with the iOS simulator target.
-    if (iOSSimTarget && (OSXTarget || iOSTarget)) {
+    if (!iOSSimTarget.empty() && (!OSXTarget.empty() || !iOSTarget.empty())) {
       getDriver().Diag(diag::err_drv_conflicting_deployment_targets)
         << "IOS_SIMULATOR_DEPLOYMENT_TARGET"
-        << (OSXTarget ? "MACOSX_DEPLOYMENT_TARGET" :
+        << (!OSXTarget.empty() ? "MACOSX_DEPLOYMENT_TARGET" :
             "IPHONEOS_DEPLOYMENT_TARGET");
     }
 
     // Allow conflicts among OSX and iOS for historical reasons, but choose the
     // default platform.
-    if (OSXTarget && iOSTarget) {
+    if (!OSXTarget.empty() && !iOSTarget.empty()) {
       if (getTriple().getArch() == llvm::Triple::arm ||
           getTriple().getArch() == llvm::Triple::thumb)
-        OSXTarget = 0;
+        OSXTarget = "";
       else
-        iOSTarget = 0;
+        iOSTarget = "";
     }
 
-    if (OSXTarget) {
+    if (!OSXTarget.empty()) {
       const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ);
       OSXVersion = Args.MakeJoinedArg(0, O, OSXTarget);
       Args.append(OSXVersion);
-    } else if (iOSTarget) {
+    } else if (!iOSTarget.empty()) {
       const Option *O = Opts.getOption(options::OPT_miphoneos_version_min_EQ);
       iOSVersion = Args.MakeJoinedArg(0, O, iOSTarget);
       Args.append(iOSVersion);
-    } else if (iOSSimTarget) {
+    } else if (!iOSSimTarget.empty()) {
       const Option *O = Opts.getOption(
         options::OPT_mios_simulator_version_min_EQ);
       iOSSimVersion = Args.MakeJoinedArg(0, O, iOSSimTarget);





More information about the cfe-commits mailing list