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.

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