You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

377 lines
14 KiB

  1. include(CheckIncludeFiles)
  2. include(CheckFunctionExists)
  3. include(CheckLibraryExists)
  4. include(CheckSymbolExists)
  5. include(CheckTypeSize)
  6. include(CheckCSourceCompiles)
  7. include(CheckCXXSourceCompiles)
  8. check_include_files(dlfcn.h HAVE_DLFCN_H )
  9. check_include_files(errno.h LOG4CPLUS_HAVE_ERRNO_H )
  10. check_include_files(iconv.h LOG4CPLUS_HAVE_ICONV_H )
  11. check_include_files(limits.h LOG4CPLUS_HAVE_LIMITS_H )
  12. check_include_files(sys/types.h LOG4CPLUS_HAVE_SYS_TYPES_H )
  13. check_include_files(sys/socket.h LOG4CPLUS_HAVE_SYS_SOCKET_H )
  14. check_include_files(sys/syscall.h LOG4CPLUS_HAVE_SYS_SYSCALL_H )
  15. check_include_files(sys/time.h LOG4CPLUS_HAVE_SYS_TIME_H )
  16. check_include_files(sys/timeb.h LOG4CPLUS_HAVE_SYS_TIMEB_H )
  17. check_include_files(sys/stat.h LOG4CPLUS_HAVE_SYS_STAT_H )
  18. check_include_files(sys/file.h LOG4CPLUS_HAVE_SYS_FILE_H )
  19. check_include_files(syslog.h LOG4CPLUS_HAVE_SYSLOG_H )
  20. check_include_files(arpa/inet.h LOG4CPLUS_HAVE_ARPA_INET_H )
  21. check_include_files(netinet/in.h LOG4CPLUS_HAVE_NETINET_IN_H )
  22. check_include_files(netinet/tcp.h LOG4CPLUS_HAVE_NETINET_TCP_H )
  23. check_include_files(netdb.h LOG4CPLUS_HAVE_NETDB_H )
  24. check_include_files(unistd.h LOG4CPLUS_HAVE_UNISTD_H )
  25. check_include_files(fcntl.h LOG4CPLUS_HAVE_FCNTL_H )
  26. check_include_files(stdio.h LOG4CPLUS_HAVE_STDIO_H )
  27. check_include_files(stdarg.h LOG4CPLUS_HAVE_STDARG_H )
  28. check_include_files(stdlib.h LOG4CPLUS_HAVE_STDLIB_H )
  29. check_include_files(time.h LOG4CPLUS_HAVE_TIME_H )
  30. check_include_files(wchar.h LOG4CPLUS_HAVE_WCHAR_H )
  31. check_include_files(inttypes.h HAVE_INTTYPES_H )
  32. check_include_files(memory.h HAVE_MEMORY_H )
  33. check_include_files(stdint.h HAVE_STDINT_H )
  34. check_include_files(strings.h HAVE_STRINGS_H )
  35. check_include_files(string.h HAVE_STRING_H )
  36. check_include_files("stdlib.h;stdio.h;stdarg.h;string.h;float.h" STDC_HEADERS )
  37. find_library(LIBADVAPI32 advapi32)
  38. find_library(LIBKERNEL32 kernel32)
  39. find_library(LIBNSL nsl)
  40. find_library(LIBRT rt)
  41. find_library(LIBICONV iconv)
  42. find_library(LIBPOSIX4 posix4)
  43. find_library(LIBCPOSIX cposix)
  44. find_library(LIBSOCKET socket)
  45. find_library(LIBWS2_32 ws2_32)
  46. check_function_exists(gmtime_r LOG4CPLUS_HAVE_GMTIME_R )
  47. check_function_exists(localtime_r LOG4CPLUS_HAVE_LOCALTIME_R )
  48. check_function_exists(gettimeofday LOG4CPLUS_HAVE_GETTIMEOFDAY )
  49. check_function_exists(getpid LOG4CPLUS_HAVE_GETPID )
  50. check_function_exists(ftime LOG4CPLUS_HAVE_FTIME )
  51. check_function_exists(stat LOG4CPLUS_HAVE_STAT )
  52. check_function_exists(lstat LOG4CPLUS_HAVE_LSTAT )
  53. check_function_exists(fcntl LOG4CPLUS_HAVE_FCNTL )
  54. check_function_exists(lockf LOG4CPLUS_HAVE_FLOCK )
  55. check_function_exists(flock LOG4CPLUS_HAVE_LOCKF )
  56. check_function_exists(htons LOG4CPLUS_HAVE_HTONS )
  57. check_function_exists(ntohs LOG4CPLUS_HAVE_NTOHS )
  58. check_function_exists(htonl LOG4CPLUS_HAVE_HTONL )
  59. check_function_exists(ntohl LOG4CPLUS_HAVE_NTOHL )
  60. check_function_exists(vsnprintf LOG4CPLUS_HAVE_VSNPRINTF )
  61. check_function_exists(_vsnprintf LOG4CPLUS_HAVE__VSNPRINTF )
  62. check_function_exists(vsprintf_s LOG4CPLUS_HAVE_VSPRINTF_S )
  63. check_function_exists(vswprintf_s LOG4CPLUS_HAVE_VSWPRINTF_S )
  64. check_function_exists(vfprintf_s LOG4CPLUS_HAVE_VFPRINTF_S )
  65. check_function_exists(vfwprintf_s LOG4CPLUS_HAVE_VFWPRINTF_S )
  66. check_function_exists(_vsnprintf_s LOG4CPLUS_HAVE__VSNPRINTF_S )
  67. check_function_exists(_vsnwprintf_s LOG4CPLUS_HAVE__VSNWPRINTF_S )
  68. check_function_exists(mbstowcs LOG4CPLUS_HAVE_MBSTOWCS )
  69. check_function_exists(wcstombs LOG4CPLUS_HAVE_WCSTOMBS )
  70. check_symbol_exists(ENAMETOOLONG errno.h LOG4CPLUS_HAVE_ENAMETOOLONG )
  71. check_symbol_exists(SYS_gettid sys/syscall.h LOG4CPLUS_HAVE_GETTID )
  72. check_symbol_exists(__FUNCTION__ "" LOG4CPLUS_HAVE_FUNCTION_MACRO )
  73. check_symbol_exists(__PRETTY_FUNCTION__ "" LOG4CPLUS_HAVE_PRETTY_FUNCTION_MACRO )
  74. check_symbol_exists(__func__ "" LOG4CPLUS_HAVE_FUNC_SYMBOL )
  75. check_c_source_compiles("#include <stdlib.h> \n int main() { int x = 1; int y = __sync_add_and_fetch (&x, 1); return y;}"
  76. LOG4CPLUS_HAVE___SYNC_ADD_AND_FETCH )
  77. check_c_source_compiles("#include <stdlib.h> \n int main() { int x = 1; int y = __sync_sub_and_fetch (&x, 1); return y;}"
  78. LOG4CPLUS_HAVE___SYNC_SUB_AND_FETCH )
  79. check_c_source_compiles("#include <stdio.h>\n #define MACRO(buf, args...) (sprintf (buf, \"%d\", args))\n int main() {char a[10]; MACRO(a, 1); return 0; }"
  80. LOG4CPLUS_HAVE_GNU_VARIADIC_MACROS )
  81. check_c_source_compiles("#include <stdio.h>\n #define MACRO(buf, ...) (sprintf (buf, \"%d\", __VA_ARGS__))\n int main() {char a[10]; MACRO(a, 1); return 0; }"
  82. LOG4CPLUS_HAVE_C99_VARIADIC_MACROS )
  83. # clock_gettime() needs -lrt here
  84. # TODO AC says this exists
  85. if (LIBRT)
  86. check_library_exists("${LIBRT}" clock_gettime ""
  87. LOG4CPLUS_HAVE_CLOCK_GETTIME )
  88. check_library_exists("${LIBRT}" clock_nanosleep ""
  89. LOG4CPLUS_HAVE_CLOCK_NANOSLEEP )
  90. check_library_exists("${LIBRT}" nanosleep ""
  91. LOG4CPLUS_HAVE_NANOSLEEP )
  92. else ()
  93. check_function_exists(clock_gettime LOG4CPLUS_HAVE_CLOCK_GETTIME )
  94. check_function_exists(clock_nanosleep LOG4CPLUS_HAVE_CLOCK_NANOSLEEP )
  95. check_function_exists(nanosleep LOG4CPLUS_HAVE_NANOSLEEP )
  96. endif ()
  97. # iconv functions may require iconv library (on OS X for example)
  98. if(LOG4CPLUS_WITH_ICONV)
  99. if(LIBICONV)
  100. check_library_exists("${LIBICONV}" iconv_open "" LOG4CPLUS_HAVE_ICONV_OPEN )
  101. check_library_exists("${LIBICONV}" iconv_close "" LOG4CPLUS_HAVE_ICONV_CLOSE )
  102. check_library_exists("${LIBICONV}" iconv "" LOG4CPLUS_HAVE_ICONV )
  103. else()
  104. check_function_exists(iconv_open LOG4CPLUS_HAVE_ICONV_OPEN )
  105. check_function_exists(iconv_close LOG4CPLUS_HAVE_ICONV_CLOSE )
  106. check_function_exists(iconv LOG4CPLUS_HAVE_ICONV )
  107. endif()
  108. endif()
  109. check_function_exists(gethostbyname_r LOG4CPLUS_HAVE_GETHOSTBYNAME_R) # TODO more complicated test in AC
  110. check_function_exists(getaddrinfo LOG4CPLUS_HAVE_GETADDRINFO ) # TODO more complicated test in AC
  111. # check for declspec stuff
  112. if(NOT DEFINED LOG4CPLUS_DECLSPEC_EXPORT)
  113. check_c_source_compiles(
  114. "#if defined (__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ <= 1))
  115. # error Please fail.
  116. #endif
  117. __attribute__((visibility(\"default\"))) int x = 0;
  118. __attribute__((visibility(\"default\"))) int foo();
  119. int foo() { return 0; }
  120. __attribute__((visibility(\"default\"))) int bar() { return x; }
  121. __attribute__((visibility(\"hidden\"))) int baz() { return 1; }
  122. int main(void) { return 0; }"
  123. HAVE_ATTRIBUTE_VISIBILITY
  124. )
  125. if(HAVE_ATTRIBUTE_VISIBILITY)
  126. set(LOG4CPLUS_DECLSPEC_EXPORT "__attribute__ ((visibility(\"default\")))" )
  127. set(LOG4CPLUS_DECLSPEC_IMPORT "__attribute__ ((visibility(\"default\")))" )
  128. set(LOG4CPLUS_DECLSPEC_PRIVATE "__attribute__ ((visibility(\"hidden\")))" )
  129. endif()
  130. endif()
  131. if(NOT DEFINED LOG4CPLUS_DECLSPEC_EXPORT)
  132. check_c_source_compiles(
  133. "#if defined (__clang__)
  134. // Here the problem is that Clang only warns that it does not support
  135. // __declspec(dllexport) but still compiles the executable.
  136. # error Please fail.
  137. #endif
  138. __declspec(dllexport) int x = 0;
  139. __declspec(dllexport) int foo ();
  140. int foo () { return 0; }
  141. __declspec(dllexport) int bar () { return x; }
  142. int main(void) { return 0; }"
  143. HAVE_DECLSPEC_DLLEXPORT
  144. )
  145. if(HAVE_DECLSPEC_DLLEXPORT)
  146. set(LOG4CPLUS_DECLSPEC_EXPORT "__declspec(dllexport)" )
  147. set(LOG4CPLUS_DECLSPEC_IMPORT "__declspec(dllimport)" )
  148. set(LOG4CPLUS_DECLSPEC_PRIVATE "" )
  149. endif()
  150. endif()
  151. if(NOT DEFINED LOG4CPLUS_DECLSPEC_EXPORT)
  152. check_c_source_compiles(
  153. "__global int x = 0;
  154. __global int foo();
  155. int foo() { return 0; }
  156. __global int bar() { return x; }
  157. __hidden int baz() { return 1; }
  158. int main(void) { return 0; }"
  159. HAVE_GLOBAL_AND_HIDDEN
  160. )
  161. if(HAVE_GLOBAL_AND_HIDDEN)
  162. set(LOG4CPLUS_DECLSPEC_EXPORT "__global" )
  163. set(LOG4CPLUS_DECLSPEC_IMPORT "__global" )
  164. set(LOG4CPLUS_DECLSPEC_PRIVATE "__hidden" )
  165. endif()
  166. endif()
  167. if(NOT DEFINED LOG4CPLUS_DECLSPEC_EXPORT)
  168. set(LOG4CPLUS_DECLSPEC_EXPORT "")
  169. set(LOG4CPLUS_DECLSPEC_IMPORT "")
  170. set(LOG4CPLUS_DECLSPEC_PRIVATE "")
  171. endif()
  172. # check for thread-local stuff
  173. if(NOT DEFINED LOG4CPLUS_HAVE_TLS_SUPPORT)
  174. # TODO: requires special compiler switch on GCC and Clang
  175. # Currently it is assumed that they are provided in
  176. # CMAKE_CXX_FLAGS
  177. set(CMAKE_REQUIRED_FLAGS "${CMAKE_CXX_FLAGS}")
  178. check_cxx_source_compiles(
  179. "extern thread_local int x;
  180. thread_local int * ptr = 0;
  181. int foo() { ptr = &x; return x; }
  182. thread_local int x = 1;
  183. int main()
  184. {
  185. x = 2;
  186. foo();
  187. return 0;
  188. }"
  189. HAVE_CXX11_THREAD_LOCAL
  190. )
  191. set(CMAKE_REQUIRED_FLAGS "")
  192. if(HAVE_CXX11_THREAD_LOCAL)
  193. set(LOG4CPLUS_HAVE_TLS_SUPPORT 1)
  194. set(LOG4CPLUS_THREAD_LOCAL_VAR "thread_local")
  195. endif()
  196. endif()
  197. if(NOT DEFINED LOG4CPLUS_HAVE_TLS_SUPPORT)
  198. check_cxx_source_compiles(
  199. "#if defined (__NetBSD__)
  200. #include <sys/param.h>
  201. #if ! __NetBSD_Prereq__(5,1,0)
  202. #error NetBSD __thread support does not work before 5.1.0. It is missing __tls_get_addr.
  203. #endif
  204. #endif
  205. extern __thread int x;
  206. __thread int * ptr = 0;
  207. int foo() { ptr = &x; return x; }
  208. __thread int x = 1;
  209. int main()
  210. {
  211. x = 2;
  212. foo();
  213. return 0;
  214. }"
  215. HAVE_GCC_THREAD_EXTENSION
  216. )
  217. if(HAVE_GCC_THREAD_EXTENSION)
  218. set(LOG4CPLUS_HAVE_TLS_SUPPORT 1)
  219. set(LOG4CPLUS_THREAD_LOCAL_VAR "__thread")
  220. endif()
  221. endif()
  222. if(NOT DEFINED LOG4CPLUS_HAVE_TLS_SUPPORT)
  223. check_cxx_source_compiles(
  224. "#if defined (__GNUC__)
  225. #error Please fail.
  226. #endif
  227. extern __declspec(thread) int x;
  228. __declspec(thread) int * ptr = 0;
  229. int foo() { ptr = &x; return x; }
  230. __declspec(thread) int x = 1;
  231. int main()
  232. {
  233. x = 2;
  234. foo();
  235. return 0;
  236. }"
  237. HAVE_DECLSPEC_THREAD
  238. )
  239. if(HAVE_DECLSPEC_THREAD)
  240. set(LOG4CPLUS_HAVE_TLS_SUPPORT 1)
  241. set(LOG4CPLUS_THREAD_LOCAL_VAR "__declspec(thread)")
  242. endif()
  243. endif()
  244. # check for c++11 atomic stuff
  245. # TODO: requires special compiler switch on GCC and Clang
  246. # Currently it is assumed that they are provided in
  247. # CMAKE_CXX_FLAGS
  248. set(CMAKE_REQUIRED_FLAGS "${CMAKE_CXX_FLAGS}")
  249. check_cxx_source_compiles(
  250. "#include <atomic>
  251. template<typename T>
  252. void test_atomic()
  253. {
  254. std::atomic<T> x(0);
  255. std::atomic_fetch_add_explicit(&x, static_cast<T>(1), std::memory_order_acquire);
  256. std::atomic_fetch_sub_explicit(&x, static_cast<T>(1), std::memory_order_release);
  257. }
  258. int main()
  259. {
  260. test_atomic<int>();
  261. test_atomic<unsigned int>();
  262. test_atomic<long>();
  263. test_atomic<unsigned long>();
  264. std::atomic_thread_fence(std::memory_order_acquire);
  265. return 0;
  266. }"
  267. LOG4CPLUS_HAVE_CXX11_ATOMICS
  268. )
  269. set(CMAKE_REQUIRED_FLAGS "")
  270. set(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h)
  271. check_type_size(socklen_t _SOCKLEN_SIZE)
  272. if (_SOCKLEN_SIZE)
  273. set(socklen_t)
  274. else()
  275. set(socklen_t TRUE)
  276. endif()
  277. macro(PATH_TO_HAVE _pathVar )
  278. if (${_pathVar})
  279. set(HAVE_${_pathVar} TRUE)
  280. else ()
  281. set(HAVE_${_pathVar} FALSE)
  282. endif ()
  283. endmacro()
  284. path_to_have(LIBADVAPI32)
  285. path_to_have(LIBKERNEL32)
  286. path_to_have(LIBNSL)
  287. path_to_have(LIBRT)
  288. path_to_have(LIBPOSIX4)
  289. path_to_have(LIBCPOSIX)
  290. path_to_have(LIBSOCKET)
  291. path_to_have(LIBWS2_32)
  292. set(HAVE_STDLIB_H ${LOG4CPLUS_HAVE_STDLIB_H} )
  293. set(HAVE_SYS_STAT_H ${LOG4CPLUS_HAVE_SYS_STAT_H} )
  294. set(HAVE_SYS_TYPES_H ${LOG4CPLUS_HAVE_SYS_TYPES_H} )
  295. set(HAVE_SYS_FILE_H ${LOG4CPLUS_HAVE_SYS_FILE_H} )
  296. set(HAVE_UNISTD_H ${LOG4CPLUS_HAVE_UNISTD_H} )
  297. set(HAVE_FTIME ${LOG4CPLUS_HAVE_FTIME} )
  298. set(HAVE_GETPID ${LOG4CPLUS_HAVE_GETPID} )
  299. set(HAVE_GETTIMEOFDAY ${LOG4CPLUS_HAVE_GETTIMEOFDAY} )
  300. set(HAVE_GETADDRINFO ${LOG4CPLUS_HAVE_GETADDRINFO} )
  301. set(HAVE_GETHOSTBYNAME_R ${LOG4CPLUS_HAVE_GETHOSTBYNAME_R} )
  302. set(HAVE_GMTIME_R ${LOG4CPLUS_HAVE_GMTIME_R} )
  303. set(HAVE_HTONL ${LOG4CPLUS_HAVE_HTONL} )
  304. set(HAVE_HTONS ${LOG4CPLUS_HAVE_HTONS} )
  305. set(HAVE_ICONV_OPEN ${LOG4CPLUS_HAVE_ICONV_OPEN} )
  306. set(HAVE_ICONV_CLOSE ${LOG4CPLUS_HAVE_ICONV_CLOSE} )
  307. set(HAVE_ICONV ${LOG4CPLUS_HAVE_ICONV} )
  308. set(HAVE_LSTAT ${LOG4CPLUS_HAVE_LSTAT} )
  309. set(HAVE_FCNTL ${LOG4CPLUS_HAVE_FCNTL} )
  310. set(HAVE_LOCKF ${LOG4CPLUS_HAVE_LOCKF} )
  311. set(HAVE_FLOCK ${LOG4CPLUS_HAVE_FLOCK} )
  312. set(HAVE_LOCALTIME_R ${LOG4CPLUS_HAVE_LOCALTIME_R} )
  313. set(HAVE_NTOHL ${LOG4CPLUS_HAVE_NTOHL} )
  314. set(HAVE_NTOHS ${LOG4CPLUS_HAVE_NTOHS} )
  315. set(HAVE_STAT ${LOG4CPLUS_HAVE_STAT} )
  316. set(HAVE_VFPRINTF_S ${LOG4CPLUS_HAVE_VFPRINTF_S} )
  317. set(HAVE_VFWPRINTF_S ${LOG4CPLUS_HAVE_VFWPRINTF_S} )
  318. set(HAVE_VSNPRINTF ${LOG4CPLUS_HAVE_VSNPRINTF} )
  319. set(HAVE_VSPRINTF_S ${LOG4CPLUS_HAVE_VSPRINTF_S} )
  320. set(HAVE_VSWPRINTF_S ${LOG4CPLUS_HAVE_VSWPRINTF_S} )
  321. set(HAVE__VSNPRINTF ${LOG4CPLUS_HAVE__VSNPRINTF} )
  322. set(HAVE__VSNPRINTF_S ${LOG4CPLUS_HAVE__VSNPRINTF_S} )
  323. set(HAVE__VSNWPRINTF_S ${LOG4CPLUS_HAVE__VSNWPRINTF_S} )
  324. set(HAVE_FUNCTION_MACRO ${LOG4CPLUS_HAVE_FUNCTION_MACRO} )
  325. set(HAVE_PRETTY_FUNCTION_MACRO ${LOG4CPLUS_HAVE_PRETTY_FUNCTION_MACRO} )
  326. set(HAVE___SYNC_ADD_AND_FETCH ${LOG4CPLUS_HAVE___SYNC_ADD_AND_FETCH} )
  327. set(HAVE___SYNC_SUB_AND_FETCH ${LOG4CPLUS_HAVE___SYNC_SUB_AND_FETCH} )