CMakeLists.txt 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. project(libuv C)
  2. # Disable warnings to avoid changing 3rd party code.
  3. if(CMAKE_C_COMPILER_ID MATCHES
  4. "^(GNU|LCC|Clang|AppleClang|IBMClang|XLClang|XL|VisualAge|SunPro|HP|Intel|IntelLLVM|NVHPC)$")
  5. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w")
  6. elseif(CMAKE_C_COMPILER_ID STREQUAL "PathScale")
  7. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -woffall")
  8. endif()
  9. find_package(Threads)
  10. set(uv_libraries ${CMAKE_THREAD_LIBS_INIT})
  11. set(uv_includes include src)
  12. set(uv_headers
  13. include/uv.h
  14. include/uv/errno.h
  15. include/uv/threadpool.h
  16. include/uv/version.h
  17. )
  18. set(uv_sources
  19. src/fs-poll.c
  20. src/heap-inl.h
  21. src/idna.c
  22. src/idna.h
  23. src/inet.c
  24. src/queue.h
  25. src/strscpy.c
  26. src/strscpy.h
  27. src/threadpool.c
  28. src/timer.c
  29. src/uv-common.c
  30. src/uv-common.h
  31. src/uv-data-getter-setters.c
  32. src/version.c
  33. )
  34. if(WIN32)
  35. list(APPEND uv_libraries
  36. ws2_32
  37. psapi
  38. iphlpapi
  39. shell32
  40. userenv
  41. )
  42. list(APPEND uv_includes
  43. src/win
  44. )
  45. list(APPEND uv_defines
  46. WIN32_LEAN_AND_MEAN
  47. _WIN32_WINNT=0x0600
  48. )
  49. list(APPEND uv_headers
  50. include/uv/win.h
  51. include/tree.h
  52. )
  53. list(APPEND uv_sources
  54. src/win/async.c
  55. src/win/atomicops-inl.h
  56. src/win/core.c
  57. src/win/detect-wakeup.c
  58. src/win/dl.c
  59. src/win/error.c
  60. src/win/fs-event.c
  61. src/win/fs.c
  62. src/win/getaddrinfo.c
  63. src/win/getnameinfo.c
  64. src/win/handle.c
  65. src/win/handle-inl.h
  66. src/win/internal.h
  67. src/win/loop-watcher.c
  68. src/win/pipe.c
  69. src/win/poll.c
  70. src/win/process-stdio.c
  71. src/win/process.c
  72. src/win/req-inl.h
  73. src/win/signal.c
  74. src/win/snprintf.c
  75. src/win/stream.c
  76. src/win/stream-inl.h
  77. src/win/tcp.c
  78. src/win/thread.c
  79. src/win/tty.c
  80. src/win/udp.c
  81. src/win/util.c
  82. src/win/winapi.c
  83. src/win/winapi.h
  84. src/win/winsock.c
  85. src/win/winsock.h
  86. )
  87. else()
  88. list(APPEND uv_includes
  89. src/unix
  90. )
  91. list(APPEND uv_headers
  92. include/uv/unix.h
  93. )
  94. list(APPEND uv_sources
  95. src/unix/async.c
  96. src/unix/atomic-ops.h
  97. src/unix/core.c
  98. src/unix/dl.c
  99. src/unix/fs.c
  100. src/unix/getaddrinfo.c
  101. src/unix/getnameinfo.c
  102. src/unix/internal.h
  103. src/unix/loop-watcher.c
  104. src/unix/loop.c
  105. src/unix/pipe.c
  106. src/unix/poll.c
  107. src/unix/process.c
  108. src/unix/signal.c
  109. src/unix/spinlock.h
  110. src/unix/stream.c
  111. src/unix/tcp.c
  112. src/unix/thread.c
  113. src/unix/tty.c
  114. src/unix/udp.c
  115. )
  116. endif()
  117. if(CMAKE_SYSTEM_NAME STREQUAL "AIX")
  118. list(APPEND uv_libraries
  119. perfstat
  120. )
  121. list(APPEND uv_headers
  122. include/uv/aix.h
  123. )
  124. list(APPEND uv_defines
  125. _ALL_SOURCE
  126. _XOPEN_SOURCE=500
  127. _LINUX_SOURCE_COMPAT
  128. _THREAD_SAFE
  129. )
  130. list(APPEND uv_sources
  131. src/unix/aix.c
  132. src/unix/aix-common.c
  133. )
  134. endif()
  135. if(CMAKE_SYSTEM_NAME STREQUAL "OS400")
  136. list(APPEND uv_headers
  137. include/uv/posix.h
  138. )
  139. list(APPEND uv_defines
  140. _ALL_SOURCE
  141. _XOPEN_SOURCE=500
  142. _LINUX_SOURCE_COMPAT
  143. _THREAD_SAFE
  144. )
  145. list(APPEND uv_sources
  146. src/unix/aix-common.c
  147. src/unix/ibmi.c
  148. src/unix/posix-poll.c
  149. src/unix/no-fsevents.c
  150. src/unix/no-proctitle.c
  151. )
  152. endif()
  153. if(CMAKE_SYSTEM_NAME MATCHES "CYGWIN" OR CMAKE_SYSTEM_NAME MATCHES "MSYS")
  154. list(APPEND uv_libraries
  155. )
  156. list(APPEND uv_headers
  157. include/uv/posix.h
  158. )
  159. list(APPEND uv_defines
  160. )
  161. list(APPEND uv_sources
  162. src/unix/cygwin.c
  163. src/unix/bsd-ifaddrs.c
  164. src/unix/no-fsevents.c
  165. src/unix/no-proctitle.c
  166. src/unix/posix-hrtime.c
  167. src/unix/posix-poll.c
  168. src/unix/procfs-exepath.c
  169. src/unix/sysinfo-loadavg.c
  170. src/unix/sysinfo-memory.c
  171. )
  172. endif()
  173. if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
  174. list(APPEND uv_headers
  175. include/uv/darwin.h
  176. )
  177. list(APPEND uv_defines
  178. _DARWIN_USE_64_BIT_INODE=1
  179. _DARWIN_UNLIMITED_SELECT=1
  180. )
  181. list(APPEND uv_sources
  182. src/unix/bsd-ifaddrs.c
  183. src/unix/darwin.c
  184. src/unix/darwin-proctitle.c
  185. src/unix/fsevents.c
  186. src/unix/kqueue.c
  187. src/unix/proctitle.c
  188. )
  189. endif()
  190. if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  191. list(APPEND uv_libraries dl rt)
  192. list(APPEND uv_headers
  193. include/uv/linux.h
  194. )
  195. list(APPEND uv_defines _GNU_SOURCE)
  196. list(APPEND uv_sources
  197. src/unix/epoll.c
  198. src/unix/linux-core.c
  199. src/unix/linux-inotify.c
  200. src/unix/linux-syscalls.c
  201. src/unix/linux-syscalls.h
  202. src/unix/procfs-exepath.c
  203. src/unix/proctitle.c
  204. src/unix/sysinfo-loadavg.c
  205. src/unix/sysinfo-memory.c
  206. )
  207. endif()
  208. if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
  209. list(APPEND uv_libraries
  210. kvm
  211. )
  212. list(APPEND uv_headers
  213. include/uv/bsd.h
  214. )
  215. list(APPEND uv_sources
  216. src/unix/bsd-ifaddrs.c
  217. src/unix/bsd-proctitle.c
  218. src/unix/freebsd.c
  219. src/unix/kqueue.c
  220. src/unix/posix-hrtime.c
  221. )
  222. endif()
  223. if(CMAKE_SYSTEM_NAME STREQUAL "kFreeBSD")
  224. list(APPEND uv_libraries
  225. freebsd-glue
  226. kvm
  227. )
  228. list(APPEND uv_headers
  229. include/uv/bsd.h
  230. )
  231. list(APPEND uv_sources
  232. src/unix/bsd-ifaddrs.c
  233. src/unix/bsd-proctitle.c
  234. src/unix/freebsd.c
  235. src/unix/kqueue.c
  236. src/unix/posix-hrtime.c
  237. )
  238. endif()
  239. if(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
  240. list(APPEND uv_libraries
  241. kvm
  242. )
  243. list(APPEND uv_headers
  244. include/uv/bsd.h
  245. )
  246. list(APPEND uv_sources
  247. src/unix/bsd-ifaddrs.c
  248. src/unix/bsd-proctitle.c
  249. src/unix/netbsd.c
  250. src/unix/kqueue.c
  251. src/unix/posix-hrtime.c
  252. )
  253. endif()
  254. if(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
  255. list(APPEND uv_libraries
  256. kvm
  257. )
  258. list(APPEND uv_headers
  259. include/uv/bsd.h
  260. )
  261. list(APPEND uv_sources
  262. src/unix/bsd-ifaddrs.c
  263. src/unix/bsd-proctitle.c
  264. src/unix/openbsd.c
  265. src/unix/kqueue.c
  266. src/unix/posix-hrtime.c
  267. )
  268. endif()
  269. if(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
  270. list(APPEND uv_libraries
  271. kstat
  272. nsl
  273. sendfile
  274. socket
  275. rt
  276. )
  277. list(APPEND uv_headers
  278. include/uv/sunos.h
  279. )
  280. list(APPEND uv_defines
  281. __EXTENSIONS__
  282. )
  283. if(CMAKE_SYSTEM_VERSION STREQUAL "5.10")
  284. set(CMAKE_C_STANDARD 90)
  285. if(CMAKE_VERSION VERSION_LESS 3.8.20170504 AND CMAKE_C_COMPILER_ID STREQUAL "SunPro" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 5.14)
  286. # The running version of CMake does not know how to add this flag.
  287. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c90")
  288. endif()
  289. list(APPEND uv_defines
  290. _XOPEN_SOURCE=500
  291. )
  292. else()
  293. if(NOT CMAKE_C_STANDARD OR CMAKE_C_STANDARD EQUAL 90)
  294. set(CMAKE_C_STANDARD 11)
  295. endif()
  296. if(CMAKE_VERSION VERSION_LESS 3.8.20170505 AND CMAKE_C_COMPILER_ID STREQUAL "SunPro" AND CMAKE_C_COMPILER_VERSION VERSION_LESS 5.14)
  297. # The running version of CMake does not know how to add this flag.
  298. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -xc99")
  299. endif()
  300. list(APPEND uv_defines
  301. _XOPEN_SOURCE=600
  302. )
  303. endif()
  304. list(APPEND uv_sources
  305. src/unix/no-proctitle.c
  306. src/unix/sunos.c
  307. )
  308. endif()
  309. if(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
  310. list(APPEND uv_libraries
  311. rt
  312. )
  313. list(APPEND uv_headers
  314. include/uv/posix.h
  315. )
  316. list(APPEND uv_defines
  317. _XOPEN_SOURCE_EXTENDED
  318. )
  319. list(APPEND uv_sources
  320. src/unix/hpux.c
  321. src/unix/no-fsevents.c
  322. src/unix/posix-poll.c
  323. )
  324. endif()
  325. if(CMAKE_SYSTEM_NAME STREQUAL "QNX")
  326. list(APPEND uv_headers
  327. include/uv/posix.h
  328. )
  329. list(APPEND uv_defines
  330. _XOPEN_SOURCE=700
  331. )
  332. list(APPEND uv_sources
  333. src/unix/posix-hrtime.c
  334. src/unix/posix-poll.c
  335. src/unix/no-fsevents.c
  336. src/unix/no-proctitle.c
  337. )
  338. list(APPEND uv_libraries
  339. socket
  340. )
  341. endif()
  342. include_directories(
  343. ${uv_includes}
  344. ${KWSYS_HEADER_ROOT}
  345. )
  346. add_library(cmlibuv STATIC ${uv_sources})
  347. target_link_libraries(cmlibuv ${uv_libraries})
  348. set_property(TARGET cmlibuv PROPERTY COMPILE_DEFINITIONS ${uv_defines})
  349. install(FILES LICENSE DESTINATION ${CMAKE_DOC_DIR}/cmlibuv)