aboutsummaryrefslogtreecommitdiffstats
path: root/include/CMakeLists.txt
blob: 3a4f2afae6c26006fa66210db1468e372650022d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
include(CheckIncludeFiles)
include(CheckIncludeFile)
include(CheckSymbolExists)
include(CheckTypeSize)
include(CheckFunctionKeywords)

## Checks for header files ##
check_include_file("inttypes.h" HAVE_INTTYPES_H)
check_include_file("memory.h" HAVE_MEMORY_H)
check_include_file("stddef.h" HAVE_STDDEF_H)
check_include_file("stdint.h" HAVE_STDINT_H)
check_include_file("stdlib.h" HAVE_STDLIB_H)
check_include_file("string.h" HAVE_STRING_H)
check_include_file("strings.h" HAVE_STRINGS_H)
check_include_file("sys/types.h" HAVE_SYS_TYPES_H)
check_include_file("sys/stat.h" HAVE_SYS_STAT_H)
if(HAVE_INTTYPES_H)
  set(INCFILE "#include <inttypes.h>")
elseif(HAVE_STDINT_H)
  set(INCFILE "#include <stdint.h>")
else(HAVE_INTTYPES_H)
  set(INCFILE "")
endif(HAVE_INTTYPES_H)

## create configuration files from .cmake file ##

## generate config.h ##
check_function_keywords("inline;__inline;__inline__;__declspec(dllexport);__declspec(dllimport)")
if(HAVE_INLINE)
  set(INLINE "inline")
elseif(HAVE___INLINE)
  set(INLINE "__inline")
elseif(HAVE___INLINE__)
  set(INLINE "__inline__")
else(HAVE_INLINE)
  set(INLINE "")
endif(HAVE_INLINE)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake" "${CMAKE_CURRENT_BINARY_DIR}/config.h")

## Checks for types ##
# sauchar_t (8bit)
check_type_size("uint8_t" UINT8_T)
if(HAVE_UINT8_T)
  set(SAUCHAR_TYPE "uint8_t")
else(HAVE_UINT8_T)
  check_type_size("unsigned char" SIZEOF_UNSIGNED_CHAR)
  if(${SIZEOF_UNSIGNED_CHAR} STREQUAL "1")
    set(SAUCHAR_TYPE "unsigned char")
  else(${SIZEOF_UNSIGNED_CHAR} STREQUAL "1")
    message(FATAL_ERROR "Cannot find unsigned 8-bit integer type")
  endif(${SIZEOF_UNSIGNED_CHAR} STREQUAL "1")
endif(HAVE_UINT8_T)
# saint_t (32bit)
check_type_size("int32_t" INT32_T)
if(HAVE_INT32_T)
  set(SAINT32_TYPE "int32_t")
  check_symbol_exists("PRId32" "inttypes.h" HAVE_PRID32)
  if(HAVE_PRID32)
    set(SAINT32_PRId "PRId32")
  else(HAVE_PRID32)
    set(SAINT32_PRId "\"d\"")
  endif(HAVE_PRID32)
else(HAVE_INT32_T)
  check_type_size("int" SIZEOF_INT)
  check_type_size("long" SIZEOF_LONG)
  check_type_size("short" SIZEOF_SHORT)
  check_type_size("__int32" SIZEOF___INT32)
  if(${SIZEOF_INT} STREQUAL "4")
    set(SAINT32_TYPE "int")
    set(SAINT32_PRId "\"d\"")
  elseif(${SIZEOF_LONG} STREQUAL "4")
    set(SAINT32_TYPE "long")
    set(SAINT32_PRId "\"ld\"")
  elseif(${SIZEOF_SHORT} STREQUAL "4")
    set(SAINT32_TYPE "short")
    set(SAINT32_PRId "\"d\"")
  elseif(${SIZEOF___INT32} STREQUAL "4")
    set(SAINT32_TYPE "__int32")
    set(SAINT32_PRId "\"d\"")
  else(${SIZEOF_INT} STREQUAL "4")
    message(FATAL_ERROR "Cannot find 32-bit integer type")
  endif(${SIZEOF_INT} STREQUAL "4")
endif(HAVE_INT32_T)

## generate divsufsort.h ##
set(DIVSUFSORT_IMPORT "")
set(DIVSUFSORT_EXPORT "")
if(BUILD_SHARED_LIBS)
  if(HAVE___DECLSPEC_DLLIMPORT_)
    set(DIVSUFSORT_IMPORT "__declspec(dllimport)")
  endif(HAVE___DECLSPEC_DLLIMPORT_)
  if(HAVE___DECLSPEC_DLLEXPORT_)
    set(DIVSUFSORT_EXPORT "__declspec(dllexport)")
  endif(HAVE___DECLSPEC_DLLEXPORT_)
endif(BUILD_SHARED_LIBS)
set(SAINDEX_TYPE "${SAINT32_TYPE}")
set(SAINDEX_PRId "${SAINT32_PRId}")
set(SAINT_PRId "${SAINT32_PRId}")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/divsufsort.h.cmake"
               "${CMAKE_CURRENT_BINARY_DIR}/divsufsort.h" @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/divsufsort.h" DESTINATION include)