CMakeLists.txt 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. #
  2. # Copyright (c) 2012-2013 Martin Sustrik All rights reserved.
  3. # Copyright (c) 2013 GoPivotal, Inc. All rights reserved.
  4. # Copyright (c) 2015-2016 Jack R. Dunaway. All rights reserved.
  5. #
  6. # Permission is hereby granted, free of charge, to any person obtaining a copy
  7. # of this software and associated documentation files (the "Software"),
  8. # to deal in the Software without restriction, including without limitation
  9. # the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. # and/or sell copies of the Software, and to permit persons to whom
  11. # the Software is furnished to do so, subject to the following conditions:
  12. #
  13. # The above copyright notice and this permission notice shall be included
  14. # in all copies or substantial portions of the Software.
  15. #
  16. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  21. # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  22. # IN THE SOFTWARE.
  23. #
  24. set (NN_SOURCES
  25. nn.h
  26. inproc.h
  27. ipc.h
  28. tcp.h
  29. ws.h
  30. pair.h
  31. pubsub.h
  32. reqrep.h
  33. pipeline.h
  34. survey.h
  35. bus.h
  36. core/ep.h
  37. core/ep.c
  38. core/epbase.c
  39. core/global.h
  40. core/global.c
  41. core/pipe.c
  42. core/poll.c
  43. core/sock.h
  44. core/sock.c
  45. core/sockbase.c
  46. core/symbol.c
  47. aio/ctx.h
  48. aio/ctx.c
  49. aio/fsm.h
  50. aio/fsm.c
  51. aio/pool.h
  52. aio/pool.c
  53. aio/timer.h
  54. aio/timer.c
  55. aio/timerset.h
  56. aio/timerset.c
  57. aio/usock.h
  58. aio/usock.c
  59. aio/worker.h
  60. aio/worker.c
  61. utils/alloc.h
  62. utils/alloc.c
  63. utils/atomic.h
  64. utils/atomic.c
  65. utils/attr.h
  66. utils/chunk.h
  67. utils/chunk.c
  68. utils/chunkref.h
  69. utils/chunkref.c
  70. utils/clock.h
  71. utils/clock.c
  72. utils/closefd.h
  73. utils/closefd.c
  74. utils/cont.h
  75. utils/efd.h
  76. utils/efd.c
  77. utils/err.h
  78. utils/err.c
  79. utils/fast.h
  80. utils/fd.h
  81. utils/hash.h
  82. utils/hash.c
  83. utils/list.h
  84. utils/list.c
  85. utils/msg.h
  86. utils/msg.c
  87. utils/condvar.h
  88. utils/condvar.c
  89. utils/mutex.h
  90. utils/mutex.c
  91. utils/once.h
  92. utils/once.c
  93. utils/queue.h
  94. utils/queue.c
  95. utils/random.h
  96. utils/random.c
  97. utils/sem.h
  98. utils/sem.c
  99. utils/sleep.h
  100. utils/sleep.c
  101. utils/thread.h
  102. utils/thread.c
  103. utils/wire.h
  104. utils/wire.c
  105. devices/device.h
  106. devices/device.c
  107. protocols/utils/dist.h
  108. protocols/utils/dist.c
  109. protocols/utils/excl.h
  110. protocols/utils/excl.c
  111. protocols/utils/fq.h
  112. protocols/utils/fq.c
  113. protocols/utils/lb.h
  114. protocols/utils/lb.c
  115. protocols/utils/priolist.h
  116. protocols/utils/priolist.c
  117. protocols/bus/bus.h
  118. protocols/bus/bus.c
  119. protocols/bus/xbus.h
  120. protocols/bus/xbus.c
  121. protocols/pipeline/push.h
  122. protocols/pipeline/push.c
  123. protocols/pipeline/pull.h
  124. protocols/pipeline/pull.c
  125. protocols/pipeline/xpull.h
  126. protocols/pipeline/xpull.c
  127. protocols/pipeline/xpush.h
  128. protocols/pipeline/xpush.c
  129. protocols/pair/pair.h
  130. protocols/pair/pair.c
  131. protocols/pair/xpair.h
  132. protocols/pair/xpair.c
  133. protocols/pubsub/pub.h
  134. protocols/pubsub/pub.c
  135. protocols/pubsub/sub.h
  136. protocols/pubsub/sub.c
  137. protocols/pubsub/trie.h
  138. protocols/pubsub/trie.c
  139. protocols/pubsub/xpub.h
  140. protocols/pubsub/xpub.c
  141. protocols/pubsub/xsub.h
  142. protocols/pubsub/xsub.c
  143. protocols/reqrep/req.h
  144. protocols/reqrep/req.c
  145. protocols/reqrep/rep.h
  146. protocols/reqrep/rep.c
  147. protocols/reqrep/task.h
  148. protocols/reqrep/task.c
  149. protocols/reqrep/xrep.h
  150. protocols/reqrep/xrep.c
  151. protocols/reqrep/xreq.h
  152. protocols/reqrep/xreq.c
  153. protocols/survey/respondent.h
  154. protocols/survey/respondent.c
  155. protocols/survey/surveyor.h
  156. protocols/survey/surveyor.c
  157. protocols/survey/xrespondent.h
  158. protocols/survey/xrespondent.c
  159. protocols/survey/xsurveyor.h
  160. protocols/survey/xsurveyor.c
  161. transports/utils/backoff.h
  162. transports/utils/backoff.c
  163. transports/utils/dns.h
  164. transports/utils/dns.c
  165. transports/utils/dns_getaddrinfo.h
  166. transports/utils/dns_getaddrinfo.inc
  167. transports/utils/dns_getaddrinfo_a.h
  168. transports/utils/dns_getaddrinfo_a.inc
  169. transports/utils/iface.h
  170. transports/utils/iface.c
  171. transports/utils/literal.h
  172. transports/utils/literal.c
  173. transports/utils/port.h
  174. transports/utils/port.c
  175. transports/utils/streamhdr.h
  176. transports/utils/streamhdr.c
  177. transports/utils/base64.h
  178. transports/utils/base64.c
  179. transports/inproc/binproc.h
  180. transports/inproc/binproc.c
  181. transports/inproc/cinproc.h
  182. transports/inproc/cinproc.c
  183. transports/inproc/inproc.h
  184. transports/inproc/inproc.c
  185. transports/inproc/ins.h
  186. transports/inproc/ins.c
  187. transports/inproc/msgqueue.h
  188. transports/inproc/msgqueue.c
  189. transports/inproc/sinproc.h
  190. transports/inproc/sinproc.c
  191. transports/ipc/aipc.h
  192. transports/ipc/aipc.c
  193. transports/ipc/bipc.h
  194. transports/ipc/bipc.c
  195. transports/ipc/cipc.h
  196. transports/ipc/cipc.c
  197. transports/ipc/ipc.h
  198. transports/ipc/ipc.c
  199. transports/ipc/sipc.h
  200. transports/ipc/sipc.c
  201. transports/tcp/atcp.h
  202. transports/tcp/atcp.c
  203. transports/tcp/btcp.h
  204. transports/tcp/btcp.c
  205. transports/tcp/ctcp.h
  206. transports/tcp/ctcp.c
  207. transports/tcp/stcp.h
  208. transports/tcp/stcp.c
  209. transports/tcp/tcp.h
  210. transports/tcp/tcp.c
  211. transports/ws/aws.h
  212. transports/ws/aws.c
  213. transports/ws/bws.h
  214. transports/ws/bws.c
  215. transports/ws/cws.h
  216. transports/ws/cws.c
  217. transports/ws/sws.h
  218. transports/ws/sws.c
  219. transports/ws/ws.h
  220. transports/ws/ws.c
  221. transports/ws/ws_handshake.h
  222. transports/ws/ws_handshake.c
  223. transports/ws/sha1.h
  224. transports/ws/sha1.c
  225. )
  226. if (WIN32)
  227. list (APPEND NN_SOURCES
  228. aio/usock_win.h
  229. aio/usock_win.inc
  230. aio/worker_win.h
  231. aio/worker_win.inc
  232. utils/thread_win.h
  233. utils/thread_win.inc
  234. utils/win.h
  235. )
  236. elseif (UNIX)
  237. list (APPEND NN_SOURCES
  238. aio/usock_posix.h
  239. aio/usock_posix.inc
  240. aio/worker_posix.h
  241. aio/worker_posix.inc
  242. utils/thread_posix.h
  243. utils/thread_posix.inc
  244. )
  245. else ()
  246. message (FATAL_ERROR "Assertion failed; this path is unreachable.")
  247. endif ()
  248. if (NN_HAVE_EPOLL)
  249. add_definitions (-DNN_USE_EPOLL)
  250. list (APPEND NN_SOURCES
  251. aio/poller.h
  252. aio/poller.c
  253. aio/poller_epoll.h
  254. aio/poller_epoll.inc
  255. )
  256. elseif (NN_HAVE_KQUEUE)
  257. add_definitions (-DNN_USE_KQUEUE)
  258. list (APPEND NN_SOURCES
  259. aio/poller.h
  260. aio/poller.c
  261. aio/poller_kqueue.h
  262. aio/poller_kqueue.inc
  263. )
  264. elseif (NN_HAVE_POLL)
  265. add_definitions (-DNN_USE_POLL)
  266. list (APPEND NN_SOURCES
  267. aio/poller.h
  268. aio/poller.c
  269. aio/poller_poll.h
  270. aio/poller_poll.inc
  271. )
  272. elseif (NN_HAVE_WINSOCK)
  273. # No operation
  274. else ()
  275. message (SEND_ERROR "ERROR: could not determine socket polling method.")
  276. message (SEND_ERROR "${ISSUE_REPORT_MSG}" )
  277. endif ()
  278. if (NN_HAVE_EVENTFD)
  279. add_definitions (-DNN_USE_EVENTFD)
  280. list (APPEND NN_SOURCES
  281. utils/efd_eventfd.h
  282. utils/efd_eventfd.inc
  283. )
  284. elseif (NN_HAVE_PIPE)
  285. add_definitions (-DNN_USE_PIPE)
  286. list (APPEND NN_SOURCES
  287. utils/efd_pipe.h
  288. utils/efd_pipe.inc
  289. )
  290. elseif (NN_HAVE_SOCKETPAIR)
  291. add_definitions (-DNN_USE_SOCKETPAIR)
  292. list (APPEND NN_SOURCES
  293. utils/efd_socketpair.h
  294. utils/efd_socketpair.inc
  295. )
  296. elseif (NN_HAVE_WINSOCK)
  297. add_definitions (-DNN_USE_WINSOCK)
  298. list (APPEND NN_SOURCES
  299. utils/efd_win.h
  300. utils/efd_win.inc
  301. )
  302. else ()
  303. message (SEND_ERROR "ERROR: could not determine socket signaling method.")
  304. message (SEND_ERROR "${ISSUE_REPORT_MSG}" )
  305. endif ()
  306. # Provide same folder structure in IDE as on disk
  307. foreach (f ${NN_SOURCES})
  308. # Get the path of the file relative to source directory
  309. if (IS_ABSOLUTE "${f}")
  310. file (RELATIVE_PATH f ${CMAKE_CURRENT_SOURCE_DIR} ${f})
  311. endif ()
  312. set (SRC_GROUP "${f}")
  313. set (f "${CMAKE_CURRENT_SOURCE_DIR}/${f}")
  314. # Remove the filename part
  315. string (REGEX REPLACE "(.*)(/[^/]*)$" "\\1" SRC_GROUP ${SRC_GROUP})
  316. # CMake source_group expects \\, not /
  317. string (REPLACE / \\ SRC_GROUP ${SRC_GROUP})
  318. source_group ("${SRC_GROUP}" FILES ${f})
  319. endforeach ()
  320. if (NN_STATIC_LIB)
  321. add_library (${PROJECT_NAME} STATIC ${NN_SOURCES})
  322. else ()
  323. add_library (${PROJECT_NAME} SHARED ${NN_SOURCES})
  324. add_definitions (-DNN_SHARED_LIB)
  325. set_target_properties (${PROJECT_NAME} PROPERTIES
  326. VERSION "${NN_PACKAGE_VERSION}"
  327. SOVERSION "${NN_ABI_VERSION}")
  328. endif ()
  329. # Set library outputs same as top-level project binary outputs
  330. set_target_properties (${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
  331. set_target_properties (${PROJECT_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
  332. set_target_properties (${PROJECT_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
  333. target_link_libraries (${PROJECT_NAME} ${NN_REQUIRED_LIBRARIES})
  334. if(THREADS_HAVE_PTHREAD_ARG)
  335. add_definitions (-pthread)
  336. endif()
  337. if(CMAKE_THREAD_LIBS_INIT)
  338. target_link_libraries (${PROJECT_NAME} "${CMAKE_THREAD_LIBS_INIT}")
  339. endif()
  340. # pkg-config file
  341. if(NN_REQUIRED_LIBRARIES)
  342. foreach (lib ${NN_REQUIRED_LIBRARIES})
  343. set (NN_REQUIRED_LFLAGS "${NN_REQUIRED_LFLAGS} -l${lib}")
  344. endforeach()
  345. endif()
  346. configure_file (pkgconfig.in ${PROJECT_NAME}.pc @ONLY)
  347. install (
  348. FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc
  349. DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
  350. install (TARGETS ${PROJECT_NAME}
  351. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  352. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  353. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  354. )