1 include(CheckIncludeFiles)
2 include(CheckIncludeFile)
3 include(CheckSymbolExists)
5 include(CheckFunctionKeywords)
8 ## Checks for header files ##
9 check_include_file("inttypes.h" HAVE_INTTYPES_H)
10 check_include_file("memory.h" HAVE_MEMORY_H)
11 check_include_file("stddef.h" HAVE_STDDEF_H)
12 check_include_file("stdint.h" HAVE_STDINT_H)
13 check_include_file("stdlib.h" HAVE_STDLIB_H)
14 check_include_file("string.h" HAVE_STRING_H)
15 check_include_file("strings.h" HAVE_STRINGS_H)
16 check_include_file("sys/types.h" HAVE_SYS_TYPES_H)
18 set(INCFILE "#include <inttypes.h>")
20 set(INCFILE "#include <stdint.h>")
23 endif(HAVE_INTTYPES_H)
25 ## create configuration files from .cmake file ##
27 ## Checks for WinIO ##
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)
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)
40 ## Checks for large file support ##
42 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/lfs.h.cmake" "${CMAKE_CURRENT_BINARY_DIR}/lfs.h" @ONLY)
45 ## generate config.h ##
46 check_function_keywords("inline;__inline;__inline__;__declspec(dllexport);__declspec(dllimport)")
50 set(INLINE "__inline")
51 elseif(HAVE___INLINE__)
52 set(INLINE "__inline__")
56 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake" "${CMAKE_CURRENT_BINARY_DIR}/config.h")
58 ## Checks for types ##
60 check_type_size("uint8_t" UINT8_T)
62 set(SAUCHAR_TYPE "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")
72 check_type_size("int32_t" INT32_T)
74 set(SAINT32_TYPE "int32_t")
75 check_symbol_exists("PRId32" "inttypes.h" HAVE_PRID32)
77 set(SAINT32_PRId "PRId32")
79 set(SAINT32_PRId "\"d\"")
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")
103 if(BUILD_DIVSUFSORT64)
104 check_type_size("int64_t" INT64_T)
106 set(SAINT64_TYPE "int64_t")
107 check_symbol_exists("PRId64" "inttypes.h" HAVE_PRID64)
109 set(SAINT64_PRId "PRId64")
111 set(SAINT64_PRId "\"lld\"")
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")
135 endif(BUILD_DIVSUFSORT64)
137 ## generate divsufsort.h ##
138 set(DIVSUFSORT_IMPORT "")
139 set(DIVSUFSORT_EXPORT "")
140 if(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_)
147 endif(BUILD_SHARED_LIBS)
149 set(SAINDEX_TYPE "${SAINT32_TYPE}")
150 set(SAINDEX_PRId "${SAINT32_PRId}")
151 set(SAINT_PRId "${SAINT32_PRId}")
152 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/divsufsort.h.cmake"
153 "${CMAKE_CURRENT_BINARY_DIR}/divsufsort.h" @ONLY)
154 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/divsufsort.h" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
155 if(BUILD_DIVSUFSORT64)
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})
162 endif(BUILD_DIVSUFSORT64)