CMakeLists.txt 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. cmake_minimum_required(VERSION 3.4)
  2. project(libuv LANGUAGES C)
  3. cmake_policy(SET CMP0057 NEW) # Enable IN_LIST operator
  4. cmake_policy(SET CMP0064 NEW) # Support if (TEST) operator
  5. list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
  6. include(CMakePackageConfigHelpers)
  7. include(CMakeDependentOption)
  8. include(CheckCCompilerFlag)
  9. include(GNUInstallDirs)
  10. include(CTest)
  11. set(CMAKE_C_VISIBILITY_PRESET hidden)
  12. set(CMAKE_C_STANDARD_REQUIRED ON)
  13. set(CMAKE_C_EXTENSIONS ON)
  14. set(CMAKE_C_STANDARD 90)
  15. cmake_dependent_option(LIBUV_BUILD_TESTS
  16. "Build the unit tests when BUILD_TESTING is enabled and we are the root project" ON
  17. "BUILD_TESTING;CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR" OFF)
  18. cmake_dependent_option(LIBUV_BUILD_BENCH
  19. "Build the benchmarks when building unit tests and we are the root project" ON
  20. "LIBUV_BUILD_TESTS" OFF)
  21. # Compiler check
  22. string(CONCAT is-msvc $<OR:
  23. $<C_COMPILER_ID:MSVC>,
  24. $<STREQUAL:${CMAKE_C_COMPILER_FRONTEND_VARIANT},MSVC>
  25. >)
  26. check_c_compiler_flag(/W4 UV_LINT_W4)
  27. check_c_compiler_flag(-Wall UV_LINT_WALL) # DO NOT use this under MSVC
  28. # TODO: Place these into its own function
  29. check_c_compiler_flag(-Wno-unused-parameter UV_LINT_NO_UNUSED_PARAMETER)
  30. check_c_compiler_flag(-Wstrict-prototypes UV_LINT_STRICT_PROTOTYPES)
  31. check_c_compiler_flag(-Wextra UV_LINT_EXTRA)
  32. set(lint-no-unused-parameter $<$<BOOL:${UV_LINT_NO_UNUSED_PARAMETER}>:-Wno-unused-parameter>)
  33. set(lint-strict-prototypes $<$<BOOL:${UV_LINT_STRICT_PROTOTYPES}>:-Wstrict-prototypes>)
  34. set(lint-extra $<$<BOOL:${UV_LINT_EXTRA}>:-Wextra>)
  35. set(lint-w4 $<$<BOOL:${UV_LINT_W4}>:/W4>)
  36. # Unfortunately, this one is complicated because MSVC and clang-cl support -Wall
  37. # but using it is like calling -Weverything
  38. string(CONCAT lint-default $<
  39. $<AND:$<BOOL:${UV_LINT_WALL}>,$<NOT:${is-msvc}>>:-Wall
  40. >)
  41. list(APPEND uv_cflags ${lint-strict-prototypes} ${lint-extra} ${lint-default} ${lint-w4})
  42. list(APPEND uv_cflags ${lint-no-unused-parameter})
  43. set(uv_sources
  44. src/fs-poll.c
  45. src/idna.c
  46. src/inet.c
  47. src/random.c
  48. src/strscpy.c
  49. src/threadpool.c
  50. src/timer.c
  51. src/uv-common.c
  52. src/uv-data-getter-setters.c
  53. src/version.c)
  54. if(WIN32)
  55. if (CMAKE_SYSTEM_VERSION VERSION_GREATER 10) # Windows 10
  56. set(windows-version 0x0A00)
  57. elseif (CMAKE_SYSTEM_VERSION VERSION_GREATER 6.3) # Windows 8.1
  58. set(windows-version 0x0603)
  59. elseif (CMAKE_SYSTEM_VERSION VERSION_GREATER 6.2) # Windows 8
  60. set(windows-version 0x0602)
  61. elseif (CMAKE_SYSTEM_VERSION VERSION_GREATER 6.1) # Windows 7
  62. set(windows-version 0x0601)
  63. elseif (CMAKE_SYSTEM_VERSION VERSION_GREATER 6.0) # Windows Vista
  64. set(windows-version 0x0600)
  65. else()
  66. message(FATAL_ERROR "Windows Vista is the minimum version supported")
  67. endif()
  68. list(APPEND uv_defines WIN32_LEAN_AND_MEAN _WIN32_WINNT=${windows-version})
  69. list(APPEND uv_libraries
  70. $<$<STREQUAL:${windows-version},0x0600>:psapi>
  71. iphlpapi
  72. userenv
  73. ws2_32)
  74. list(APPEND uv_sources
  75. src/win/async.c
  76. src/win/core.c
  77. src/win/detect-wakeup.c
  78. src/win/dl.c
  79. src/win/error.c
  80. src/win/fs.c
  81. src/win/fs-event.c
  82. src/win/getaddrinfo.c
  83. src/win/getnameinfo.c
  84. src/win/handle.c
  85. src/win/loop-watcher.c
  86. src/win/pipe.c
  87. src/win/thread.c
  88. src/win/poll.c
  89. src/win/process.c
  90. src/win/process-stdio.c
  91. src/win/signal.c
  92. src/win/snprintf.c
  93. src/win/stream.c
  94. src/win/tcp.c
  95. src/win/tty.c
  96. src/win/udp.c
  97. src/win/util.c
  98. src/win/winapi.c
  99. src/win/winsock.c)
  100. list(APPEND uv_test_libraries ws2_32)
  101. list(APPEND uv_test_sources src/win/snprintf.c test/runner-win.c)
  102. else()
  103. list(APPEND uv_defines _FILE_OFFSET_BITS=64 _LARGEFILE_SOURCE)
  104. if(NOT CMAKE_SYSTEM_NAME MATCHES "Android|OS390")
  105. # TODO: This should be replaced with find_package(Threads) if possible
  106. # Android has pthread as part of its c library, not as a separate
  107. # libpthread.so.
  108. list(APPEND uv_libraries pthread)
  109. endif()
  110. list(APPEND uv_sources
  111. src/unix/async.c
  112. src/unix/core.c
  113. src/unix/dl.c
  114. src/unix/fs.c
  115. src/unix/getaddrinfo.c
  116. src/unix/getnameinfo.c
  117. src/unix/loop-watcher.c
  118. src/unix/loop.c
  119. src/unix/pipe.c
  120. src/unix/poll.c
  121. src/unix/process.c
  122. src/unix/random-devurandom.c
  123. src/unix/signal.c
  124. src/unix/stream.c
  125. src/unix/tcp.c
  126. src/unix/thread.c
  127. src/unix/tty.c
  128. src/unix/udp.c)
  129. list(APPEND uv_test_sources test/runner-unix.c)
  130. endif()
  131. if(CMAKE_SYSTEM_NAME STREQUAL "AIX")
  132. list(APPEND uv_defines
  133. _ALL_SOURCE
  134. _LINUX_SOURCE_COMPAT
  135. _THREAD_SAFE
  136. _XOPEN_SOURCE=500
  137. HAVE_SYS_AHAFS_EVPRODS_H)
  138. list(APPEND uv_libraries perfstat)
  139. list(APPEND uv_sources
  140. src/unix/aix.c
  141. src/unix/aix-common.c)
  142. endif()
  143. if(CMAKE_SYSTEM_NAME STREQUAL "Android")
  144. list(APPEND uv_libs dl)
  145. list(APPEND uv_sources
  146. src/unix/android-ifaddrs.c
  147. src/unix/linux-core.c
  148. src/unix/linux-inotify.c
  149. src/unix/linux-syscalls.c
  150. src/unix/procfs-exepath.c
  151. src/unix/pthread-fixes.c
  152. src/unix/random-getentropy.c
  153. src/unix/random-getrandom.c
  154. src/unix/random-sysctl-linux.c
  155. src/unix/sysinfo-loadavg.c)
  156. endif()
  157. if(APPLE OR CMAKE_SYSTEM_NAME MATCHES "Android|Linux|OS390")
  158. list(APPEND uv_sources src/unix/proctitle.c)
  159. endif()
  160. if(CMAKE_SYSTEM_NAME MATCHES "DragonFly|FreeBSD")
  161. list(APPEND uv_sources src/unix/freebsd.c)
  162. endif()
  163. if(CMAKE_SYSTEM_NAME MATCHES "DragonFly|FreeBSD|NetBSD|OpenBSD")
  164. list(APPEND uv_sources src/unix/posix-hrtime.c src/unix/bsd-proctitle.c)
  165. list(APPEND uv_libraries kvm)
  166. endif()
  167. if(APPLE OR CMAKE_SYSTEM_NAME MATCHES "DragonFly|FreeBSD|NetBSD|OpenBSD")
  168. list(APPEND uv_sources src/unix/bsd-ifaddrs.c src/unix/kqueue.c)
  169. endif()
  170. if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
  171. list(APPEND uv_sources src/unix/random-getrandom.c)
  172. endif()
  173. if(APPLE OR CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
  174. list(APPEND uv_sources src/unix/random-getentropy.c)
  175. endif()
  176. if(APPLE)
  177. list(APPEND uv_defines _DARWIN_UNLIMITED_SELECT=1 _DARWIN_USE_64_BIT_INODE=1)
  178. list(APPEND uv_sources
  179. src/unix/darwin-proctitle.c
  180. src/unix/darwin.c
  181. src/unix/fsevents.c)
  182. endif()
  183. if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  184. list(APPEND uv_defines _GNU_SOURCE _POSIX_C_SOURCE=200112)
  185. list(APPEND uv_libraries dl rt)
  186. list(APPEND uv_sources
  187. src/unix/linux-core.c
  188. src/unix/linux-inotify.c
  189. src/unix/linux-syscalls.c
  190. src/unix/procfs-exepath.c
  191. src/unix/random-getrandom.c
  192. src/unix/random-sysctl-linux.c
  193. src/unix/sysinfo-loadavg.c)
  194. endif()
  195. if(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
  196. list(APPEND uv_sources src/unix/netbsd.c)
  197. endif()
  198. if(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
  199. list(APPEND uv_sources src/unix/openbsd.c)
  200. endif()
  201. if(CMAKE_SYSTEM_NAME STREQUAL "OS390")
  202. list(APPEND uv_defines PATH_MAX=255)
  203. list(APPEND uv_defines _AE_BIMODAL)
  204. list(APPEND uv_defines _ALL_SOURCE)
  205. list(APPEND uv_defines _ISOC99_SOURCE)
  206. list(APPEND uv_defines _LARGE_TIME_API)
  207. list(APPEND uv_defines _OPEN_MSGQ_EXT)
  208. list(APPEND uv_defines _OPEN_SYS_FILE_EXT)
  209. list(APPEND uv_defines _OPEN_SYS_IF_EXT)
  210. list(APPEND uv_defines _OPEN_SYS_SOCK_EXT3)
  211. list(APPEND uv_defines _OPEN_SYS_SOCK_IPV6)
  212. list(APPEND uv_defines _UNIX03_SOURCE)
  213. list(APPEND uv_defines _UNIX03_THREADS)
  214. list(APPEND uv_defines _UNIX03_WITHDRAWN)
  215. list(APPEND uv_defines _XOPEN_SOURCE_EXTENDED)
  216. list(APPEND uv_sources
  217. src/unix/pthread-fixes.c
  218. src/unix/os390.c
  219. src/unix/os390-syscalls.c)
  220. list(APPEND uv_cflags -Wc,DLL -Wc,exportall -Wc,xplink)
  221. list(APPEND uv_libraries -Wl,xplink)
  222. list(APPEND uv_test_libraries -Wl,xplink)
  223. endif()
  224. if(CMAKE_SYSTEM_NAME STREQUAL "OS400")
  225. list(APPEND uv_defines
  226. _ALL_SOURCE
  227. _LINUX_SOURCE_COMPAT
  228. _THREAD_SAFE
  229. _XOPEN_SOURCE=500)
  230. list(APPEND uv_sources
  231. src/unix/aix-common.c
  232. src/unix/ibmi.c
  233. src/unix/no-fsevents.c
  234. src/unix/no-proctitle.c
  235. src/unix/posix-poll.c)
  236. endif()
  237. if(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
  238. list(APPEND uv_defines __EXTENSIONS__ _XOPEN_SOURCE=500)
  239. list(APPEND uv_libraries kstat nsl sendfile socket)
  240. list(APPEND uv_sources src/unix/no-proctitle.c src/unix/sunos.c)
  241. endif()
  242. if(APPLE OR CMAKE_SYSTEM_NAME MATCHES "DragonFly|FreeBSD|Linux|NetBSD|OpenBSD")
  243. list(APPEND uv_test_libraries util)
  244. endif()
  245. add_library(uv SHARED ${uv_sources})
  246. target_compile_definitions(uv
  247. INTERFACE
  248. USING_UV_SHARED=1
  249. PRIVATE
  250. BUILDING_UV_SHARED=1
  251. ${uv_defines})
  252. target_compile_options(uv PRIVATE ${uv_cflags})
  253. target_include_directories(uv
  254. PUBLIC
  255. $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
  256. $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
  257. PRIVATE
  258. $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>)
  259. target_link_libraries(uv ${uv_libraries})
  260. add_library(uv_a STATIC ${uv_sources})
  261. target_compile_definitions(uv_a PRIVATE ${uv_defines})
  262. target_compile_options(uv_a PRIVATE ${uv_cflags})
  263. target_include_directories(uv_a
  264. PUBLIC
  265. $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
  266. $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
  267. PRIVATE
  268. $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>)
  269. target_link_libraries(uv_a ${uv_libraries})
  270. if(LIBUV_BUILD_TESTS)
  271. # Small hack: use ${uv_test_sources} now to get the runner skeleton,
  272. # before the actual tests are added.
  273. add_executable(
  274. uv_run_benchmarks_a
  275. ${uv_test_sources}
  276. test/benchmark-async-pummel.c
  277. test/benchmark-async.c
  278. test/benchmark-fs-stat.c
  279. test/benchmark-getaddrinfo.c
  280. test/benchmark-loop-count.c
  281. test/benchmark-million-async.c
  282. test/benchmark-million-timers.c
  283. test/benchmark-multi-accept.c
  284. test/benchmark-ping-pongs.c
  285. test/benchmark-ping-udp.c
  286. test/benchmark-pound.c
  287. test/benchmark-pump.c
  288. test/benchmark-sizes.c
  289. test/benchmark-spawn.c
  290. test/benchmark-tcp-write-batch.c
  291. test/benchmark-thread.c
  292. test/benchmark-udp-pummel.c
  293. test/blackhole-server.c
  294. test/dns-server.c
  295. test/echo-server.c
  296. test/run-benchmarks.c
  297. test/runner.c)
  298. target_compile_definitions(uv_run_benchmarks_a PRIVATE ${uv_defines})
  299. target_compile_options(uv_run_benchmarks_a PRIVATE ${uv_cflags})
  300. target_link_libraries(uv_run_benchmarks_a uv_a ${uv_test_libraries})
  301. list(APPEND uv_test_sources
  302. test/blackhole-server.c
  303. test/echo-server.c
  304. test/run-tests.c
  305. test/runner.c
  306. test/test-active.c
  307. test/test-async-null-cb.c
  308. test/test-async.c
  309. test/test-barrier.c
  310. test/test-callback-order.c
  311. test/test-callback-stack.c
  312. test/test-close-fd.c
  313. test/test-close-order.c
  314. test/test-condvar.c
  315. test/test-connect-unspecified.c
  316. test/test-connection-fail.c
  317. test/test-cwd-and-chdir.c
  318. test/test-default-loop-close.c
  319. test/test-delayed-accept.c
  320. test/test-dlerror.c
  321. test/test-eintr-handling.c
  322. test/test-embed.c
  323. test/test-emfile.c
  324. test/test-env-vars.c
  325. test/test-error.c
  326. test/test-fail-always.c
  327. test/test-fork.c
  328. test/test-fs-copyfile.c
  329. test/test-fs-event.c
  330. test/test-fs-poll.c
  331. test/test-fs.c
  332. test/test-fs-readdir.c
  333. test/test-fs-fd-hash.c
  334. test/test-fs-open-flags.c
  335. test/test-get-currentexe.c
  336. test/test-get-loadavg.c
  337. test/test-get-memory.c
  338. test/test-get-passwd.c
  339. test/test-getaddrinfo.c
  340. test/test-gethostname.c
  341. test/test-getnameinfo.c
  342. test/test-getsockname.c
  343. test/test-getters-setters.c
  344. test/test-gettimeofday.c
  345. test/test-handle-fileno.c
  346. test/test-homedir.c
  347. test/test-hrtime.c
  348. test/test-idle.c
  349. test/test-idna.c
  350. test/test-ip4-addr.c
  351. test/test-ip6-addr.c
  352. test/test-ipc-heavy-traffic-deadlock-bug.c
  353. test/test-ipc-send-recv.c
  354. test/test-ipc.c
  355. test/test-loop-alive.c
  356. test/test-loop-close.c
  357. test/test-loop-configure.c
  358. test/test-loop-handles.c
  359. test/test-loop-stop.c
  360. test/test-loop-time.c
  361. test/test-multiple-listen.c
  362. test/test-mutexes.c
  363. test/test-osx-select.c
  364. test/test-pass-always.c
  365. test/test-ping-pong.c
  366. test/test-pipe-bind-error.c
  367. test/test-pipe-close-stdout-read-stdin.c
  368. test/test-pipe-connect-error.c
  369. test/test-pipe-connect-multiple.c
  370. test/test-pipe-connect-prepare.c
  371. test/test-pipe-getsockname.c
  372. test/test-pipe-pending-instances.c
  373. test/test-pipe-sendmsg.c
  374. test/test-pipe-server-close.c
  375. test/test-pipe-set-fchmod.c
  376. test/test-pipe-set-non-blocking.c
  377. test/test-platform-output.c
  378. test/test-poll-close-doesnt-corrupt-stack.c
  379. test/test-poll-close.c
  380. test/test-poll-closesocket.c
  381. test/test-poll-oob.c
  382. test/test-poll.c
  383. test/test-process-priority.c
  384. test/test-process-title-threadsafe.c
  385. test/test-process-title.c
  386. test/test-queue-foreach-delete.c
  387. test/test-random.c
  388. test/test-ref.c
  389. test/test-run-nowait.c
  390. test/test-run-once.c
  391. test/test-semaphore.c
  392. test/test-shutdown-close.c
  393. test/test-shutdown-eof.c
  394. test/test-shutdown-twice.c
  395. test/test-signal-multiple-loops.c
  396. test/test-signal-pending-on-close.c
  397. test/test-signal.c
  398. test/test-socket-buffer-size.c
  399. test/test-spawn.c
  400. test/test-stdio-over-pipes.c
  401. test/test-strscpy.c
  402. test/test-tcp-alloc-cb-fail.c
  403. test/test-tcp-bind-error.c
  404. test/test-tcp-bind6-error.c
  405. test/test-tcp-close-accept.c
  406. test/test-tcp-close-while-connecting.c
  407. test/test-tcp-close.c
  408. test/test-tcp-close-reset.c
  409. test/test-tcp-connect-error-after-write.c
  410. test/test-tcp-connect-error.c
  411. test/test-tcp-connect-timeout.c
  412. test/test-tcp-connect6-error.c
  413. test/test-tcp-create-socket-early.c
  414. test/test-tcp-flags.c
  415. test/test-tcp-oob.c
  416. test/test-tcp-open.c
  417. test/test-tcp-read-stop.c
  418. test/test-tcp-shutdown-after-write.c
  419. test/test-tcp-try-write.c
  420. test/test-tcp-try-write-error.c
  421. test/test-tcp-unexpected-read.c
  422. test/test-tcp-write-after-connect.c
  423. test/test-tcp-write-fail.c
  424. test/test-tcp-write-queue-order.c
  425. test/test-tcp-write-to-half-open-connection.c
  426. test/test-tcp-writealot.c
  427. test/test-thread-equal.c
  428. test/test-thread.c
  429. test/test-threadpool-cancel.c
  430. test/test-threadpool.c
  431. test/test-timer-again.c
  432. test/test-timer-from-check.c
  433. test/test-timer.c
  434. test/test-tmpdir.c
  435. test/test-tty-duplicate-key.c
  436. test/test-tty-escape-sequence-processing.c
  437. test/test-tty.c
  438. test/test-udp-alloc-cb-fail.c
  439. test/test-udp-bind.c
  440. test/test-udp-connect.c
  441. test/test-udp-create-socket-early.c
  442. test/test-udp-dgram-too-big.c
  443. test/test-udp-ipv6.c
  444. test/test-udp-multicast-interface.c
  445. test/test-udp-multicast-interface6.c
  446. test/test-udp-multicast-join.c
  447. test/test-udp-multicast-join6.c
  448. test/test-udp-multicast-ttl.c
  449. test/test-udp-open.c
  450. test/test-udp-options.c
  451. test/test-udp-send-and-recv.c
  452. test/test-udp-send-hang-loop.c
  453. test/test-udp-send-immediate.c
  454. test/test-udp-send-unreachable.c
  455. test/test-udp-try-send.c
  456. test/test-uname.c
  457. test/test-walk-handles.c
  458. test/test-watcher-cross-stop.c)
  459. add_executable(uv_run_tests ${uv_test_sources})
  460. target_compile_definitions(uv_run_tests
  461. PRIVATE ${uv_defines} USING_UV_SHARED=1)
  462. target_compile_options(uv_run_tests PRIVATE ${uv_cflags})
  463. target_link_libraries(uv_run_tests uv ${uv_test_libraries})
  464. add_test(NAME uv_test
  465. COMMAND uv_run_tests
  466. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
  467. if(CMAKE_SYSTEM_NAME STREQUAL "OS390")
  468. set_tests_properties(uv_test PROPERTIES ENVIRONMENT
  469. "LIBPATH=${CMAKE_BINARY_DIR}:$ENV{LIBPATH}")
  470. endif()
  471. add_executable(uv_run_tests_a ${uv_test_sources})
  472. target_compile_definitions(uv_run_tests_a PRIVATE ${uv_defines})
  473. target_compile_options(uv_run_tests_a PRIVATE ${uv_cflags})
  474. target_link_libraries(uv_run_tests_a uv_a ${uv_test_libraries})
  475. add_test(NAME uv_test_a
  476. COMMAND uv_run_tests_a
  477. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
  478. endif()
  479. if(UNIX)
  480. # Now for some gibbering horrors from beyond the stars...
  481. foreach(lib IN LISTS uv_libraries)
  482. list(APPEND LIBS "-l${lib}")
  483. endforeach()
  484. string(REPLACE ";" " " LIBS "${LIBS}")
  485. # Consider setting project version via project() call?
  486. file(STRINGS configure.ac configure_ac REGEX ^AC_INIT)
  487. string(REGEX MATCH "([0-9]+)[.][0-9]+[.][0-9]+" PACKAGE_VERSION "${configure_ac}")
  488. set(UV_VERSION_MAJOR "${CMAKE_MATCH_1}")
  489. # The version in the filename is mirroring the behaviour of autotools.
  490. set_target_properties(uv PROPERTIES
  491. VERSION ${UV_VERSION_MAJOR}.0.0
  492. SOVERSION ${UV_VERSION_MAJOR})
  493. set(includedir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR})
  494. set(libdir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
  495. set(prefix ${CMAKE_INSTALL_PREFIX})
  496. configure_file(libuv.pc.in libuv.pc @ONLY)
  497. install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
  498. install(FILES LICENSE DESTINATION ${CMAKE_INSTALL_DOCDIR})
  499. install(FILES ${PROJECT_BINARY_DIR}/libuv.pc
  500. DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
  501. install(TARGETS uv LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
  502. install(TARGETS uv_a ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
  503. endif()
  504. if(WIN32)
  505. install(DIRECTORY include/ DESTINATION include)
  506. install(FILES LICENSE DESTINATION .)
  507. install(TARGETS uv uv_a
  508. RUNTIME DESTINATION lib/$<CONFIG>
  509. ARCHIVE DESTINATION lib/$<CONFIG>)
  510. endif()