CMakeLists.txt 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. project(libuv C)
  2. # Disable warnings to avoid changing 3rd party code.
  3. if(CMAKE_C_COMPILER_ID MATCHES
  4. "^(GNU|Clang|AppleClang|XL|VisualAge|SunPro|MIPSpro|HP|Intel)$")
  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/inet.c
  22. src/queue.h
  23. src/threadpool.c
  24. src/uv-common.c
  25. src/uv-common.h
  26. src/uv-data-getter-setters.c
  27. src/version.c
  28. )
  29. if(WIN32)
  30. list(APPEND uv_libraries
  31. ws2_32
  32. psapi
  33. iphlpapi
  34. shell32
  35. userenv
  36. )
  37. list(APPEND uv_includes
  38. src/win
  39. )
  40. list(APPEND uv_defines
  41. WIN32_LEAN_AND_MEAN
  42. _WIN32_WINNT=0x0600
  43. )
  44. list(APPEND uv_headers
  45. include/uv-win.h
  46. include/tree.h
  47. )
  48. list(APPEND uv_sources
  49. src/win/async.c
  50. src/win/atomicops-inl.h
  51. src/win/core.c
  52. src/win/detect-wakeup.c
  53. src/win/dl.c
  54. src/win/error.c
  55. src/win/fs-event.c
  56. src/win/fs.c
  57. src/win/getaddrinfo.c
  58. src/win/getnameinfo.c
  59. src/win/handle.c
  60. src/win/handle-inl.h
  61. src/win/internal.h
  62. src/win/loop-watcher.c
  63. src/win/pipe.c
  64. src/win/poll.c
  65. src/win/process-stdio.c
  66. src/win/process.c
  67. src/win/req.c
  68. src/win/req-inl.h
  69. src/win/signal.c
  70. src/win/snprintf.c
  71. src/win/stream.c
  72. src/win/stream-inl.h
  73. src/win/tcp.c
  74. src/win/thread.c
  75. src/win/timer.c
  76. src/win/tty.c
  77. src/win/udp.c
  78. src/win/util.c
  79. src/win/winapi.c
  80. src/win/winapi.h
  81. src/win/winsock.c
  82. src/win/winsock.h
  83. )
  84. else()
  85. list(APPEND uv_includes
  86. src/unix
  87. )
  88. list(APPEND uv_headers
  89. include/uv-unix.h
  90. )
  91. list(APPEND uv_sources
  92. src/unix/async.c
  93. src/unix/atomic-ops.h
  94. src/unix/core.c
  95. src/unix/dl.c
  96. src/unix/fs.c
  97. src/unix/getaddrinfo.c
  98. src/unix/getnameinfo.c
  99. src/unix/internal.h
  100. src/unix/loop-watcher.c
  101. src/unix/loop.c
  102. src/unix/pipe.c
  103. src/unix/poll.c
  104. src/unix/process.c
  105. src/unix/signal.c
  106. src/unix/spinlock.h
  107. src/unix/stream.c
  108. src/unix/tcp.c
  109. src/unix/thread.c
  110. src/unix/timer.c
  111. src/unix/tty.c
  112. src/unix/udp.c
  113. )
  114. endif()
  115. if(CMAKE_SYSTEM_NAME STREQUAL "AIX")
  116. list(APPEND uv_libraries
  117. perfstat
  118. )
  119. list(APPEND uv_headers
  120. include/uv-aix.h
  121. )
  122. list(APPEND uv_defines
  123. _ALL_SOURCE
  124. _XOPEN_SOURCE=500
  125. _LINUX_SOURCE_COMPAT
  126. _THREAD_SAFE
  127. )
  128. list(APPEND uv_sources
  129. src/unix/aix.c
  130. src/unix/aix-common.c
  131. )
  132. endif()
  133. if(CMAKE_SYSTEM_NAME MATCHES "CYGWIN")
  134. list(APPEND uv_libraries
  135. )
  136. list(APPEND uv_headers
  137. include/uv-posix.h
  138. )
  139. list(APPEND uv_defines
  140. )
  141. list(APPEND uv_sources
  142. src/unix/cygwin.c
  143. src/unix/bsd-ifaddrs.c
  144. src/unix/no-fsevents.c
  145. src/unix/no-proctitle.c
  146. src/unix/posix-hrtime.c
  147. src/unix/posix-poll.c
  148. src/unix/procfs-exepath.c
  149. src/unix/sysinfo-loadavg.c
  150. src/unix/sysinfo-memory.c
  151. )
  152. endif()
  153. if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
  154. list(APPEND uv_headers
  155. include/uv-darwin.h
  156. include/pthread-barrier.h
  157. )
  158. list(APPEND uv_defines
  159. _DARWIN_USE_64_BIT_INODE=1
  160. _DARWIN_UNLIMITED_SELECT=1
  161. )
  162. list(APPEND uv_sources
  163. src/unix/bsd-ifaddrs.c
  164. src/unix/darwin.c
  165. src/unix/darwin-proctitle.c
  166. src/unix/fsevents.c
  167. src/unix/kqueue.c
  168. src/unix/proctitle.c
  169. )
  170. endif()
  171. if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  172. list(APPEND uv_libraries dl rt)
  173. list(APPEND uv_headers
  174. include/uv-linux.h
  175. )
  176. list(APPEND uv_defines _GNU_SOURCE)
  177. list(APPEND uv_sources
  178. src/unix/linux-core.c
  179. src/unix/linux-inotify.c
  180. src/unix/linux-syscalls.c
  181. src/unix/linux-syscalls.h
  182. src/unix/procfs-exepath.c
  183. src/unix/proctitle.c
  184. src/unix/sysinfo-loadavg.c
  185. src/unix/sysinfo-memory.c
  186. )
  187. endif()
  188. if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
  189. list(APPEND uv_libraries
  190. kvm
  191. )
  192. list(APPEND uv_headers
  193. include/uv-bsd.h
  194. )
  195. list(APPEND uv_sources
  196. src/unix/bsd-ifaddrs.c
  197. src/unix/freebsd.c
  198. src/unix/kqueue.c
  199. src/unix/posix-hrtime.c
  200. )
  201. endif()
  202. if(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
  203. list(APPEND uv_libraries
  204. kvm
  205. )
  206. list(APPEND uv_headers
  207. include/uv-bsd.h
  208. )
  209. list(APPEND uv_sources
  210. src/unix/bsd-ifaddrs.c
  211. src/unix/netbsd.c
  212. src/unix/kqueue.c
  213. src/unix/posix-hrtime.c
  214. )
  215. endif()
  216. if(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
  217. list(APPEND uv_libraries
  218. kvm
  219. )
  220. list(APPEND uv_headers
  221. include/uv-bsd.h
  222. )
  223. list(APPEND uv_sources
  224. src/unix/bsd-ifaddrs.c
  225. src/unix/openbsd.c
  226. src/unix/kqueue.c
  227. src/unix/posix-hrtime.c
  228. )
  229. endif()
  230. if(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
  231. list(APPEND uv_libraries
  232. kstat
  233. nsl
  234. sendfile
  235. socket
  236. rt
  237. )
  238. list(APPEND uv_headers
  239. include/uv-sunos.h
  240. )
  241. list(APPEND uv_defines
  242. __EXTENSIONS__
  243. )
  244. if(CMAKE_SYSTEM_VERSION STREQUAL "5.10")
  245. set(CMAKE_C_STANDARD 90)
  246. 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)
  247. # The running version of CMake does not know how to add this flag.
  248. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c90")
  249. endif()
  250. list(APPEND uv_defines
  251. _XOPEN_SOURCE=500
  252. )
  253. else()
  254. if(NOT CMAKE_C_STANDARD OR CMAKE_C_STANDARD EQUAL 90)
  255. set(CMAKE_C_STANDARD 11)
  256. endif()
  257. if(CMAKE_VERSION VERSION_LESS 3.8.20170505 AND CMAKE_C_COMPILER_ID STREQUAL "SunPro" AND CMAKE_C_COMPILER_VERSION VERSION_LESS 5.14)
  258. # The running version of CMake does not know how to add this flag.
  259. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -xc99")
  260. endif()
  261. list(APPEND uv_defines
  262. _XOPEN_SOURCE=600
  263. )
  264. endif()
  265. list(APPEND uv_sources
  266. src/unix/no-proctitle.c
  267. src/unix/sunos.c
  268. )
  269. endif()
  270. include_directories(
  271. ${uv_includes}
  272. ${KWSYS_HEADER_ROOT}
  273. )
  274. add_library(cmlibuv STATIC ${uv_sources})
  275. target_link_libraries(cmlibuv ${uv_libraries})
  276. set_property(TARGET cmlibuv PROPERTY COMPILE_DEFINITIONS ${uv_defines})
  277. install(FILES LICENSE DESTINATION ${CMAKE_DOC_DIR}/cmlibuv)