Make it possible to include llvm-c without including C++ headers. Patch by Filip Pizlo.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@178713 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/llvm-c/Core.h b/include/llvm-c/Core.h
index e85fb97..cc78b2e 100644
--- a/include/llvm-c/Core.h
+++ b/include/llvm-c/Core.h
@@ -17,14 +17,15 @@
 
 #include "llvm/Support/DataTypes.h"
 
-#ifdef __cplusplus
-
+#if defined(__cplusplus) && !defined(LLVM_DO_NOT_INCLUDE_CPP_HEADERS)
 /* Need these includes to support the LLVM 'cast' template for the C++ 'wrap' 
    and 'unwrap' conversion functions. */
 #include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/Module.h"
 #include "llvm/PassRegistry.h"
+#endif /* defined(__cplusplus) && !defined(LLVM_DO_NOT_INCLUDE_CPP_HEADERS) */
 
+#ifdef __cplusplus
 extern "C" {
 #endif
 
@@ -2669,7 +2670,9 @@
 
 #ifdef __cplusplus
 }
+#endif
 
+#if defined(__cplusplus) && !defined(LLVM_DO_NOT_INCLUDE_CPP_HEADERS)
 namespace llvm {
   class MemoryBuffer;
   class PassManagerBase;
@@ -2763,6 +2766,6 @@
   }
 }
 
-#endif /* !defined(__cplusplus) */
+#endif /* defined(__cplusplus) && !defined(LLVM_DO_NOT_INCLUDE_CPP_HEADERS) */
 
-#endif /* !defined(LLVM_C_CORE_H) */
+#endif /* defined(LLVM_C_CORE_H) */
diff --git a/include/llvm-c/ExecutionEngine.h b/include/llvm-c/ExecutionEngine.h
index cb77bb2..6ca316c 100644
--- a/include/llvm-c/ExecutionEngine.h
+++ b/include/llvm-c/ExecutionEngine.h
@@ -138,7 +138,9 @@
 
 #ifdef __cplusplus
 }
+#endif
 
+#if defined(__cplusplus) && !defined(LLVM_DO_NOT_INCLUDE_CPP_HEADERS)
 namespace llvm {
   struct GenericValue;
   class ExecutionEngine;
@@ -157,7 +159,6 @@
   
   #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
 }
-  
-#endif /* defined(__cplusplus) */
+#endif /* defined(__cplusplus) && !defined(LLVM_DO_NOT_INCLUDE_CPP_HEADERS) */
 
 #endif
diff --git a/include/llvm-c/Object.h b/include/llvm-c/Object.h
index e2dad62..b6fe17a 100644
--- a/include/llvm-c/Object.h
+++ b/include/llvm-c/Object.h
@@ -22,9 +22,11 @@
 #include "llvm-c/Core.h"
 #include "llvm/Config/llvm-config.h"
 
-#ifdef __cplusplus
+#if defined(__cplusplus) && !defined(LLVM_DO_NOT_INCLUDE_CPP_HEADERS)
 #include "llvm/Object/ObjectFile.h"
+#endif /* defined(__cplusplus) && !defined(LLVM_DO_NOT_INCLUDE_CPP_HEADERS) */
 
+#ifdef __cplusplus
 extern "C" {
 #endif
 
@@ -99,7 +101,9 @@
 
 #ifdef __cplusplus
 }
+#endif
 
+#if defined(__cplusplus) && !defined(LLVM_DO_NOT_INCLUDE_CPP_HEADERS)
 namespace llvm {
   namespace object {
     inline ObjectFile *unwrap(LLVMObjectFileRef OF) {
@@ -142,8 +146,8 @@
 
   }
 }
+#endif /* defined(__cplusplus) && !defined(LLVM_DO_NOT_INCLUDE_CPP_HEADERS) */
 
-#endif /* defined(__cplusplus) */
 
 #endif
 
diff --git a/include/llvm-c/Target.h b/include/llvm-c/Target.h
index 57abfa0..0327c04 100644
--- a/include/llvm-c/Target.h
+++ b/include/llvm-c/Target.h
@@ -235,7 +235,9 @@
 
 #ifdef __cplusplus
 }
+#endif
 
+#if defined(__cplusplus) && !defined(LLVM_DO_NOT_INCLUDE_CPP_HEADERS)
 namespace llvm {
   class DataLayout;
   class TargetLibraryInfo;
@@ -257,7 +259,6 @@
     return reinterpret_cast<LLVMTargetLibraryInfoRef>(X);
   }
 }
-
-#endif /* defined(__cplusplus) */
+#endif /* defined(__cplusplus) && !defined(LLVM_DO_NOT_INCLUDE_CPP_HEADERS) */
 
 #endif
diff --git a/include/llvm-c/TargetMachine.h b/include/llvm-c/TargetMachine.h
index 691abdf..e6f477a 100644
--- a/include/llvm-c/TargetMachine.h
+++ b/include/llvm-c/TargetMachine.h
@@ -119,7 +119,9 @@
 
 #ifdef __cplusplus
 }
+#endif
 
+#if defined(__cplusplus) && !defined(LLVM_DO_NOT_INCLUDE_CPP_HEADERS)
 namespace llvm {
   class TargetMachine;
   class Target;
@@ -138,6 +140,6 @@
     return reinterpret_cast<LLVMTargetRef>(const_cast<Target*>(P));
   }
 }
-#endif
+#endif /* defined(__cplusplus) && !defined(LLVM_DO_NOT_INCLUDE_CPP_HEADERS) */
 
 #endif
diff --git a/include/llvm-c/Transforms/PassManagerBuilder.h b/include/llvm-c/Transforms/PassManagerBuilder.h
index 82e513d..b39dd24 100644
--- a/include/llvm-c/Transforms/PassManagerBuilder.h
+++ b/include/llvm-c/Transforms/PassManagerBuilder.h
@@ -18,8 +18,11 @@
 
 typedef struct LLVMOpaquePassManagerBuilder *LLVMPassManagerBuilderRef;
 
-#ifdef __cplusplus
+#if defined(__cplusplus) && !defined(LLVM_DO_NOT_INCLUDE_CPP_HEADERS)
 #include "llvm/Transforms/IPO/PassManagerBuilder.h"
+#endif
+
+#ifdef __cplusplus
 extern "C" {
 #endif
 
@@ -86,7 +89,9 @@
 
 #ifdef __cplusplus
 }
+#endif
 
+#if defined(__cplusplus) && !defined(LLVM_DO_NOT_INCLUDE_CPP_HEADERS)
 namespace llvm {
   inline PassManagerBuilder *unwrap(LLVMPassManagerBuilderRef P) {
     return reinterpret_cast<PassManagerBuilder*>(P);
@@ -96,6 +101,6 @@
     return reinterpret_cast<LLVMPassManagerBuilderRef>(P);
   }
 }
-#endif
+#endif /* defined(__cplusplus) && !defined(LLVM_DO_NOT_INCLUDE_CPP_HEADERS) */
 
 #endif