Imported Upstream version 3.25.0
[platform/upstream/cmake.git] / Utilities / cmlibuv / CMakeLists.txt
1 project(libuv C)
2
3 # Disable warnings to avoid changing 3rd party code.
4 if(CMAKE_C_COMPILER_ID MATCHES
5     "^(GNU|LCC|Clang|AppleClang|IBMClang|XLClang|XL|VisualAge|SunPro|HP|Intel|IntelLLVM|NVHPC)$")
6   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w")
7 elseif(CMAKE_C_COMPILER_ID STREQUAL "PathScale")
8   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -woffall")
9 endif()
10
11 find_package(Threads)
12
13 set(uv_libraries ${CMAKE_THREAD_LIBS_INIT})
14 set(uv_includes include src)
15 set(uv_headers
16   include/uv.h
17   include/uv/errno.h
18   include/uv/threadpool.h
19   include/uv/version.h
20   )
21 set(uv_sources
22   src/fs-poll.c
23   src/heap-inl.h
24   src/idna.c
25   src/idna.h
26   src/inet.c
27   src/queue.h
28   src/strscpy.c
29   src/strscpy.h
30   src/strtok.c
31   src/strtok.h
32   src/threadpool.c
33   src/timer.c
34   src/uv-common.c
35   src/uv-common.h
36   src/uv-data-getter-setters.c
37   src/version.c
38   )
39 if(WIN32)
40   list(APPEND uv_libraries
41     ws2_32
42     psapi
43     iphlpapi
44     shell32
45     userenv
46     )
47   list(APPEND uv_includes
48     src/win
49     )
50   list(APPEND uv_defines
51     WIN32_LEAN_AND_MEAN
52     _WIN32_WINNT=0x0600
53     )
54   list(APPEND uv_headers
55     include/uv/win.h
56     include/tree.h
57     )
58   list(APPEND uv_sources
59     src/win/async.c
60     src/win/atomicops-inl.h
61     src/win/core.c
62     src/win/detect-wakeup.c
63     src/win/dl.c
64     src/win/error.c
65     src/win/fs-event.c
66     src/win/fs.c
67     src/win/getaddrinfo.c
68     src/win/getnameinfo.c
69     src/win/handle.c
70     src/win/handle-inl.h
71     src/win/internal.h
72     src/win/loop-watcher.c
73     src/win/pipe.c
74     src/win/poll.c
75     src/win/process-stdio.c
76     src/win/process.c
77     src/win/req-inl.h
78     src/win/signal.c
79     src/win/snprintf.c
80     src/win/stream.c
81     src/win/stream-inl.h
82     src/win/tcp.c
83     src/win/thread.c
84     src/win/tty.c
85     src/win/udp.c
86     src/win/util.c
87     src/win/winapi.c
88     src/win/winapi.h
89     src/win/winsock.c
90     src/win/winsock.h
91     )
92 else()
93   list(APPEND uv_includes
94     src/unix
95     )
96   list(APPEND uv_headers
97     include/uv/unix.h
98     )
99   list(APPEND uv_sources
100     src/unix/async.c
101     src/unix/atomic-ops.h
102     src/unix/core.c
103     src/unix/dl.c
104     src/unix/fs.c
105     src/unix/getaddrinfo.c
106     src/unix/getnameinfo.c
107     src/unix/internal.h
108     src/unix/loop-watcher.c
109     src/unix/loop.c
110     src/unix/pipe.c
111     src/unix/poll.c
112     src/unix/process.c
113     src/unix/signal.c
114     src/unix/spinlock.h
115     src/unix/stream.c
116     src/unix/tcp.c
117     src/unix/thread.c
118     src/unix/tty.c
119     src/unix/udp.c
120     )
121 endif()
122
123 if(CMAKE_SYSTEM_NAME STREQUAL "AIX")
124   list(APPEND uv_libraries
125     perfstat
126     )
127   list(APPEND uv_headers
128     include/uv/aix.h
129     )
130   list(APPEND uv_defines
131     _ALL_SOURCE
132     _XOPEN_SOURCE=500
133     _LINUX_SOURCE_COMPAT
134     _THREAD_SAFE
135     )
136   list(APPEND uv_sources
137     src/unix/aix.c
138     src/unix/aix-common.c
139     )
140 endif()
141
142 if(CMAKE_SYSTEM_NAME STREQUAL "OS400")
143   list(APPEND uv_headers
144     include/uv/posix.h
145     )
146   list(APPEND uv_defines
147     _ALL_SOURCE
148     _XOPEN_SOURCE=500
149     _LINUX_SOURCE_COMPAT
150     _THREAD_SAFE
151     )
152   list(APPEND uv_sources
153     src/unix/aix-common.c
154     src/unix/ibmi.c
155     src/unix/posix-poll.c
156     src/unix/no-fsevents.c
157     src/unix/no-proctitle.c
158     )
159 endif()
160
161 if(CMAKE_SYSTEM_NAME MATCHES "CYGWIN" OR CMAKE_SYSTEM_NAME MATCHES "MSYS")
162   list(APPEND uv_libraries
163     )
164   list(APPEND uv_headers
165     include/uv/posix.h
166     )
167   list(APPEND uv_defines
168     )
169   list(APPEND uv_sources
170     src/unix/cygwin.c
171     src/unix/bsd-ifaddrs.c
172     src/unix/no-fsevents.c
173     src/unix/no-proctitle.c
174     src/unix/posix-hrtime.c
175     src/unix/posix-poll.c
176     src/unix/procfs-exepath.c
177     src/unix/sysinfo-loadavg.c
178     src/unix/sysinfo-memory.c
179     )
180 endif()
181
182 if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
183   list(APPEND uv_headers
184     include/uv/darwin.h
185     )
186   list(APPEND uv_defines
187     _DARWIN_USE_64_BIT_INODE=1
188     _DARWIN_UNLIMITED_SELECT=1
189     )
190   list(APPEND uv_sources
191     src/unix/bsd-ifaddrs.c
192     src/unix/darwin.c
193     src/unix/darwin-proctitle.c
194     src/unix/fsevents.c
195     src/unix/kqueue.c
196     src/unix/proctitle.c
197     )
198 endif()
199
200 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
201   list(APPEND uv_libraries dl rt)
202   list(APPEND uv_headers
203     include/uv/linux.h
204     )
205   list(APPEND uv_defines _GNU_SOURCE)
206   list(APPEND uv_sources
207     src/unix/epoll.c
208     src/unix/linux-core.c
209     src/unix/linux-inotify.c
210     src/unix/linux-syscalls.c
211     src/unix/linux-syscalls.h
212     src/unix/procfs-exepath.c
213     src/unix/proctitle.c
214     src/unix/sysinfo-loadavg.c
215     src/unix/sysinfo-memory.c
216     )
217 endif()
218
219 if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
220   list(APPEND uv_libraries
221     kvm
222     )
223   list(APPEND uv_headers
224     include/uv/bsd.h
225     )
226   list(APPEND uv_sources
227     src/unix/bsd-ifaddrs.c
228     src/unix/bsd-proctitle.c
229     src/unix/freebsd.c
230     src/unix/kqueue.c
231     src/unix/posix-hrtime.c
232     )
233 endif()
234
235 if(CMAKE_SYSTEM_NAME STREQUAL "kFreeBSD")
236   list(APPEND uv_libraries
237     freebsd-glue
238     kvm
239     )
240   list(APPEND uv_headers
241     include/uv/bsd.h
242     )
243   list(APPEND uv_sources
244     src/unix/bsd-ifaddrs.c
245     src/unix/bsd-proctitle.c
246     src/unix/freebsd.c
247     src/unix/kqueue.c
248     src/unix/posix-hrtime.c
249     )
250 endif()
251
252 if(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
253   list(APPEND uv_libraries
254     kvm
255     )
256   list(APPEND uv_headers
257     include/uv/bsd.h
258     )
259   list(APPEND uv_sources
260     src/unix/bsd-ifaddrs.c
261     src/unix/bsd-proctitle.c
262     src/unix/netbsd.c
263     src/unix/kqueue.c
264     src/unix/posix-hrtime.c
265     )
266 endif()
267
268 if(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
269   list(APPEND uv_libraries
270     kvm
271     )
272   list(APPEND uv_headers
273     include/uv/bsd.h
274     )
275   list(APPEND uv_sources
276     src/unix/bsd-ifaddrs.c
277     src/unix/bsd-proctitle.c
278     src/unix/openbsd.c
279     src/unix/kqueue.c
280     src/unix/posix-hrtime.c
281     )
282 endif()
283
284 if(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
285   list(APPEND uv_libraries
286     kstat
287     nsl
288     sendfile
289     socket
290     rt
291     )
292   list(APPEND uv_headers
293     include/uv/sunos.h
294     )
295   list(APPEND uv_defines
296     __EXTENSIONS__
297     )
298   if(CMAKE_SYSTEM_VERSION STREQUAL "5.10")
299     set(CMAKE_C_STANDARD 90)
300     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)
301       # The running version of CMake does not know how to add this flag.
302       set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c90")
303     endif()
304     list(APPEND uv_defines
305       _XOPEN_SOURCE=500
306       )
307   else()
308     if(NOT CMAKE_C_STANDARD OR CMAKE_C_STANDARD EQUAL 90)
309       set(CMAKE_C_STANDARD 11)
310     endif()
311     if(CMAKE_VERSION VERSION_LESS 3.8.20170505 AND CMAKE_C_COMPILER_ID STREQUAL "SunPro" AND CMAKE_C_COMPILER_VERSION VERSION_LESS 5.14)
312       # The running version of CMake does not know how to add this flag.
313       set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -xc99")
314     endif()
315     list(APPEND uv_defines
316       _XOPEN_SOURCE=600
317       )
318   endif()
319   list(APPEND uv_sources
320     src/unix/no-proctitle.c
321     src/unix/sunos.c
322     )
323 endif()
324
325 if(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
326   list(APPEND uv_libraries
327     rt
328     )
329   list(APPEND uv_headers
330     include/uv/posix.h
331     )
332   list(APPEND uv_defines
333     _XOPEN_SOURCE_EXTENDED
334     )
335   list(APPEND uv_sources
336     src/unix/hpux.c
337     src/unix/no-fsevents.c
338     src/unix/posix-poll.c
339     )
340 endif()
341
342 if(CMAKE_SYSTEM_NAME STREQUAL "QNX")
343   list(APPEND uv_headers
344     include/uv/posix.h
345     )
346   list(APPEND uv_defines
347     _XOPEN_SOURCE=700
348     )
349   list(APPEND uv_sources
350     src/unix/posix-hrtime.c
351     src/unix/posix-poll.c
352     src/unix/no-fsevents.c
353     src/unix/no-proctitle.c
354     )
355   list(APPEND uv_libraries
356     socket
357     )
358 endif()
359
360 include_directories(
361   ${uv_includes}
362   ${KWSYS_HEADER_ROOT}
363   )
364 add_library(cmlibuv STATIC ${uv_sources})
365 target_link_libraries(cmlibuv ${uv_libraries})
366 set_property(TARGET cmlibuv PROPERTY COMPILE_DEFINITIONS ${uv_defines})
367
368 install(FILES LICENSE DESTINATION ${CMAKE_DOC_DIR}/cmlibuv)