瀏覽代碼

CMake: Handle endian.h locations on other platforms

Gbp-Dch: ignore
Julian Andres Klode 10 年之前
父節點
當前提交
b10ec8cc7b
共有 3 個文件被更改,包括 27 次插入0 次删除
  1. 6 0
      CMake/config.h.in
  2. 9 0
      CMake/endian.h.in
  3. 12 0
      CMakeLists.txt

+ 6 - 0
CMake/config.h.in

@@ -25,6 +25,12 @@
 /* Define if we have sys/mount.h */
 #cmakedefine HAVE_MOUNT_H
 
+/* Define if we have sys/endian.h */
+#cmakedefine HAVE_SYS_ENDIAN_H
+
+/* Define if we have machine/endian.h */
+#cmakedefine HAVE_MACHINE_ENDIAN_H
+
 /* Define if we have enabled pthread support */
 #cmakedefine HAVE_PTHREAD
 

+ 9 - 0
CMake/endian.h.in

@@ -0,0 +1,9 @@
+#include <config.h>
+
+#ifdef HAVE_MACHINE_ENDIAN_H
+#include <machine/endian.h>
+#endif
+#ifdef HAVE_SYS_ENDIAN_H
+#include <sys/types.h>
+#include <sys/endian.h>
+#endif

+ 12 - 0
CMakeLists.txt

@@ -118,6 +118,18 @@ if (CMAKE_USE_PTHREADS_INIT)
   set(HAVE_PTHREAD 1)
 endif()
 
+CHECK_INCLUDE_FILES(machine/endian.h HAVE_MACHINE_ENDIAN_H)
+CHECK_INCLUDE_FILES(sys/endian.h HAVE_SYS_ENDIAN_H)
+CHECK_INCLUDE_FILES(endian.h HAVE_ENDIAN_H)
+if (NOT HAVE_ENDIAN_H)
+  if (HAVE_MACHINE_ENDIAN_H OR HAVE_SYS_ENDIAN_H)
+    configure_file(CMake/endian.h.in ${PROJECT_BINARY_DIR}/include/endian.h)
+  else()
+    message(FATAL_ERROR "Cannot find endian.h")
+  endif()
+endif()
+
+
 include(CheckTypeSize)
 set(CMAKE_EXTRA_INCLUDE_FILES "signal.h")
 check_type_size("sig_t" SIG_T LANGUAGE "CXX")