mgorny created this revision.
mgorny added reviewers: rsmith, vsk.
mgorny added a subscriber: cfe-commits.

Add a cmake check for sys/resource.h and replace the __has_include() check with 
its result, in order to make it possible to use rlimits when building with 
compilers not supporting __has_include() -- i.e. when bootstrapping.

// Please also re-apply dfcd52eb1d8e5d322404b40414cb7331c7380a8c (llvm-config.h 
fix)

https://reviews.llvm.org/D23744

Files:
  CMakeLists.txt
  include/clang/Config/config.h.cmake
  tools/driver/cc1_main.cpp

Index: tools/driver/cc1_main.cpp
===================================================================
--- tools/driver/cc1_main.cpp
+++ tools/driver/cc1_main.cpp
@@ -15,6 +15,7 @@
 
 #include "llvm/Option/Arg.h"
 #include "clang/CodeGen/ObjectFilePCHContainerOperations.h"
+#include "clang/Config/config.h"
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
 #include "clang/Frontend/CompilerInstance.h"
@@ -38,12 +39,9 @@
 #include "llvm/Support/raw_ostream.h"
 #include <cstdio>
 
-#ifdef __has_include
-#if __has_include(<sys/resource.h>)
-#define HAVE_RLIMITS
+#ifdef CLANG_HAVE_RLIMITS
 #include <sys/resource.h>
 #endif
-#endif
 
 using namespace clang;
 using namespace llvm::opt;
@@ -74,7 +72,7 @@
 }
 #endif
 
-#ifdef HAVE_RLIMITS
+#ifdef CLANG_HAVE_RLIMITS
 // The amount of stack we think is "sufficient". If less than this much is
 // available, we may be unable to reach our template instantiation depth
 // limit and other similar limits.
Index: include/clang/Config/config.h.cmake
===================================================================
--- include/clang/Config/config.h.cmake
+++ include/clang/Config/config.h.cmake
@@ -35,6 +35,9 @@
 /* Define if we have libxml2 */
 #cmakedefine CLANG_HAVE_LIBXML ${CLANG_HAVE_LIBXML}
 
+/* Define if we have sys/resource.h (rlimits) */
+#cmakedefine CLANG_HAVE_RLIMITS ${CLANG_HAVE_RLIMITS}
+
 /* The LLVM product name and version */
 #define BACKEND_PACKAGE_STRING "${BACKEND_PACKAGE_STRING}"
 
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -177,6 +177,9 @@
   set(CLANG_HAVE_LIBXML 1)
 endif()
 
+include(CheckIncludeFile)
+check_include_file(sys/resource.h CLANG_HAVE_RLIMITS)
+
 set(CLANG_RESOURCE_DIR "" CACHE STRING
   "Relative directory from the Clang binary to its resource files.")
 


Index: tools/driver/cc1_main.cpp
===================================================================
--- tools/driver/cc1_main.cpp
+++ tools/driver/cc1_main.cpp
@@ -15,6 +15,7 @@
 
 #include "llvm/Option/Arg.h"
 #include "clang/CodeGen/ObjectFilePCHContainerOperations.h"
+#include "clang/Config/config.h"
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
 #include "clang/Frontend/CompilerInstance.h"
@@ -38,12 +39,9 @@
 #include "llvm/Support/raw_ostream.h"
 #include <cstdio>
 
-#ifdef __has_include
-#if __has_include(<sys/resource.h>)
-#define HAVE_RLIMITS
+#ifdef CLANG_HAVE_RLIMITS
 #include <sys/resource.h>
 #endif
-#endif
 
 using namespace clang;
 using namespace llvm::opt;
@@ -74,7 +72,7 @@
 }
 #endif
 
-#ifdef HAVE_RLIMITS
+#ifdef CLANG_HAVE_RLIMITS
 // The amount of stack we think is "sufficient". If less than this much is
 // available, we may be unable to reach our template instantiation depth
 // limit and other similar limits.
Index: include/clang/Config/config.h.cmake
===================================================================
--- include/clang/Config/config.h.cmake
+++ include/clang/Config/config.h.cmake
@@ -35,6 +35,9 @@
 /* Define if we have libxml2 */
 #cmakedefine CLANG_HAVE_LIBXML ${CLANG_HAVE_LIBXML}
 
+/* Define if we have sys/resource.h (rlimits) */
+#cmakedefine CLANG_HAVE_RLIMITS ${CLANG_HAVE_RLIMITS}
+
 /* The LLVM product name and version */
 #define BACKEND_PACKAGE_STRING "${BACKEND_PACKAGE_STRING}"
 
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -177,6 +177,9 @@
   set(CLANG_HAVE_LIBXML 1)
 endif()
 
+include(CheckIncludeFile)
+check_include_file(sys/resource.h CLANG_HAVE_RLIMITS)
+
 set(CLANG_RESOURCE_DIR "" CACHE STRING
   "Relative directory from the Clang binary to its resource files.")
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to