1include(CheckIncludeFiles) 2include(CheckIncludeFile) 3include(CheckSymbolExists) 4include(CheckTypeSize) 5include(CheckFunctionKeywords) 6include(CheckLFS) 7 8## Checks for header files ## 9check_include_file("inttypes.h" HAVE_INTTYPES_H) 10check_include_file("memory.h" HAVE_MEMORY_H) 11check_include_file("stddef.h" HAVE_STDDEF_H) 12check_include_file("stdint.h" HAVE_STDINT_H) 13check_include_file("stdlib.h" HAVE_STDLIB_H) 14check_include_file("string.h" HAVE_STRING_H) 15check_include_file("strings.h" HAVE_STRINGS_H) 16check_include_file("sys/types.h" HAVE_SYS_TYPES_H) 17if(HAVE_INTTYPES_H) 18 set(INCFILE "#include <inttypes.h>") 19elseif(HAVE_STDINT_H) 20 set(INCFILE "#include <stdint.h>") 21else(HAVE_INTTYPES_H) 22 set(INCFILE "") 23endif(HAVE_INTTYPES_H) 24 25## create configuration files from .cmake file ## 26if(BUILD_EXAMPLES) 27 ## Checks for WinIO ## 28 if(WIN32) 29 check_include_file("io.h" HAVE_IO_H) 30 check_include_file("fcntl.h" HAVE_FCNTL_H) 31 check_symbol_exists("_setmode" "io.h;fcntl.h" HAVE__SETMODE) 32 if(NOT HAVE__SETMODE) 33 check_symbol_exists("setmode" "io.h;fcntl.h" HAVE_SETMODE) 34 endif(NOT HAVE__SETMODE) 35 check_symbol_exists("_fileno" "stdio.h" HAVE__FILENO) 36 check_symbol_exists("fopen_s" "stdio.h" HAVE_FOPEN_S) 37 check_symbol_exists("_O_BINARY" "fcntl.h" HAVE__O_BINARY) 38 endif(WIN32) 39 40 ## Checks for large file support ## 41 check_lfs(WITH_LFS) 42 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/lfs.h.cmake" "${CMAKE_CURRENT_BINARY_DIR}/lfs.h" @ONLY) 43endif(BUILD_EXAMPLES) 44 45## generate config.h ## 46check_function_keywords("inline;__inline;__inline__;__declspec(dllexport);__declspec(dllimport)") 47if(HAVE_INLINE) 48 set(INLINE "inline") 49elseif(HAVE___INLINE) 50 set(INLINE "__inline") 51elseif(HAVE___INLINE__) 52 set(INLINE "__inline__") 53else(HAVE_INLINE) 54 set(INLINE "") 55endif(HAVE_INLINE) 56configure_file("${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake" "${CMAKE_CURRENT_BINARY_DIR}/config.h") 57 58## Checks for types ## 59# sauchar_t (8bit) 60check_type_size("uint8_t" UINT8_T) 61if(HAVE_UINT8_T) 62 set(SAUCHAR_TYPE "uint8_t") 63else(HAVE_UINT8_T) 64 check_type_size("unsigned char" SIZEOF_UNSIGNED_CHAR) 65 if("${SIZEOF_UNSIGNED_CHAR}" STREQUAL "1") 66 set(SAUCHAR_TYPE "unsigned char") 67 else("${SIZEOF_UNSIGNED_CHAR}" STREQUAL "1") 68 message(FATAL_ERROR "Cannot find unsigned 8-bit integer type") 69 endif("${SIZEOF_UNSIGNED_CHAR}" STREQUAL "1") 70endif(HAVE_UINT8_T) 71# saint_t (32bit) 72check_type_size("int32_t" INT32_T) 73if(HAVE_INT32_T) 74 set(SAINT32_TYPE "int32_t") 75 check_symbol_exists("PRId32" "inttypes.h" HAVE_PRID32) 76 if(HAVE_PRID32) 77 set(SAINT32_PRId "PRId32") 78 else(HAVE_PRID32) 79 set(SAINT32_PRId "\"d\"") 80 endif(HAVE_PRID32) 81else(HAVE_INT32_T) 82 check_type_size("int" SIZEOF_INT) 83 check_type_size("long" SIZEOF_LONG) 84 check_type_size("short" SIZEOF_SHORT) 85 check_type_size("__int32" SIZEOF___INT32) 86 if("${SIZEOF_INT}" STREQUAL "4") 87 set(SAINT32_TYPE "int") 88 set(SAINT32_PRId "\"d\"") 89 elseif("${SIZEOF_LONG}" STREQUAL "4") 90 set(SAINT32_TYPE "long") 91 set(SAINT32_PRId "\"ld\"") 92 elseif("${SIZEOF_SHORT}" STREQUAL "4") 93 set(SAINT32_TYPE "short") 94 set(SAINT32_PRId "\"d\"") 95 elseif("${SIZEOF___INT32}" STREQUAL "4") 96 set(SAINT32_TYPE "__int32") 97 set(SAINT32_PRId "\"d\"") 98 else("${SIZEOF_INT}" STREQUAL "4") 99 message(FATAL_ERROR "Cannot find 32-bit integer type") 100 endif("${SIZEOF_INT}" STREQUAL "4") 101endif(HAVE_INT32_T) 102# saint64_t (64bit) 103if(BUILD_DIVSUFSORT64) 104 check_type_size("int64_t" INT64_T) 105 if(HAVE_INT64_T) 106 set(SAINT64_TYPE "int64_t") 107 check_symbol_exists("PRId64" "inttypes.h" HAVE_PRID64) 108 if(HAVE_PRID64) 109 set(SAINT64_PRId "PRId64") 110 else(HAVE_PRID64) 111 set(SAINT64_PRId "\"lld\"") 112 endif(HAVE_PRID64) 113 else(HAVE_INT64_T) 114 check_type_size("int" SIZEOF_INT) 115 check_type_size("long" SIZEOF_LONG) 116 check_type_size("long long" SIZEOF_LONG_LONG) 117 check_type_size("__int64" SIZEOF___INT64) 118 if("${SIZEOF_INT}" STREQUAL "8") 119 set(SAINT64_TYPE "int") 120 set(SAINT64_PRId "\"d\"") 121 elseif("${SIZEOF_LONG}" STREQUAL "8") 122 set(SAINT64_TYPE "long") 123 set(SAINT64_PRId "\"ld\"") 124 elseif("${SIZEOF_LONG_LONG}" STREQUAL "8") 125 set(SAINT64_TYPE "long long") 126 set(SAINT64_PRId "\"lld\"") 127 elseif("${SIZEOF___INT64}" STREQUAL "8") 128 set(SAINT64_TYPE "__int64") 129 set(SAINT64_PRId "\"I64d\"") 130 else("${SIZEOF_INT}" STREQUAL "8") 131 message(SEND_ERROR "Cannot find 64-bit integer type") 132 set(BUILD_DIVSUFSORT64 OFF) 133 endif("${SIZEOF_INT}" STREQUAL "8") 134 endif(HAVE_INT64_T) 135endif(BUILD_DIVSUFSORT64) 136 137## generate divsufsort.h ## 138set(DIVSUFSORT_IMPORT "") 139set(DIVSUFSORT_EXPORT "") 140if(BUILD_SHARED_LIBS) 141 if(HAVE___DECLSPEC_DLLIMPORT_) 142 set(DIVSUFSORT_IMPORT "__declspec(dllimport)") 143 endif(HAVE___DECLSPEC_DLLIMPORT_) 144 if(HAVE___DECLSPEC_DLLEXPORT_) 145 set(DIVSUFSORT_EXPORT "__declspec(dllexport)") 146 endif(HAVE___DECLSPEC_DLLEXPORT_) 147endif(BUILD_SHARED_LIBS) 148set(W64BIT "") 149set(SAINDEX_TYPE "${SAINT32_TYPE}") 150set(SAINDEX_PRId "${SAINT32_PRId}") 151set(SAINT_PRId "${SAINT32_PRId}") 152configure_file("${CMAKE_CURRENT_SOURCE_DIR}/divsufsort.h.cmake" 153 "${CMAKE_CURRENT_BINARY_DIR}/divsufsort.h" @ONLY) 154install(FILES "${CMAKE_CURRENT_BINARY_DIR}/divsufsort.h" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) 155if(BUILD_DIVSUFSORT64) 156 set(W64BIT "64") 157 set(SAINDEX_TYPE "${SAINT64_TYPE}") 158 set(SAINDEX_PRId "${SAINT64_PRId}") 159 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/divsufsort.h.cmake" 160 "${CMAKE_CURRENT_BINARY_DIR}/divsufsort64.h" @ONLY) 161 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/divsufsort64.h" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) 162endif(BUILD_DIVSUFSORT64) 163