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