-
Notifications
You must be signed in to change notification settings - Fork 8
/
ConfigureChecks.cmake
224 lines (199 loc) · 5.52 KB
/
ConfigureChecks.cmake
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# This file is part of enblend.
# Licence details can be found in the file COPYING.
#
# Copyright (c) 2009-2015, Kornel Benko <Kornel.Benko@berlin.de>
# , Ryan Sleevi <ryan+hugin@sleevi.com>
# , Harry van der Wolf <hvdwolf@gmail.com>
#
include(CheckIncludeFile)
include(CheckIncludeFileCXX)
include(CheckIncludeFiles)
include(CheckSymbolExists)
include(CheckFunctionExists)
include(CheckLibraryExists)
include(CheckTypeSize)
include(CheckCXXSourceCompiles)
include(CheckFunctionExists)
include(TestBigEndian)
MACRO(AddHeaderTestToConfig header var)
STRING(CONFIGURE "/* Define if you have the <${header}> header file. */\n#cmakedefine ${var} 1\n" _str)
SET(CMAKE_HEADER_EXISTS "${CMAKE_HEADER_EXISTS}${_str}\n")
UNSET(_str)
ENDMACRO()
MACRO(AddFunctionTestToConfig function var)
STRING(CONFIGURE "/* Define if you have the '${function}' function. */\n#cmakedefine ${var} 1\n" _str)
SET(CMAKE_FUNCTION_EXISTS "${CMAKE_FUNCTION_EXISTS}${_str}\n")
UNSET(_str)
ENDMACRO()
#Check for some include files and set appropriate variables
# e.g. "sys/dir.h" found => "HAVE_SYS_DIR_H" set to 1
foreach(_fl "dirent.h" "fenv.h"
"inttypes.h" "limits.h"
"memory.h" "stdint.h" "stdlib.h" "stdbool.h" "strings.h" "string.h"
"sys/stat.h" "sys/types.h" "unistd.h" "windows.h" "sys/times.h")
string(REGEX REPLACE "[/\\.]" "_" _var ${_fl})
string(TOUPPER "${_var}" _FLN)
check_include_file_cxx("${_fl}" "HAVE_${_FLN}" )
AddHeaderTestToConfig("${_fl}" "HAVE_${_FLN}")
endforeach()
#Check for functions
set(CMAKE_REQUIRED_LIBRARIES -lm)
foreach(_fc atexit fesetround floor fseeko lrint lrintf
memset mkstemp pow select sqrt malloc
strchr strcspn strdup strerror strerror_r strpbrk strrchr strtol strtok_r strerror_r strtoul)
string(TOUPPER "${_fc}" _FC)
check_function_exists(${_fc} "HAVE_${_FC}")
AddFunctionTestToConfig("${_fc}" "HAVE_${_FC}")
endforeach()
if(HAVE_DIRENT_H)
check_cxx_source_compiles(
"
#include <dirent.h>
DIR *DI;
int i = closedir(DI);
int main(){return(0);}
"
CLOSEDIR_INT)
endif(HAVE_DIRENT_H)
if (NOT CLOSEDIR_INT)
set(CLOSEDIR_VOID 1)
endif()
CHECK_LIBRARY_EXISTS(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME)
AddFunctionTestToConfig("clock_gettime" "HAVE_CLOCK_GETTIME")
# Check for restrict keyword
# Builds the macro A_C_RESTRICT form automake
set(RESTRICT)
foreach(ac_kw __restrict __restrict__ _Restrict restrict)
check_cxx_source_compiles(
"
int foo (int * ${ac_kw} ip) {
return ip[0];
}
int main(){
int s[1];
int * ${ac_kw} t = s;
t[0] = 0;
return foo(t);
}
"
RESTRICT_${ac_kw}_FOUND)
if(RESTRICT_${ac_kw}_FOUND)
set(RESTRICT ${ac_kw})
break()
endif()
endforeach()
if(VIGRA_FOUND AND NOT VIGRA_VERSION_CHECK)
unset(VIGRA_SETIMAGEINDEX CACHE)
set(CMAKE_REQUIRED_INCLUDES ${VIGRA_INCLUDE_DIR})
set(CMAKE_REQUIRED_LIBRARIES ${VIGRA_LIBRARIES})
check_cxx_source_compiles(
"
#include <vigra/imageinfo.hxx>
#include <vigra/impexalpha.hxx>
vigra::ImageImportInfo info(\"image.tif\");
int main(){
vigra::BRGBImage image;
vigra::BImage alpha;
vigra::impexListFormats();
info.setImageIndex(99);
vigra::importImageAlpha(info, destImage(image), destImage(alpha));
return(0);
}
"
VIGRA_SETIMAGEINDEX)
if(NOT VIGRA_SETIMAGEINDEX)
message(FATAL_ERROR "Vigra library too old")
endif()
endif()
message(STATUS "CMAKE_ERRFILE = ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log")
message(STATUS "CMAKE_LOGFILE = ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log")
check_type_size( ptrdiff_t HAVE_PTRDIFF_T )
# How to check if stdbool.h conforms to C99?
check_cxx_source_compiles(
"
#include <sys/dir.h>
DIR *a = 0;
int main(){return(0);}
"
HAVE_SYS_DIR_H)
AddHeaderTestToConfig("sys/dir.h" "HAVE_SYS_DIR_H")
check_cxx_source_compiles(
"
#include <ndir.h>
DIR *a = 0;
int main(){return(0);}
"
HAVE_NDIR_H)
AddHeaderTestToConfig("ndir.h" "HAVE_NDIR_H")
check_cxx_source_compiles(
"
#include <sys/ndir.h>
DIR *a = 0;
int main(){return(0);}
"
HAVE_SYS_NDIR_H)
AddHeaderTestToConfig("sys/ndir.h" "HAVE_SYS_NDIR_H")
check_include_files("stdlib.h;stdarg.h;string.h;float.h" STDC_HEADERS)
check_cxx_source_compiles(
"
#include <signal.h>
static void sg(int b) { return;}
int main(int c, char *av[]) { signal(0, sg); return(0);}
"
RETSIGTYPE_VOID)
if(RETSIGTYPE_VOID)
set(RETSIGTYPE void)
else(RETSIGTYPE_VOID)
set(RETSIGTYPE int)
endif(RETSIGTYPE_VOID)
test_big_endian(WORDS_BIGENDIAN)
check_cxx_source_compiles(
"
#include <sys/types.h>
off_t a = 0;
int main(){return(0);}
"
HAVE_OFF_T)
check_cxx_source_compiles(
"
#include <sys/types.h>
size_t a = 0;
int main(){return(0);}
"
HAVE_SIZE_T)
check_cxx_source_compiles(
"
#include <string.h>
int main(){char b;char *a = strerror_r(0, &b, 0); return(0);}
"
STRERROR_R_CHAR_P)
SET(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
SET(CMAKE_REQUIRED_FLAGS "${CMAKE_CXX_FLAGS}")
check_cxx_source_compiles(
"
#include <string>
#include <type_traits>
#include <utility>
int main()
{
std::string s(\"foo\");
const std::string& const_s = std::as_const(s);
return 0;
}
"
HAVE_AS_CONST
)
check_cxx_source_compiles(
"
#include <filesystem>
#include <string>
int main()
{
std::tr2::sys::path filepath;
std::string s=filepath.filename().string();
return 0;
};
"
HAVE_STD_FILESYSTEM
)
SET(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}")