xref: /aosp_15_r20/external/sandboxed-api/oss-internship-2020/libuv/CMakeLists.txt (revision ec63e07ab9515d95e79c211197c445ef84cefa6a)
1# Copyright 2020 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15cmake_minimum_required(VERSION 3.12)
16
17project(libuv_sandbox)
18
19set(CMAKE_CXX_STANDARD 17)
20set(CMAKE_CXX_STANDARD_REQUIRED True)
21
22# Add SAPI directories
23add_subdirectory(
24  "${SAPI_ROOT}"
25  "${CMAKE_BINARY_DIR}/sandboxed-api-build"
26  EXCLUDE_FROM_ALL
27)
28
29file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/uv_wrapper")
30add_custom_command(
31
32  OUTPUT "${CMAKE_BINARY_DIR}/uv_wrapper/uv_wrapper.h"
33         "${CMAKE_BINARY_DIR}/uv_wrapper/uv_wrapper.cc"
34
35  WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
36
37  COMMAND "${SAPI_PYTHON3_EXECUTABLE}"
38          "generator/wrapper_generator.py"
39          "libuv/include/uv.h"
40          "${CMAKE_BINARY_DIR}/uv_wrapper/uv_wrapper.h"
41          "${CMAKE_BINARY_DIR}/uv_wrapper/uv_wrapper.cc"
42
43  COMMENT "Generate the wrapper header and source files"
44)
45
46option(SAPI_UV_ENABLE_EXAMPLES "" ON)
47option(SAPI_UV_ENABLE_TESTS "" ON)
48
49# Add callbacks used by examples and tests
50if (SAPI_UV_ENABLE_EXAMPLES OR SAPI_UV_ENABLE_TESTS)
51  list(APPEND SAPI_UV_CALLBACKS
52    "${CMAKE_CURRENT_SOURCE_DIR}/callbacks/callbacks.h"
53    "${CMAKE_CURRENT_SOURCE_DIR}/callbacks/callbacks.cc"
54  )
55endif()
56
57# Wrapper library including wrappers for all libuv methods and callbacks
58# The SAPI_UV_CALLBACKS variable should contain the absolute paths of
59# all the files implementing the callbacks
60add_library(uv_wrapper_and_callbacks OBJECT
61  "${CMAKE_BINARY_DIR}/uv_wrapper/uv_wrapper.h"
62  "${CMAKE_BINARY_DIR}/uv_wrapper/uv_wrapper.cc"
63  "${SAPI_UV_CALLBACKS}"
64)
65set_target_properties(uv_wrapper_and_callbacks
66  PROPERTIES LINKER_LANGUAGE C
67)
68
69# Link the wrapper to the original uv library
70add_subdirectory(libuv)
71target_link_libraries(uv_wrapper_and_callbacks uv_a)
72
73# Setup Sandboxed API
74set(SAPI_ROOT "" CACHE PATH "Path to the Sandboxed API source tree")
75set(SAPI_BUILD_EXAMPLES ${SAPI_UV_ENABLE_EXAMPLES} CACHE BOOL "" FORCE)
76set(SAPI_BUILD_TESTING ${SAPI_UV_ENABLE_TESTS} CACHE BOOL "" FORCE)
77
78# Generate SAPI header
79add_sapi_library(uv_sapi
80
81  # List of all the generated methods
82  FUNCTIONS sapi_uv_accept
83            sapi_uv_async_init
84            sapi_uv_async_send
85            sapi_uv_backend_fd
86            sapi_uv_backend_timeout
87            sapi_uv_barrier_destroy
88            sapi_uv_barrier_init
89            sapi_uv_barrier_wait
90            # TODO(cblichmann): sapi_uv_buf_init
91            sapi_uv_cancel
92            sapi_uv_chdir
93            sapi_uv_check_init
94            sapi_uv_check_start
95            sapi_uv_check_stop
96            sapi_uv_close
97            sapi_uv_cond_broadcast
98            sapi_uv_cond_destroy
99            sapi_uv_cond_init
100            sapi_uv_cond_signal
101            sapi_uv_cond_timedwait
102            sapi_uv_cond_wait
103            sapi_uv_cpu_info
104            sapi_uv_cwd
105            sapi_uv_default_loop
106            sapi_uv_disable_stdio_inheritance
107            sapi_uv_dlclose
108            sapi_uv_dlerror
109            sapi_uv_dlopen
110            sapi_uv_dlsym
111            sapi_uv_err_name
112            sapi_uv_err_name_r
113            sapi_uv_exepath
114            sapi_uv_fileno
115            sapi_uv_free_cpu_info
116            sapi_uv_free_interface_addresses
117            sapi_uv_freeaddrinfo
118            sapi_uv_fs_access
119            sapi_uv_fs_chmod
120            sapi_uv_fs_chown
121            sapi_uv_fs_close
122            sapi_uv_fs_closedir
123            sapi_uv_fs_copyfile
124            sapi_uv_fs_event_getpath
125            sapi_uv_fs_event_init
126            sapi_uv_fs_event_start
127            sapi_uv_fs_event_stop
128            sapi_uv_fs_fchmod
129            sapi_uv_fs_fchown
130            sapi_uv_fs_fdatasync
131            sapi_uv_fs_fstat
132            sapi_uv_fs_fsync
133            sapi_uv_fs_ftruncate
134            sapi_uv_fs_futime
135            sapi_uv_fs_get_path
136            sapi_uv_fs_get_ptr
137            sapi_uv_fs_get_result
138            sapi_uv_fs_get_statbuf
139            sapi_uv_fs_get_system_error
140            sapi_uv_fs_get_type
141            sapi_uv_fs_lchown
142            sapi_uv_fs_link
143            sapi_uv_fs_lstat
144            sapi_uv_fs_lutime
145            sapi_uv_fs_mkdir
146            sapi_uv_fs_mkdtemp
147            sapi_uv_fs_mkstemp
148            sapi_uv_fs_open
149            sapi_uv_fs_opendir
150            sapi_uv_fs_poll_getpath
151            sapi_uv_fs_poll_init
152            sapi_uv_fs_poll_start
153            sapi_uv_fs_poll_stop
154            sapi_uv_fs_read
155            sapi_uv_fs_readdir
156            sapi_uv_fs_readlink
157            sapi_uv_fs_realpath
158            sapi_uv_fs_rename
159            sapi_uv_fs_req_cleanup
160            sapi_uv_fs_rmdir
161            sapi_uv_fs_scandir
162            sapi_uv_fs_scandir_next
163            sapi_uv_fs_sendfile
164            sapi_uv_fs_stat
165            sapi_uv_fs_statfs
166            sapi_uv_fs_symlink
167            sapi_uv_fs_unlink
168            sapi_uv_fs_utime
169            sapi_uv_fs_write
170            sapi_uv_get_constrained_memory
171            sapi_uv_get_free_memory
172            sapi_uv_get_osfhandle
173            sapi_uv_get_process_title
174            sapi_uv_get_total_memory
175            sapi_uv_getaddrinfo
176            sapi_uv_getnameinfo
177            sapi_uv_getrusage
178            sapi_uv_gettimeofday
179            sapi_uv_guess_handle
180            sapi_uv_handle_get_data
181            sapi_uv_handle_get_loop
182            sapi_uv_handle_get_type
183            sapi_uv_handle_set_data
184            sapi_uv_handle_size
185            sapi_uv_handle_type_name
186            sapi_uv_has_ref
187            sapi_uv_hrtime
188            sapi_uv_idle_init
189            sapi_uv_idle_start
190            sapi_uv_idle_stop
191            sapi_uv_if_indextoiid
192            sapi_uv_if_indextoname
193            sapi_uv_inet_ntop
194            sapi_uv_inet_pton
195            sapi_uv_interface_addresses
196            sapi_uv_ip4_addr
197            sapi_uv_ip4_name
198            sapi_uv_ip6_addr
199            sapi_uv_ip6_name
200            sapi_uv_is_active
201            sapi_uv_is_closing
202            sapi_uv_is_readable
203            sapi_uv_is_writable
204            sapi_uv_key_create
205            sapi_uv_key_delete
206            sapi_uv_key_get
207            sapi_uv_key_set
208            sapi_uv_kill
209            sapi_uv_library_shutdown
210            sapi_uv_listen
211            sapi_uv_loadavg
212            sapi_uv_loop_alive
213            sapi_uv_loop_close
214            sapi_uv_loop_configure
215            sapi_uv_loop_configure_int
216            sapi_uv_loop_delete
217            sapi_uv_loop_fork
218            sapi_uv_loop_get_data
219            sapi_uv_loop_init
220            sapi_uv_loop_new
221            sapi_uv_loop_set_data
222            sapi_uv_loop_size
223            sapi_uv_metrics_idle_time
224            sapi_uv_mutex_destroy
225            sapi_uv_mutex_init
226            sapi_uv_mutex_init_recursive
227            sapi_uv_mutex_lock
228            sapi_uv_mutex_trylock
229            sapi_uv_mutex_unlock
230            sapi_uv_now
231            sapi_uv_once
232            sapi_uv_open_osfhandle
233            sapi_uv_os_environ
234            sapi_uv_os_free_environ
235            sapi_uv_os_free_passwd
236            sapi_uv_os_get_passwd
237            sapi_uv_os_getenv
238            sapi_uv_os_gethostname
239            sapi_uv_os_getpid
240            sapi_uv_os_getppid
241            sapi_uv_os_getpriority
242            sapi_uv_os_homedir
243            sapi_uv_os_setenv
244            sapi_uv_os_setpriority
245            sapi_uv_os_tmpdir
246            sapi_uv_os_uname
247            sapi_uv_os_unsetenv
248            sapi_uv_pipe_bind
249            sapi_uv_pipe_chmod
250            sapi_uv_pipe_connect
251            sapi_uv_pipe_getpeername
252            sapi_uv_pipe_getsockname
253            sapi_uv_pipe_init
254            sapi_uv_pipe_open
255            sapi_uv_pipe_pending_count
256            sapi_uv_pipe_pending_instances
257            sapi_uv_pipe_pending_type
258            sapi_uv_poll_init
259            sapi_uv_poll_init_socket
260            sapi_uv_poll_start
261            sapi_uv_poll_stop
262            sapi_uv_prepare_init
263            sapi_uv_prepare_start
264            sapi_uv_prepare_stop
265            sapi_uv_print_active_handles
266            sapi_uv_print_all_handles
267            sapi_uv_process_get_pid
268            sapi_uv_process_kill
269            sapi_uv_queue_work
270            sapi_uv_random
271            sapi_uv_read_start
272            sapi_uv_read_stop
273            sapi_uv_recv_buffer_size
274            sapi_uv_ref
275            sapi_uv_replace_allocator
276            sapi_uv_req_get_data
277            sapi_uv_req_get_type
278            sapi_uv_req_set_data
279            sapi_uv_req_size
280            sapi_uv_req_type_name
281            sapi_uv_resident_set_memory
282            sapi_uv_run
283            sapi_uv_rwlock_destroy
284            sapi_uv_rwlock_init
285            sapi_uv_rwlock_rdlock
286            sapi_uv_rwlock_rdunlock
287            sapi_uv_rwlock_tryrdlock
288            sapi_uv_rwlock_trywrlock
289            sapi_uv_rwlock_wrlock
290            sapi_uv_rwlock_wrunlock
291            sapi_uv_sem_destroy
292            sapi_uv_sem_init
293            sapi_uv_sem_post
294            sapi_uv_sem_trywait
295            sapi_uv_sem_wait
296            sapi_uv_send_buffer_size
297            sapi_uv_set_process_title
298            sapi_uv_setup_args
299            sapi_uv_shutdown
300            sapi_uv_signal_init
301            sapi_uv_signal_start
302            sapi_uv_signal_start_oneshot
303            sapi_uv_signal_stop
304            sapi_uv_sleep
305            sapi_uv_spawn
306            sapi_uv_stop
307            sapi_uv_stream_get_write_queue_size
308            sapi_uv_stream_set_blocking
309            sapi_uv_strerror
310            sapi_uv_strerror_r
311            sapi_uv_tcp_bind
312            sapi_uv_tcp_close_reset
313            sapi_uv_tcp_connect
314            sapi_uv_tcp_getpeername
315            sapi_uv_tcp_getsockname
316            sapi_uv_tcp_init
317            sapi_uv_tcp_init_ex
318            sapi_uv_tcp_keepalive
319            sapi_uv_tcp_nodelay
320            sapi_uv_tcp_open
321            sapi_uv_tcp_simultaneous_accepts
322            sapi_uv_thread_create
323            sapi_uv_thread_create_ex
324            sapi_uv_thread_equal
325            sapi_uv_thread_join
326            sapi_uv_thread_self
327            sapi_uv_timer_again
328            sapi_uv_timer_get_due_in
329            sapi_uv_timer_get_repeat
330            sapi_uv_timer_init
331            sapi_uv_timer_set_repeat
332            sapi_uv_timer_start
333            sapi_uv_timer_stop
334            sapi_uv_translate_sys_error
335            sapi_uv_try_write
336            sapi_uv_tty_get_vterm_state
337            sapi_uv_tty_get_winsize
338            sapi_uv_tty_init
339            sapi_uv_tty_reset_mode
340            sapi_uv_tty_set_mode
341            sapi_uv_tty_set_vterm_state
342            sapi_uv_udp_bind
343            sapi_uv_udp_connect
344            sapi_uv_udp_get_send_queue_count
345            sapi_uv_udp_get_send_queue_size
346            sapi_uv_udp_getpeername
347            sapi_uv_udp_getsockname
348            sapi_uv_udp_init
349            sapi_uv_udp_init_ex
350            sapi_uv_udp_open
351            sapi_uv_udp_recv_start
352            sapi_uv_udp_recv_stop
353            sapi_uv_udp_send
354            sapi_uv_udp_set_broadcast
355            sapi_uv_udp_set_membership
356            sapi_uv_udp_set_multicast_interface
357            sapi_uv_udp_set_multicast_loop
358            sapi_uv_udp_set_multicast_ttl
359            sapi_uv_udp_set_source_membership
360            sapi_uv_udp_set_ttl
361            sapi_uv_udp_try_send
362            sapi_uv_udp_using_recvmmsg
363            sapi_uv_unref
364            sapi_uv_update_time
365            sapi_uv_uptime
366            sapi_uv_version
367            sapi_uv_version_string
368            sapi_uv_walk
369            sapi_uv_write
370            sapi_uv_write2
371
372  INPUTS "${CMAKE_BINARY_DIR}/uv_wrapper/uv_wrapper.h"
373
374  LIBRARY uv_wrapper_and_callbacks
375
376  LIBRARY_NAME UV
377
378  NAMESPACE uv
379)
380
381# Include generated SAPI header
382target_include_directories(uv_sapi INTERFACE
383  "${PROJECT_BINARY_DIR}"
384)
385
386# Add examples
387if (SAPI_UV_ENABLE_EXAMPLES)
388  add_subdirectory(examples)
389endif()
390
391# Add tests
392if (SAPI_UV_ENABLE_TESTS)
393  add_subdirectory(tests)
394endif()
395