CMakeLists.txt 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. project(libuv C)
  2. # Disable warnings to avoid changing 3rd party code.
  3. if(CMAKE_C_COMPILER_ID MATCHES
  4. "^(GNU|Clang|AppleClang|XLClang|XL|VisualAge|SunPro|HP|Intel|IntelLLVM)$")
  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")
  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/linux-core.c
  198. src/unix/linux-inotify.c
  199. src/unix/linux-syscalls.c
  200. src/unix/linux-syscalls.h
  201. src/unix/procfs-exepath.c
  202. src/unix/proctitle.c
  203. src/unix/sysinfo-loadavg.c
  204. src/unix/sysinfo-memory.c
  205. )
  206. endif()
  207. if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
  208. list(APPEND uv_libraries
  209. kvm
  210. )
  211. list(APPEND uv_headers
  212. include/uv/bsd.h
  213. )
  214. list(APPEND uv_sources
  215. src/unix/bsd-ifaddrs.c
  216. src/unix/bsd-proctitle.c
  217. src/unix/freebsd.c
  218. src/unix/kqueue.c
  219. src/unix/posix-hrtime.c
  220. )
  221. endif()
  222. if(CMAKE_SYSTEM_NAME STREQUAL "kFreeBSD")
  223. list(APPEND uv_libraries
  224. freebsd-glue
  225. kvm
  226. )
  227. list(APPEND uv_headers
  228. include/uv/bsd.h
  229. )
  230. list(APPEND uv_sources
  231. src/unix/bsd-ifaddrs.c
  232. src/unix/bsd-proctitle.c
  233. src/unix/freebsd.c
  234. src/unix/kqueue.c
  235. src/unix/posix-hrtime.c
  236. )
  237. endif()
  238. if(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
  239. list(APPEND uv_libraries
  240. kvm
  241. )
  242. list(APPEND uv_headers
  243. include/uv/bsd.h
  244. )
  245. list(APPEND uv_sources
  246. src/unix/bsd-ifaddrs.c
  247. src/unix/bsd-proctitle.c
  248. src/unix/netbsd.c
  249. src/unix/kqueue.c
  250. src/unix/posix-hrtime.c
  251. )
  252. endif()
  253. if(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
  254. list(APPEND uv_libraries
  255. kvm
  256. )
  257. list(APPEND uv_headers
  258. include/uv/bsd.h
  259. )
  260. list(APPEND uv_sources
  261. src/unix/bsd-ifaddrs.c
  262. src/unix/bsd-proctitle.c
  263. src/unix/openbsd.c
  264. src/unix/kqueue.c
  265. src/unix/posix-hrtime.c
  266. )
  267. endif()
  268. if(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
  269. list(APPEND uv_libraries
  270. kstat
  271. nsl
  272. sendfile
  273. socket
  274. rt
  275. )
  276. list(APPEND uv_headers
  277. include/uv/sunos.h
  278. )
  279. list(APPEND uv_defines
  280. __EXTENSIONS__
  281. )
  282. if(CMAKE_SYSTEM_VERSION STREQUAL "5.10")
  283. set(CMAKE_C_STANDARD 90)
  284. 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)
  285. # The running version of CMake does not know how to add this flag.
  286. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c90")
  287. endif()
  288. list(APPEND uv_defines
  289. _XOPEN_SOURCE=500
  290. )
  291. else()
  292. if(NOT CMAKE_C_STANDARD OR CMAKE_C_STANDARD EQUAL 90)
  293. set(CMAKE_C_STANDARD 11)
  294. endif()
  295. if(CMAKE_VERSION VERSION_LESS 3.8.20170505 AND CMAKE_C_COMPILER_ID STREQUAL "SunPro" AND CMAKE_C_COMPILER_VERSION VERSION_LESS 5.14)
  296. # The running version of CMake does not know how to add this flag.
  297. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -xc99")
  298. endif()
  299. list(APPEND uv_defines
  300. _XOPEN_SOURCE=600
  301. )
  302. endif()
  303. list(APPEND uv_sources
  304. src/unix/no-proctitle.c
  305. src/unix/sunos.c
  306. )
  307. endif()
  308. if(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
  309. list(APPEND uv_libraries
  310. rt
  311. )
  312. list(APPEND uv_headers
  313. include/uv/posix.h
  314. )
  315. list(APPEND uv_defines
  316. _XOPEN_SOURCE_EXTENDED
  317. )
  318. list(APPEND uv_sources
  319. src/unix/hpux.c
  320. src/unix/no-fsevents.c
  321. src/unix/posix-poll.c
  322. )
  323. endif()
  324. if(CMAKE_SYSTEM_NAME STREQUAL "QNX")
  325. list(APPEND uv_headers
  326. include/uv/posix.h
  327. )
  328. list(APPEND uv_defines
  329. _XOPEN_SOURCE=700
  330. )
  331. list(APPEND uv_sources
  332. src/unix/posix-hrtime.c
  333. src/unix/posix-poll.c
  334. src/unix/no-fsevents.c
  335. src/unix/no-proctitle.c
  336. )
  337. list(APPEND uv_libraries
  338. socket
  339. )
  340. endif()
  341. include_directories(
  342. ${uv_includes}
  343. ${KWSYS_HEADER_ROOT}
  344. )
  345. add_library(cmlibuv STATIC ${uv_sources})
  346. target_link_libraries(cmlibuv ${uv_libraries})
  347. set_property(TARGET cmlibuv PROPERTY COMPILE_DEFINITIONS ${uv_defines})
  348. install(FILES LICENSE DESTINATION ${CMAKE_DOC_DIR}/cmlibuv)