An easy case where GCC should really be able to work out that the value is only
[oota-llvm.git] / tools / llvm-config / llvm-config.cpp
index 4b6179904afee46b0ce8db6a2e64fd6786e549c9..79fd7f8c5aec5636b430914d2e73ca490861b2cc 100644 (file)
@@ -25,7 +25,6 @@
 #include "llvm/Config/llvm-config.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
-#include "llvm/Support/TargetRegistry.h"
 #include "llvm/Support/raw_ostream.h"
 #include <cstdlib>
 #include <set>
@@ -170,7 +169,8 @@ int main(int argc, char **argv) {
   // and from an installed path. We try and auto-detect which case we are in so
   // that we can report the correct information when run from a development
   // tree.
-  bool IsInDevelopmentTree, DevelopmentTreeLayoutIsCMakeStyle;
+  bool IsInDevelopmentTree;
+  enum { MakefileStyle, CMakeStyle, CMakeBuildModeStyle } DevelopmentTreeLayout;
   llvm::SmallString<256> CurrentPath(GetExecutablePath(argv[0]).str());
   std::string CurrentExecPrefix;
   std::string ActiveObjRoot;
@@ -186,7 +186,7 @@ int main(int argc, char **argv) {
   // symbolic links, but is good enough.
   if (CurrentExecPrefix == std::string(LLVM_OBJ_ROOT) + "/" + LLVM_BUILDMODE) {
     IsInDevelopmentTree = true;
-    DevelopmentTreeLayoutIsCMakeStyle = false;
+    DevelopmentTreeLayout = MakefileStyle;
 
     // If we are in a development tree, then check if we are in a BuildTools
     // directory. This indicates we are built for the build triple, but we
@@ -196,12 +196,17 @@ int main(int argc, char **argv) {
     } else {
       ActiveObjRoot = LLVM_OBJ_ROOT;
     }
+  } else if (CurrentExecPrefix == std::string(LLVM_OBJ_ROOT)) {
+    IsInDevelopmentTree = true;
+    DevelopmentTreeLayout = CMakeStyle;
+    ActiveObjRoot = LLVM_OBJ_ROOT;
   } else if (CurrentExecPrefix == std::string(LLVM_OBJ_ROOT) + "/bin") {
     IsInDevelopmentTree = true;
-    DevelopmentTreeLayoutIsCMakeStyle = true;
+    DevelopmentTreeLayout = CMakeBuildModeStyle;
     ActiveObjRoot = LLVM_OBJ_ROOT;
   } else {
     IsInDevelopmentTree = false;
+    DevelopmentTreeLayout = MakefileStyle; // Initialized to avoid warnings.
   }
 
   // Compute various directory locations based on the derived location
@@ -214,12 +219,19 @@ int main(int argc, char **argv) {
 
     // CMake organizes the products differently than a normal prefix style
     // layout.
-    if (DevelopmentTreeLayoutIsCMakeStyle) {
-      ActiveBinDir = ActiveObjRoot + "/bin/" + LLVM_BUILDMODE;
-      ActiveLibDir = ActiveObjRoot + "/lib/" + LLVM_BUILDMODE;
-    } else {
+    switch (DevelopmentTreeLayout) {
+    case MakefileStyle:
       ActiveBinDir = ActiveObjRoot + "/" + LLVM_BUILDMODE + "/bin";
       ActiveLibDir = ActiveObjRoot + "/" + LLVM_BUILDMODE + "/lib";
+      break;
+    case CMakeStyle:
+      ActiveBinDir = ActiveObjRoot + "/bin";
+      ActiveLibDir = ActiveObjRoot + "/lib";
+      break;
+    case CMakeBuildModeStyle:
+      ActiveBinDir = ActiveObjRoot + "/bin/" + LLVM_BUILDMODE;
+      ActiveLibDir = ActiveObjRoot + "/lib/" + LLVM_BUILDMODE;
+      break;
     }
 
     // We need to include files from both the source and object trees.
@@ -271,14 +283,7 @@ int main(int argc, char **argv) {
         }
         OS << '\n';
       } else if (Arg == "--targets-built") {
-        bool First = true;
-        for (TargetRegistry::iterator I = TargetRegistry::begin(),
-               E = TargetRegistry::end(); I != E; First = false, ++I) {
-          if (!First)
-            OS << ' ';
-          OS << I->getName();
-        }
-        OS << '\n';
+        OS << LLVM_TARGETS_BUILT << '\n';
       } else if (Arg == "--host-target") {
         OS << LLVM_DEFAULT_TARGET_TRIPLE << '\n';
       } else if (Arg == "--build-mode") {