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.

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