1# This file is part of enblend. 2# Licence details can be found in the file COPYING. 3# 4# Copyright (c) 2009-2015, Kornel Benko <Kornel.Benko@berlin.de> 5# , Ryan Sleevi <ryan+hugin@sleevi.com> 6# , Harry van der Wolf <hvdwolf@gmail.com> 7# 8 9include(CheckIncludeFile) 10include(CheckIncludeFileCXX) 11include(CheckIncludeFiles) 12include(CheckSymbolExists) 13include(CheckFunctionExists) 14include(CheckLibraryExists) 15include(CheckTypeSize) 16include(CheckCXXSourceCompiles) 17include(CheckFunctionExists) 18include(TestBigEndian) 19 20MACRO(AddHeaderTestToConfig header var) 21STRING(CONFIGURE "/* Define if you have the <${header}> header file. */\n#cmakedefine ${var} 1\n" _str) 22SET(CMAKE_HEADER_EXISTS "${CMAKE_HEADER_EXISTS}${_str}\n") 23UNSET(_str) 24ENDMACRO() 25 26MACRO(AddFunctionTestToConfig function var) 27STRING(CONFIGURE "/* Define if you have the '${function}' function. */\n#cmakedefine ${var} 1\n" _str) 28SET(CMAKE_FUNCTION_EXISTS "${CMAKE_FUNCTION_EXISTS}${_str}\n") 29UNSET(_str) 30ENDMACRO() 31 32 33#Check for some include files and set appropriate variables 34# e.g. "sys/dir.h" found => "HAVE_SYS_DIR_H" set to 1 35foreach(_fl "dirent.h" "fenv.h" 36 "inttypes.h" "limits.h" 37 "memory.h" "stdint.h" "stdlib.h" "stdbool.h" "strings.h" "string.h" 38 "sys/stat.h" "sys/types.h" "unistd.h" "windows.h" "sys/times.h") 39 string(REGEX REPLACE "[/\\.]" "_" _var ${_fl}) 40 string(TOUPPER "${_var}" _FLN) 41 check_include_file_cxx("${_fl}" "HAVE_${_FLN}" ) 42 AddHeaderTestToConfig("${_fl}" "HAVE_${_FLN}") 43endforeach() 44 45#Check for functions 46set(CMAKE_REQUIRED_LIBRARIES -lm) 47foreach(_fc atexit fesetround floor fseeko lrint lrintf 48 memset mkstemp pow select sqrt malloc 49 strchr strcspn strdup strerror strerror_r strpbrk strrchr strtol strtok_r strerror_r strtoul) 50 string(TOUPPER "${_fc}" _FC) 51 check_function_exists(${_fc} "HAVE_${_FC}") 52 AddFunctionTestToConfig("${_fc}" "HAVE_${_FC}") 53endforeach() 54 55if(HAVE_DIRENT_H) 56 check_cxx_source_compiles( 57 " 58 #include <dirent.h> 59 DIR *DI; 60 int i = closedir(DI); 61 int main(){return(0);} 62 " 63 CLOSEDIR_INT) 64endif(HAVE_DIRENT_H) 65if (NOT CLOSEDIR_INT) 66 set(CLOSEDIR_VOID 1) 67endif() 68 69CHECK_LIBRARY_EXISTS(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME) 70AddFunctionTestToConfig("clock_gettime" "HAVE_CLOCK_GETTIME") 71 72# Check for restrict keyword 73# Builds the macro A_C_RESTRICT form automake 74set(RESTRICT) 75foreach(ac_kw __restrict __restrict__ _Restrict restrict) 76 check_cxx_source_compiles( 77 " 78 int foo (int * ${ac_kw} ip) { 79 return ip[0]; 80 } 81 int main(){ 82 int s[1]; 83 int * ${ac_kw} t = s; 84 t[0] = 0; 85 return foo(t); 86 } 87 " 88 RESTRICT_${ac_kw}_FOUND) 89 if(RESTRICT_${ac_kw}_FOUND) 90 set(RESTRICT ${ac_kw}) 91 break() 92 endif() 93endforeach() 94 95if(VIGRA_FOUND AND NOT VIGRA_VERSION_CHECK) 96 unset(VIGRA_SETIMAGEINDEX CACHE) 97 set(CMAKE_REQUIRED_INCLUDES ${VIGRA_INCLUDE_DIR}) 98 set(CMAKE_REQUIRED_LIBRARIES ${VIGRA_LIBRARIES}) 99 check_cxx_source_compiles( 100 " 101 #include <vigra/imageinfo.hxx> 102 #include <vigra/impexalpha.hxx> 103 104 vigra::ImageImportInfo info(\"image.tif\"); 105 int main(){ 106 vigra::BRGBImage image; 107 vigra::BImage alpha; 108 vigra::impexListFormats(); 109 info.setImageIndex(99); 110 vigra::importImageAlpha(info, destImage(image), destImage(alpha)); 111 return(0); 112 } 113 " 114 VIGRA_SETIMAGEINDEX) 115 if(NOT VIGRA_SETIMAGEINDEX) 116 message(FATAL_ERROR "Vigra library too old") 117 endif() 118endif() 119 120message(STATUS "CMAKE_ERRFILE = ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log") 121message(STATUS "CMAKE_LOGFILE = ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log") 122 123check_type_size( ptrdiff_t HAVE_PTRDIFF_T ) 124# How to check if stdbool.h conforms to C99? 125 126check_cxx_source_compiles( 127 " 128 #include <sys/dir.h> 129 DIR *a = 0; 130 int main(){return(0);} 131 " 132 HAVE_SYS_DIR_H) 133AddHeaderTestToConfig("sys/dir.h" "HAVE_SYS_DIR_H") 134check_cxx_source_compiles( 135 " 136 #include <ndir.h> 137 DIR *a = 0; 138 int main(){return(0);} 139 " 140 HAVE_NDIR_H) 141AddHeaderTestToConfig("ndir.h" "HAVE_NDIR_H") 142check_cxx_source_compiles( 143 " 144 #include <sys/ndir.h> 145 DIR *a = 0; 146 int main(){return(0);} 147 " 148 HAVE_SYS_NDIR_H) 149AddHeaderTestToConfig("sys/ndir.h" "HAVE_SYS_NDIR_H") 150 151check_include_files("stdlib.h;stdarg.h;string.h;float.h" STDC_HEADERS) 152check_cxx_source_compiles( 153 " 154 #include <signal.h> 155 156 static void sg(int b) { return;} 157 int main(int c, char *av[]) { signal(0, sg); return(0);} 158 " 159 RETSIGTYPE_VOID) 160 161if(RETSIGTYPE_VOID) 162 set(RETSIGTYPE void) 163else(RETSIGTYPE_VOID) 164 set(RETSIGTYPE int) 165endif(RETSIGTYPE_VOID) 166 167test_big_endian(WORDS_BIGENDIAN) 168check_cxx_source_compiles( 169 " 170 #include <sys/types.h> 171 off_t a = 0; 172 int main(){return(0);} 173 " 174 HAVE_OFF_T) 175 176check_cxx_source_compiles( 177 " 178 #include <sys/types.h> 179 size_t a = 0; 180 int main(){return(0);} 181 " 182 HAVE_SIZE_T) 183check_cxx_source_compiles( 184 " 185 #include <string.h> 186 int main(){char b;char *a = strerror_r(0, &b, 0); return(0);} 187 " 188 STRERROR_R_CHAR_P) 189 190SET(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") 191SET(CMAKE_REQUIRED_FLAGS "${CMAKE_CXX_FLAGS}") 192check_cxx_source_compiles( 193 " 194 #include <string> 195 #include <type_traits> 196 #include <utility> 197 198 int main() 199 { 200 std::string s(\"foo\"); 201 const std::string& const_s = std::as_const(s); 202 return 0; 203 } 204 " 205 206 HAVE_AS_CONST 207) 208 209check_cxx_source_compiles( 210 " 211 #include <filesystem> 212 #include <string> 213 214 int main() 215 { 216 std::tr2::sys::path filepath; 217 std::string s=filepath.filename().string(); 218 return 0; 219 }; 220 " 221 HAVE_STD_FILESYSTEM 222) 223 224SET(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}") 225 226# workaround for older boost versions (<1.55) 227set(CMAKE_REQUIRED_INCLUDES ${Boost_INCLUDE_DIR}) 228check_cxx_source_compiles( 229 " 230 #include <boost/config/suffix.hpp> 231 #ifndef BOOST_FALLTHROUGH 232 #error \"BOOST_FALLTHROUGH not defined\" 233 #endif 234 int main(){return(0);} 235 " 236 HAVE_BOOST_FALLTHROUGH 237) 238