CMakeLists.txt 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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/strtok.c
  28. src/strtok.h
  29. src/threadpool.c
  30. src/timer.c
  31. src/uv-common.c
  32. src/uv-common.h
  33. src/uv-data-getter-setters.c
  34. src/version.c
  35. )
  36. if(WIN32)
  37. list(APPEND uv_libraries
  38. ws2_32
  39. psapi
  40. iphlpapi
  41. shell32
  42. userenv
  43. )
  44. list(APPEND uv_includes
  45. src/win
  46. )
  47. list(APPEND uv_defines
  48. WIN32_LEAN_AND_MEAN
  49. _WIN32_WINNT=0x0600
  50. )
  51. list(APPEND uv_headers
  52. include/uv/win.h
  53. include/tree.h
  54. )
  55. list(APPEND uv_sources
  56. src/win/async.c
  57. src/win/atomicops-inl.h
  58. src/win/core.c
  59. src/win/detect-wakeup.c
  60. src/win/dl.c
  61. src/win/error.c
  62. src/win/fs-event.c
  63. src/win/fs.c
  64. src/win/getaddrinfo.c
  65. src/win/getnameinfo.c
  66. src/win/handle.c
  67. src/win/handle-inl.h
  68. src/win/internal.h
  69. src/win/loop-watcher.c
  70. src/win/pipe.c
  71. src/win/poll.c
  72. src/win/process-stdio.c
  73. src/win/process.c
  74. src/win/req-inl.h
  75. src/win/signal.c
  76. src/win/snprintf.c
  77. src/win/stream.c
  78. src/win/stream-inl.h
  79. src/win/tcp.c
  80. src/win/thread.c
  81. src/win/tty.c
  82. src/win/udp.c
  83. src/win/util.c
  84. src/win/winapi.c
  85. src/win/winapi.h
  86. src/win/winsock.c
  87. src/win/winsock.h
  88. )
  89. else()
  90. list(APPEND uv_includes
  91. src/unix
  92. )
  93. list(APPEND uv_headers
  94. include/uv/unix.h
  95. )
  96. list(APPEND uv_sources
  97. src/unix/async.c
  98. src/unix/atomic-ops.h
  99. src/unix/core.c
  100. src/unix/dl.c
  101. src/unix/fs.c
  102. src/unix/getaddrinfo.c
  103. src/unix/getnameinfo.c
  104. src/unix/internal.h
  105. src/unix/loop-watcher.c
  106. src/unix/loop.c
  107. src/unix/pipe.c
  108. src/unix/poll.c
  109. src/unix/process.c
  110. src/unix/signal.c
  111. src/unix/spinlock.h
  112. src/unix/stream.c
  113. src/unix/tcp.c
  114. src/unix/thread.c
  115. src/unix/tty.c
  116. src/unix/udp.c
  117. )
  118. endif()
  119. if(CMAKE_SYSTEM_NAME STREQUAL "AIX")
  120. list(APPEND uv_libraries
  121. perfstat
  122. )
  123. list(APPEND uv_headers
  124. include/uv/aix.h
  125. )
  126. list(APPEND uv_defines
  127. _ALL_SOURCE
  128. _XOPEN_SOURCE=500
  129. _LINUX_SOURCE_COMPAT
  130. _THREAD_SAFE
  131. )
  132. list(APPEND uv_sources
  133. src/unix/aix.c
  134. src/unix/aix-common.c
  135. )
  136. endif()
  137. if(CMAKE_SYSTEM_NAME STREQUAL "OS400")
  138. list(APPEND uv_headers
  139. include/uv/posix.h
  140. )
  141. list(APPEND uv_defines
  142. _ALL_SOURCE
  143. _XOPEN_SOURCE=500
  144. _LINUX_SOURCE_COMPAT
  145. _THREAD_SAFE
  146. )
  147. list(APPEND uv_sources
  148. src/unix/aix-common.c
  149. src/unix/ibmi.c
  150. src/unix/posix-poll.c
  151. src/unix/no-fsevents.c
  152. src/unix/no-proctitle.c
  153. )
  154. endif()
  155. if(CMAKE_SYSTEM_NAME MATCHES "CYGWIN" OR CMAKE_SYSTEM_NAME MATCHES "MSYS")
  156. list(APPEND uv_libraries
  157. )
  158. list(APPEND uv_headers
  159. include/uv/posix.h
  160. )
  161. list(APPEND uv_defines
  162. _GNU_SOURCE
  163. )
  164. list(APPEND uv_sources
  165. src/unix/cygwin.c
  166. src/unix/bsd-ifaddrs.c
  167. src/unix/no-fsevents.c
  168. src/unix/no-proctitle.c
  169. src/unix/posix-hrtime.c
  170. src/unix/posix-poll.c
  171. src/unix/procfs-exepath.c
  172. src/unix/sysinfo-loadavg.c
  173. src/unix/sysinfo-memory.c
  174. )
  175. endif()
  176. if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
  177. list(APPEND uv_headers
  178. include/uv/darwin.h
  179. )
  180. list(APPEND uv_defines
  181. _DARWIN_USE_64_BIT_INODE=1
  182. _DARWIN_UNLIMITED_SELECT=1
  183. )
  184. list(APPEND uv_sources
  185. src/unix/bsd-ifaddrs.c
  186. src/unix/darwin.c
  187. src/unix/darwin-proctitle.c
  188. src/unix/fsevents.c
  189. src/unix/kqueue.c
  190. src/unix/proctitle.c
  191. )
  192. endif()
  193. if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  194. list(APPEND uv_libraries dl rt)
  195. list(APPEND uv_headers
  196. include/uv/linux.h
  197. )
  198. list(APPEND uv_defines _GNU_SOURCE)
  199. list(APPEND uv_sources
  200. src/unix/epoll.c
  201. src/unix/linux-core.c
  202. src/unix/linux-inotify.c
  203. src/unix/linux-syscalls.c
  204. src/unix/linux-syscalls.h
  205. src/unix/procfs-exepath.c
  206. src/unix/proctitle.c
  207. src/unix/sysinfo-loadavg.c
  208. src/unix/sysinfo-memory.c
  209. )
  210. endif()
  211. if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
  212. list(APPEND uv_libraries
  213. )
  214. list(APPEND uv_headers
  215. include/uv/bsd.h
  216. )
  217. list(APPEND uv_sources
  218. src/unix/bsd-ifaddrs.c
  219. src/unix/bsd-proctitle.c
  220. src/unix/freebsd.c
  221. src/unix/kqueue.c
  222. src/unix/posix-hrtime.c
  223. )
  224. endif()
  225. if(CMAKE_SYSTEM_NAME STREQUAL "kFreeBSD")
  226. list(APPEND uv_libraries
  227. freebsd-glue
  228. )
  229. list(APPEND uv_headers
  230. include/uv/bsd.h
  231. )
  232. list(APPEND uv_sources
  233. src/unix/bsd-ifaddrs.c
  234. src/unix/bsd-proctitle.c
  235. src/unix/freebsd.c
  236. src/unix/kqueue.c
  237. src/unix/posix-hrtime.c
  238. )
  239. endif()
  240. if(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
  241. list(APPEND uv_libraries
  242. kvm
  243. )
  244. list(APPEND uv_headers
  245. include/uv/bsd.h
  246. )
  247. list(APPEND uv_sources
  248. src/unix/bsd-ifaddrs.c
  249. src/unix/bsd-proctitle.c
  250. src/unix/netbsd.c
  251. src/unix/kqueue.c
  252. src/unix/posix-hrtime.c
  253. )
  254. endif()
  255. if(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
  256. list(APPEND uv_libraries
  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. _XOPEN_SOURCE=600
  283. )
  284. if(NOT CMAKE_C_STANDARD OR CMAKE_C_STANDARD EQUAL 90)
  285. set(CMAKE_C_STANDARD 11)
  286. endif()
  287. if(CMAKE_SYSTEM_VERSION STREQUAL "5.10")
  288. list(APPEND uv_defines SUNOS_NO_IFADDRS)
  289. if(CMAKE_SYSTEM_PROCESSOR STREQUAL "i386")
  290. list(APPEND uv_defines CMAKE_NO_MKDTEMP)
  291. endif()
  292. endif()
  293. list(APPEND uv_sources
  294. src/unix/no-proctitle.c
  295. src/unix/sunos.c
  296. )
  297. endif()
  298. if(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
  299. list(APPEND uv_libraries
  300. rt
  301. )
  302. list(APPEND uv_headers
  303. include/uv/posix.h
  304. )
  305. list(APPEND uv_defines
  306. _XOPEN_SOURCE_EXTENDED
  307. CMAKE_NO_MKDTEMP
  308. )
  309. list(APPEND uv_sources
  310. src/unix/hpux.c
  311. src/unix/no-fsevents.c
  312. src/unix/posix-poll.c
  313. )
  314. endif()
  315. if(CMAKE_SYSTEM_NAME STREQUAL "QNX")
  316. list(APPEND uv_headers
  317. include/uv/posix.h
  318. )
  319. list(APPEND uv_defines
  320. _XOPEN_SOURCE=700
  321. )
  322. list(APPEND uv_sources
  323. src/unix/posix-hrtime.c
  324. src/unix/posix-poll.c
  325. src/unix/no-fsevents.c
  326. src/unix/no-proctitle.c
  327. )
  328. list(APPEND uv_libraries
  329. socket
  330. )
  331. endif()
  332. include_directories(
  333. ${uv_includes}
  334. ${KWSYS_HEADER_ROOT}
  335. )
  336. add_library(cmlibuv STATIC ${uv_sources})
  337. target_link_libraries(cmlibuv ${uv_libraries})
  338. set_property(TARGET cmlibuv PROPERTY COMPILE_DEFINITIONS ${uv_defines})
  339. if(WIN32 AND CMake_BUILD_PCH)
  340. target_precompile_headers(cmlibuv PRIVATE "include/uv.h" "src/win/internal.h")
  341. endif()
  342. install(FILES LICENSE DESTINATION ${CMAKE_DOC_DIR}/cmlibuv)