aboutsummaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
Diffstat (limited to 'cmake')
-rw-r--r--cmake/Findlibusb.cmake36
-rw-r--r--cmake/LargeFiles.c15
-rw-r--r--cmake/LargeFiles.cmake107
-rw-r--r--cmake/LargeFiles64.c16
-rw-r--r--cmake/LargeFilesWindows.c8
5 files changed, 182 insertions, 0 deletions
diff --git a/cmake/Findlibusb.cmake b/cmake/Findlibusb.cmake
new file mode 100644
index 0000000..3e21b98
--- /dev/null
+++ b/cmake/Findlibusb.cmake
@@ -0,0 +1,36 @@
+find_path(LIBUSB_INCLUDE_DIR
+ NAMES
+ libusb.h
+ PATHS
+ /usr/local/include
+ /opt/local/include
+ /usr/include
+ PATH_SUFFIXES
+ libusb-1.0
+)
+
+if (libusb_USE_STATIC_LIBS AND NOT MSVC)
+ set (LIBUSB_LIB_PREFIX "lib" CACHE INTERNAL "libusb library name prefix passed to find_library")
+ set (LIBUSB_LIB_SUFFIX ".a" CACHE INTERNAL "libusb library name suffix passed to find_library")
+else (libusb_USE_STATIC_LIBS AND NOT MSVC)
+ set (LIBUSB_LIB_PREFIX "" CACHE INTERNAL "libusb library name prefix passed to find_library")
+ set (LIBUSB_LIB_SUFFIX "" CACHE INTERNAL "libusb library name suffix passed to find_library")
+endif (libusb_USE_STATIC_LIBS AND NOT MSVC)
+
+find_library(LIBUSB_LIBRARY
+ NAMES
+ ${LIBUSB_LIB_PREFIX}usb-1.0${LIBUSB_LIB_SUFFIX} ${LIBUSB_LIB_PREFIX}usb${LIBUSB_LIB_SUFFIX}
+ PATHS
+ /usr/local/lib
+ /opt/local/lib
+ /usr/lib
+)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(libusb REQUIRED_VARS LIBUSB_LIBRARY LIBUSB_INCLUDE_DIR)
+
+if (LIBUSB_FOUND)
+ set(LIBUSB_INCLUDE_DIRS ${LIBUSB_INCLUDE_DIR})
+ set(LIBUSB_LIBRARIES ${LIBUSB_LIBRARY})
+ mark_as_advanced(LIBUSB_INCLUDE_DIR LIBUSB_LIBRARY)
+endif (LIBUSB_FOUND)
diff --git a/cmake/LargeFiles.c b/cmake/LargeFiles.c
new file mode 100644
index 0000000..d11ea97
--- /dev/null
+++ b/cmake/LargeFiles.c
@@ -0,0 +1,15 @@
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+#define VALID_ARRAY_LENGTH 1
+#define INVALID_ARRAY_LENGTH -1
+
+int main(int argc, const char **argv)
+{
+ int a[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? VALID_ARRAY_LENGTH : INVALID_ARRAY_LENGTH];
+ off_t offset = ftello(NULL);
+ fseeko(NULL, offset, SEEK_SET);
+ return 0;
+}
diff --git a/cmake/LargeFiles.cmake b/cmake/LargeFiles.cmake
new file mode 100644
index 0000000..6e60a8d
--- /dev/null
+++ b/cmake/LargeFiles.cmake
@@ -0,0 +1,107 @@
+macro(test_large_files VARIABLE USE_64_SUFFIX)
+ if(NOT DEFINED ${VARIABLE})
+ message(STATUS "Checking if large (64-bit) file support is available...")
+
+ if(USE_64_SUFFIX)
+ set(SUFFIX_64 "64")
+ else(USE_64_SUFFIX)
+ set(SUFFIX_64 "")
+ endif(USE_64_SUFFIX)
+
+ # First try without any macros defined
+ try_compile(LARGE_FILES_SUPPORTED "${CMAKE_BINARY_DIR}"
+ "${CMAKE_MODULE_PATH}/LargeFiles${SUFFIX_64}.c"
+ OUTPUT_VARIABLE TRY_LARGE_FILES_OUTPUT)
+
+ if(VERBOSE_LARGE_FILES)
+ message(STATUS "Large file output (no special flags):\n${TRY_LARGE_FILES_OUTPUT}")
+ endif(VERBOSE_LARGE_FILES)
+
+ if(NOT LARGE_FILES_SUPPORTED)
+ # Try with C macro _FILE_OFFSET_BITS=64
+ try_compile(LARGE_FILES_SUPPORTED "${CMAKE_BINARY_DIR}"
+ "${CMAKE_MODULE_PATH}/LargeFiles${SUFFIX_64}.c"
+ COMPILE_DEFINITIONS "-D_FILE_OFFSET_BITS=64"
+ OUTPUT_VARIABLE TRY_LARGE_FILES_OUTPUT)
+
+ if(VERBOSE_LARGE_FILES)
+ message(STATUS "Large file output (_FILE_OFFSET_BITS=64):\n${TRY_LARGE_FILES_OUTPUT}")
+ endif(VERBOSE_LARGE_FILES)
+
+ if(LARGE_FILES_SUPPORTED)
+ set(_FILE_OFFSET_BITS=64 CACHE INTERNAL "C macro _FILE_OFFSET_BITS=64 is required for 64-bit file support")
+ endif(LARGE_FILES_SUPPORTED)
+ endif(NOT LARGE_FILES_SUPPORTED)
+
+ if(NOT LARGE_FILES_SUPPORTED)
+ # Try with C macro _LARGEFILE_SOURCE
+
+ try_compile(LARGE_FILES_SUPPORTED "${CMAKE_BINARY_DIR}"
+ "${CMAKE_MODULE_PATH}/LargeFiles${SUFFIX_64}.c"
+ COMPILE_DEFINITIONS "-D_LARGEFILE${SUFFIX_64}_SOURCE"
+ OUTPUT_VARIABLE TRY_LARGE_FILES_OUTPUT)
+
+ if(VERBOSE_LARGE_FILES)
+ message(STATUS "Large file output (_LARGEFILE${SUFFIX_64}_SOURCE):\n${TRY_LARGE_FILES_OUTPUT}")
+ endif(VERBOSE_LARGE_FILES)
+
+ if(LARGE_FILES_SUPPORTED)
+ set(_LARGEFILE${SUFFIX_64}_SOURCE=1 CACHE INTERNAL "C macro _LARGEFILE${SUFFIX_64}_SOURCE is required for 64-bit file support")
+ endif(LARGE_FILES_SUPPORTED)
+ endif(NOT LARGE_FILES_SUPPORTED)
+
+ if(NOT LARGE_FILES_SUPPORTED)
+ # Try with both C macro _FILE_OFFSET_BITS=64 and _LARGEFILE_SOURCE
+ try_compile(LARGE_FILES_SUPPORTED "${CMAKE_BINARY_DIR}"
+ "${CMAKE_MODULE_PATH}/LargeFiles${SUFFIX_64}.c"
+ COMPILE_DEFINITIONS "-D_FILE_OFFSET_BITS=64" "-D_LARGEFILE${SUFFIX_64}_SOURCE"
+ OUTPUT_VARIABLE TRY_LARGE_FILES_OUTPUT)
+
+ if(VERBOSE_LARGE_FILES)
+ message(STATUS "Large file output (_FILE_OFFSET_BITS=64 and _LARGEFILE${SUFFIX_64}_SOURCE):\n${TRY_LARGE_FILES_OUTPUT}")
+ endif(VERBOSE_LARGE_FILES)
+
+ if(LARGE_FILES_SUPPORTED)
+ set(_FILE_OFFSET_BITS=64 CACHE INTERNAL "C macro _FILE_OFFSET_BITS=64 is required for 64-bit file support")
+ set(_LARGEFILE${SUFFIX_64}_SOURCE=1 CACHE INTERNAL "C macro _LARGEFILE${SUFFIX_64}_SOURCE is required for 64-bit file support")
+ endif(LARGE_FILES_SUPPORTED)
+ endif(NOT LARGE_FILES_SUPPORTED)
+
+ if(NOT LARGE_FILES_SUPPORTED)
+ # Maybe we are using the Windows C standard library
+ try_compile(LARGE_FILES_SUPPORTED "${CMAKE_BINARY_DIR}"
+ "${CMAKE_MODULE_PATH}/LargeFilesWindows.c")
+ endif(NOT LARGE_FILES_SUPPORTED)
+
+ if(LARGE_FILES_SUPPORTED)
+ message(STATUS "Checking if large (64-bit) file support is available - yes")
+ set(${VARIABLE} 1 CACHE INTERNAL "Is large file support available?")
+ else(LARGE_FILES_SUPPORTED)
+ message(STATUS "Checking if large (64-bit) file support is available - no")
+ set(${VARIABLE} 0 CACHE INTERNAL "Is large file support available?")
+ endif(LARGE_FILES_SUPPORTED)
+ endif(NOT DEFINED ${VARIABLE})
+endmacro(test_large_files VARIABLE USE_64_SUFFIX)
+
+macro(use_large_files TARGET USE_64_SUFFIX)
+ test_large_files(USING_LARGE_FILES ${USE_64_SUFFIX})
+
+ if(USING_LARGE_FILES)
+ if(DEFINED _FILE_OFFSET_BITS)
+ set_property(TARGET ${TARGET}
+ APPEND PROPERTY COMPILE_DEFINITIONS "-D_FILE_OFFSET_BITS=${_FILE_OFFSET_BITS}")
+ endif(DEFINED _FILE_OFFSET_BITS)
+
+ if(DEFINED _LARGEFILE_SOURCE)
+ set_property(TARGET ${TARGET}
+ APPEND PROPERTY COMPILE_DEFINITIONS "-D_LARGEFILE_SOURCE")
+ endif(DEFINED _LARGEFILE_SOURCE)
+
+ if(DEFINED _LARGEFILE64_SOURCE)
+ set_property(TARGET ${TARGET}
+ APPEND PROPERTY COMPILE_DEFINITIONS "-D_LARGEFILE64_SOURCE")
+ endif(DEFINED _LARGEFILE64_SOURCE)
+ else(USING_LARGE_FILES)
+ message(FATAL_ERROR "Large file support not available")
+ endif(USING_LARGE_FILES)
+endmacro(use_large_files TARGET USE_64_SUFFIX)
diff --git a/cmake/LargeFiles64.c b/cmake/LargeFiles64.c
new file mode 100644
index 0000000..479993d
--- /dev/null
+++ b/cmake/LargeFiles64.c
@@ -0,0 +1,16 @@
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stddef.h>
+
+#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+#define VALID_ARRAY_LENGTH 1
+#define INVALID_ARRAY_LENGTH -1
+
+int main(int argc, const char **argv)
+{
+ int a[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? VALID_ARRAY_LENGTH : INVALID_ARRAY_LENGTH];
+ off64_t offset = ftello64(NULL);
+ fseeko64(NULL, offset, SEEK_SET);
+ return 0;
+}
diff --git a/cmake/LargeFilesWindows.c b/cmake/LargeFilesWindows.c
new file mode 100644
index 0000000..85fadd8
--- /dev/null
+++ b/cmake/LargeFilesWindows.c
@@ -0,0 +1,8 @@
+#include <stdio.h>
+
+int main()
+{
+ __int64 off = 0;
+ _fseeki64(NULL, off, SEEK_SET);
+ return 0;
+}