CMakeLists.txt 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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/version.c
  27. )
  28. if(WIN32)
  29. list(APPEND uv_libraries
  30. ws2_32
  31. psapi
  32. iphlpapi
  33. shell32
  34. userenv
  35. )
  36. list(APPEND uv_includes
  37. src/win
  38. )
  39. list(APPEND uv_defines
  40. WIN32_LEAN_AND_MEAN
  41. _WIN32_WINNT=0x0600
  42. )
  43. list(APPEND uv_headers
  44. include/uv-win.h
  45. include/tree.h
  46. )
  47. list(APPEND uv_sources
  48. src/win/async.c
  49. src/win/atomicops-inl.h
  50. src/win/core.c
  51. src/win/detect-wakeup.c
  52. src/win/dl.c
  53. src/win/error.c
  54. src/win/fs-event.c
  55. src/win/fs.c
  56. src/win/getaddrinfo.c
  57. src/win/getnameinfo.c
  58. src/win/handle.c
  59. src/win/handle-inl.h
  60. src/win/internal.h
  61. src/win/loop-watcher.c
  62. src/win/pipe.c
  63. src/win/poll.c
  64. src/win/process-stdio.c
  65. src/win/process.c
  66. src/win/req.c
  67. src/win/req-inl.h
  68. src/win/signal.c
  69. src/win/snprintf.c
  70. src/win/stream.c
  71. src/win/stream-inl.h
  72. src/win/tcp.c
  73. src/win/thread.c
  74. src/win/timer.c
  75. src/win/tty.c
  76. src/win/udp.c
  77. src/win/util.c
  78. src/win/winapi.c
  79. src/win/winapi.h
  80. src/win/winsock.c
  81. src/win/winsock.h
  82. )
  83. else()
  84. list(APPEND uv_includes
  85. src/unix
  86. )
  87. list(APPEND uv_headers
  88. include/uv-unix.h
  89. )
  90. list(APPEND uv_sources
  91. src/unix/async.c
  92. src/unix/atomic-ops.h
  93. src/unix/core.c
  94. src/unix/dl.c
  95. src/unix/fs.c
  96. src/unix/getaddrinfo.c
  97. src/unix/getnameinfo.c
  98. src/unix/internal.h
  99. src/unix/loop-watcher.c
  100. src/unix/loop.c
  101. src/unix/pipe.c
  102. src/unix/poll.c
  103. src/unix/process.c
  104. src/unix/signal.c
  105. src/unix/spinlock.h
  106. src/unix/stream.c
  107. src/unix/tcp.c
  108. src/unix/thread.c
  109. src/unix/timer.c
  110. src/unix/tty.c
  111. src/unix/udp.c
  112. )
  113. endif()
  114. if(CMAKE_SYSTEM_NAME STREQUAL "AIX")
  115. list(APPEND uv_libraries
  116. perfstat
  117. )
  118. list(APPEND uv_headers
  119. include/uv-aix.h
  120. )
  121. list(APPEND uv_defines
  122. _ALL_SOURCE
  123. _XOPEN_SOURCE=500
  124. _LINUX_SOURCE_COMPAT
  125. _THREAD_SAFE
  126. )
  127. list(APPEND uv_sources
  128. src/unix/aix.c
  129. )
  130. endif()
  131. if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
  132. list(APPEND uv_headers
  133. include/uv-darwin.h
  134. include/pthread-barrier.h
  135. )
  136. list(APPEND uv_defines
  137. _DARWIN_USE_64_BIT_INODE=1
  138. _DARWIN_UNLIMITED_SELECT=1
  139. )
  140. list(APPEND uv_sources
  141. src/unix/darwin.c
  142. src/unix/darwin-proctitle.c
  143. src/unix/fsevents.c
  144. src/unix/kqueue.c
  145. src/unix/proctitle.c
  146. src/unix/pthread-barrier.c
  147. )
  148. endif()
  149. if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  150. list(APPEND uv_libraries dl rt)
  151. list(APPEND uv_headers
  152. include/uv-linux.h
  153. )
  154. list(APPEND uv_defines _GNU_SOURCE)
  155. list(APPEND uv_sources
  156. src/unix/linux-core.c
  157. src/unix/linux-inotify.c
  158. src/unix/linux-syscalls.c
  159. src/unix/linux-syscalls.h
  160. src/unix/proctitle.c
  161. )
  162. endif()
  163. if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
  164. list(APPEND uv_libraries
  165. kvm
  166. )
  167. list(APPEND uv_headers
  168. include/uv-bsd.h
  169. )
  170. list(APPEND uv_sources
  171. src/unix/freebsd.c
  172. src/unix/kqueue.c
  173. )
  174. endif()
  175. if(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
  176. list(APPEND uv_libraries
  177. kvm
  178. )
  179. list(APPEND uv_headers
  180. include/uv-bsd.h
  181. )
  182. list(APPEND uv_sources
  183. src/unix/netbsd.c
  184. src/unix/kqueue.c
  185. )
  186. endif()
  187. if(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
  188. list(APPEND uv_libraries
  189. kvm
  190. )
  191. list(APPEND uv_headers
  192. include/uv-bsd.h
  193. )
  194. list(APPEND uv_sources
  195. src/unix/openbsd.c
  196. src/unix/kqueue.c
  197. )
  198. endif()
  199. if(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
  200. list(APPEND uv_libraries
  201. kstat
  202. nsl
  203. sendfile
  204. socket
  205. )
  206. list(APPEND uv_headers
  207. include/uv-sunos.h
  208. )
  209. list(APPEND uv_defines
  210. __EXTENSIONS__
  211. )
  212. if(CMAKE_SYSTEM_VERSION STREQUAL "5.10")
  213. list(APPEND uv_defines
  214. _XOPEN_SOURCE=500
  215. )
  216. else()
  217. list(APPEND uv_defines
  218. _XOPEN_SOURCE=600
  219. )
  220. endif()
  221. list(APPEND uv_sources
  222. src/unix/sunos.c
  223. )
  224. endif()
  225. include_directories(
  226. ${uv_includes}
  227. ${KWSYS_HEADER_ROOT}
  228. )
  229. add_library(cmlibuv STATIC ${uv_sources})
  230. target_link_libraries(cmlibuv ${uv_libraries})
  231. set_property(TARGET cmlibuv PROPERTY COMPILE_DEFINITIONS ${uv_defines})
  232. install(FILES LICENSE DESTINATION ${CMAKE_DOC_DIR}/cmlibuv)