Przeglądaj źródła

Add test for big endian

Andy Cedilnik 23 lat temu
rodzic
commit
dfb25dd982
2 zmienionych plików z 26 dodań i 0 usunięć
  1. 10 0
      Modules/TestBigEndian.c
  2. 16 0
      Modules/TestBigEndian.cmake

+ 10 - 0
Modules/TestBigEndian.c

@@ -0,0 +1,10 @@
+int main () {
+  /* Are we little or big endian?  From Harbison&Steele.  */
+  union
+  {
+    long l;
+    char c[sizeof (long)];
+  } u;
+  u.l = 1;
+  exit (u.c[sizeof (long) - 1] == 1);
+}

+ 16 - 0
Modules/TestBigEndian.cmake

@@ -0,0 +1,16 @@
+#
+# Check if the system is big endian or little endian
+#
+# VARIABLE - variable to store the result to
+#
+
+MACRO(TEST_BIG_ENDIAN VARIABLE)
+  TRY_RUN(${VARIABLE} HAVE_${VARIABLE}
+          ${PROJECT_BINARY_DIR}
+          ${CMAKE_ROOT}/Modules/TestBigEndian.c
+          OUTPUT_VARIABLE OUTPUT)
+  IF(NOT HAVE_${VARIABLE})
+    WRITE_FILE(${PROJECT_BINARY_DIR}/CMakeError.log 
+      "Determining the endianes of the system failed with the following output:\n${OUTPUT}\n")
+  ENDIF(NOT HAVE_${VARIABLE})
+ENDMACRO(TEST_BIG_ENDIAN)