summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJörg Mayer <jmayer@loplof.de>2013-07-23 09:40:21 +0000
committerJörg Mayer <jmayer@loplof.de>2013-07-23 09:40:21 +0000
commit1cbd49e61b022970dc7a24fefd6a6f8fba69eac5 (patch)
treef82678ef6135d90c2b0aa0fee55f6925f4798fa4
parentd937adcc9ee07dde8c96f17b9c54fbba37fb45ba (diff)
downloadwireshark-1cbd49e61b022970dc7a24fefd6a6f8fba69eac5.tar.gz
Copy over cmake largfile detection from the gromacs project.
svn path=/trunk/; revision=50824
-rw-r--r--cmake/TestFileOffsetBits.c17
-rw-r--r--cmake/TestLargeFiles.c.cmakein31
-rw-r--r--cmake/modules/gmxTestLargeFiles.cmake125
3 files changed, 173 insertions, 0 deletions
diff --git a/cmake/TestFileOffsetBits.c b/cmake/TestFileOffsetBits.c
new file mode 100644
index 0000000000..9a9dcfd182
--- /dev/null
+++ b/cmake/TestFileOffsetBits.c
@@ -0,0 +1,17 @@
+/* This code was copied from http://www.gromacs.org/
+ * and its toplevel COPYING file starts with:
+ *
+ * GROMACS is free software, distributed under the GNU General Public License
+ * (GPL) Version 2.
+ */
+
+#include <sys/types.h>
+
+int main(int argc, char **argv)
+{
+ /* Cause a compile-time error if off_t is smaller than 64 bits */
+#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+ int off_t_is_large[ (LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1 ];
+ return 0;
+}
+
diff --git a/cmake/TestLargeFiles.c.cmakein b/cmake/TestLargeFiles.c.cmakein
new file mode 100644
index 0000000000..53a1f614e6
--- /dev/null
+++ b/cmake/TestLargeFiles.c.cmakein
@@ -0,0 +1,31 @@
+/* This code was copied from http://www.gromacs.org/
+ * and its toplevel COPYING file starts with:
+ *
+ * GROMACS is free software, distributed under the GNU General Public License
+ * (GPL) Version 2.
+ */
+
+#cmakedefine _LARGEFILE_SOURCE
+#cmakedefine _LARGEFILE64_SOURCE
+#cmakedefine _LARGE_FILES
+#cmakedefine _FILE_OFFSET_BITS @_FILE_OFFSET_BITS@
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int argc, char **argv)
+{
+ /* Cause a compile-time error if off_t is smaller than 64 bits,
+ * and make sure we have ftello / fseeko.
+ */
+#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+ int off_t_is_large[ (LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1 ];
+ FILE *fp = fopen(argv[0],"r");
+ off_t offset = ftello( fp );
+
+ fseeko( fp, offset, SEEK_CUR );
+ fclose(fp);
+ return 0;
+}
+
diff --git a/cmake/modules/gmxTestLargeFiles.cmake b/cmake/modules/gmxTestLargeFiles.cmake
new file mode 100644
index 0000000000..e7593e9924
--- /dev/null
+++ b/cmake/modules/gmxTestLargeFiles.cmake
@@ -0,0 +1,125 @@
+# This code was copied from http://www.gromacs.org/
+# and its toplevel COPYING file starts with:
+#
+# GROMACS is free software, distributed under the GNU General Public License
+# (GPL) Version 2.
+
+# - Define macro to check large file support
+#
+# GMX_TEST_LARGE_FILES(VARIABLE)
+#
+# VARIABLE will be set to true if off_t is 64 bits, and fseeko/ftello present.
+# This macro will also set defines necessary enable large file support, for instance
+# _LARGE_FILES
+# _LARGEFILE_SOURCE
+# _FILE_OFFSET_BITS 64
+#
+# However, it is YOUR job to make sure these defines are set in a cmakedefine so they
+# end up in a config.h file that is included in your source if necessary!
+
+MACRO(GMX_TEST_LARGE_FILES VARIABLE)
+ IF(NOT DEFINED ${VARIABLE})
+
+ # On most platforms it is probably overkill to first test the flags for 64-bit off_t,
+ # and then separately fseeko. However, in the future we might have 128-bit filesystems
+ # (ZFS), so it might be dangerous to indiscriminately set e.g. _FILE_OFFSET_BITS=64.
+
+ MESSAGE(STATUS "Checking for 64-bit off_t")
+
+ # First check without any special flags
+ TRY_COMPILE(FILE64_OK "${CMAKE_BINARY_DIR}"
+ "${CMAKE_SOURCE_DIR}/cmake/TestFileOffsetBits.c")
+ if(FILE64_OK)
+ MESSAGE(STATUS "Checking for 64-bit off_t - present")
+ endif(FILE64_OK)
+
+ if(NOT FILE64_OK)
+ # Test with _FILE_OFFSET_BITS=64
+ TRY_COMPILE(FILE64_OK "${CMAKE_BINARY_DIR}"
+ "${CMAKE_SOURCE_DIR}/cmake/TestFileOffsetBits.c"
+ COMPILE_DEFINITIONS "-D_FILE_OFFSET_BITS=64" )
+ if(FILE64_OK)
+ MESSAGE(STATUS "Checking for 64-bit off_t - present with _FILE_OFFSET_BITS=64")
+ set(_FILE_OFFSET_BITS 64 CACHE INTERNAL "64-bit off_t requires _FILE_OFFSET_BITS=64")
+ endif(FILE64_OK)
+ endif(NOT FILE64_OK)
+
+ if(NOT FILE64_OK)
+ # Test with _LARGE_FILES
+ TRY_COMPILE(FILE64_OK "${CMAKE_BINARY_DIR}"
+ "${CMAKE_SOURCE_DIR}/cmake/TestFileOffsetBits.c"
+ COMPILE_DEFINITIONS "-D_LARGE_FILES" )
+ if(FILE64_OK)
+ MESSAGE(STATUS "Checking for 64-bit off_t - present with _LARGE_FILES")
+ set(_LARGE_FILES 1 CACHE INTERNAL "64-bit off_t requires _LARGE_FILES")
+ endif(FILE64_OK)
+ endif(NOT FILE64_OK)
+
+ if(NOT FILE64_OK)
+ # Test with _LARGEFILE_SOURCE
+ TRY_COMPILE(FILE64_OK "${CMAKE_BINARY_DIR}"
+ "${CMAKE_SOURCE_DIR}/cmake/TestFileOffsetBits.c"
+ COMPILE_DEFINITIONS "-D_LARGEFILE_SOURCE" )
+ if(FILE64_OK)
+ MESSAGE(STATUS "Checking for 64-bit off_t - present with _LARGEFILE_SOURCE")
+ set(_LARGEFILE_SOURCE 1 CACHE INTERNAL "64-bit off_t requires _LARGEFILE_SOURCE")
+ endif(FILE64_OK)
+ endif(NOT FILE64_OK)
+
+ if(NOT FILE64_OK)
+ # now check for Windows stuff
+ TRY_COMPILE(FILE64_OK "${CMAKE_BINARY_DIR}"
+ "${CMAKE_SOURCE_DIR}/cmake/TestWindowsFSeek.c")
+ if(FILE64_OK)
+ MESSAGE(STATUS "Checking for 64-bit off_t - present with _fseeki64")
+ set(HAVE__FSEEKI64 1 CACHE INTERNAL "64-bit off_t requires _fseeki64")
+ endif(FILE64_OK)
+ endif(NOT FILE64_OK)
+
+ if(NOT FILE64_OK)
+ MESSAGE(STATUS "Checking for 64-bit off_t - not present")
+ else(NOT FILE64_OK)
+
+ # Set the flags we might have determined to be required above
+ configure_file("${CMAKE_SOURCE_DIR}/cmake/TestLargeFiles.c.cmakein"
+ "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestLargeFiles.c")
+
+ MESSAGE(STATUS "Checking for fseeko/ftello")
+ # Test if ftello/fseeko are available
+ TRY_COMPILE(FSEEKO_COMPILE_OK "${CMAKE_BINARY_DIR}"
+ "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestLargeFiles.c")
+ if(FSEEKO_COMPILE_OK)
+ MESSAGE(STATUS "Checking for fseeko/ftello - present")
+ endif(FSEEKO_COMPILE_OK)
+
+ if(NOT FSEEKO_COMPILE_OK)
+ # glibc 2.2 neds _LARGEFILE_SOURCE for fseeko (but not 64-bit off_t...)
+ TRY_COMPILE(FSEEKO_COMPILE_OK "${CMAKE_BINARY_DIR}"
+ "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestLargeFiles.c"
+ COMPILE_DEFINITIONS "-D_LARGEFILE_SOURCE" )
+ if(FSEEKO_COMPILE_OK)
+ MESSAGE(STATUS "Checking for fseeko/ftello - present with _LARGEFILE_SOURCE")
+ set(_LARGEFILE_SOURCE 1 CACHE INTERNAL "64-bit fseeko requires _LARGEFILE_SOURCE")
+ endif(FSEEKO_COMPILE_OK)
+ endif(NOT FSEEKO_COMPILE_OK)
+
+ endif(NOT FILE64_OK)
+
+ if(FSEEKO_COMPILE_OK)
+ SET(${VARIABLE} 1 CACHE INTERNAL "Result of test for large file support" FORCE)
+ set(HAVE_FSEEKO 1 CACHE INTERNAL "64bit fseeko is available" FORCE)
+ else(FSEEKO_COMPILE_OK)
+ if (HAVE__FSEEKI64)
+ SET(${VARIABLE} 1 CACHE INTERNAL "Result of test for large file support" FORCE)
+ SET(HAVE__FSEEKI64 1 CACHE INTERNAL "Windows 64-bit fseek" FORCE)
+ else (HAVE__FSEEKI64)
+ MESSAGE(STATUS "Checking for fseeko/ftello - not found")
+ SET(${VARIABLE} 0 CACHE INTERNAL "Result of test for large file support" FORCE)
+ endif (HAVE__FSEEKI64)
+ endif(FSEEKO_COMPILE_OK)
+
+ ENDIF(NOT DEFINED ${VARIABLE})
+ENDMACRO(GMX_TEST_LARGE_FILES VARIABLE)
+
+
+