1 set(LIBC_INCLUDE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
2 set(LIBC_INCLUDE_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
4 include(LLVMLibCHeaderRules)
6 # The GPU build wants to install files in the compiler's resource directory.
7 if(LIBC_TARGET_ARCHITECTURE_IS_GPU)
8 include(GetClangResourceDir)
11 add_subdirectory(llvm-libc-macros)
12 add_subdirectory(llvm-libc-types)
34 .llvm-libc-types.ino_t
36 .llvm-libc-types.struct_dirent
45 .llvm-libc-macros.fcntl_macros
46 .llvm-libc-types.mode_t
55 .llvm-libc-macros.fenv_macros
56 .llvm-libc-types.fenv_t
57 .llvm-libc-types.fexcept_t
62 DEF_FILE inttypes.h.def
66 .llvm-libc-types.imaxdiv_t
75 .llvm-libc-macros.math_macros
76 .llvm-libc-types.double_t
77 .llvm-libc-types.float_t
80 # TODO: This should be conditional on POSIX networking being included.
81 file(MAKE_DIRECTORY ${LIBC_INCLUDE_DIR}/arpa)
85 DEF_FILE arpa/inet.h.def
101 DEF_FILE setjmp.h.def
105 .llvm-libc-types.jmp_buf
110 DEF_FILE string.h.def
114 .llvm-libc-macros.null_macro
115 .llvm-libc-types.size_t
120 DEF_FILE strings.h.def
124 .llvm-libc-types.size_t
133 .llvm-libc-macros.time_macros
134 .llvm-libc-types.clock_t
135 .llvm-libc-types.time_t
136 .llvm-libc-types.struct_tm
137 .llvm-libc-types.struct_timespec
138 .llvm-libc-types.struct_timeval
139 .llvm-libc-types.clockid_t
144 DEF_FILE threads.h.def
148 .llvm-libc-types.__call_once_func_t
149 .llvm-libc-types.once_flag
150 .llvm-libc-types.cnd_t
151 .llvm-libc-types.mtx_t
152 .llvm-libc-types.thrd_t
153 .llvm-libc-types.thrd_start_t
154 .llvm-libc-types.tss_t
155 .llvm-libc-types.tss_dtor_t
163 .llvm-libc-macros.generic_error_number_macros
168 DEF_FILE signal.h.def
170 platform_signal=../config/${LIBC_TARGET_OS}/signal.h.in
173 ../config/${LIBC_TARGET_OS}/signal.h.in
175 .llvm-libc-macros.signal_macros
176 .llvm-libc-types.sig_atomic_t
177 .llvm-libc-types.sigset_t
178 .llvm-libc-types.struct_sigaction
179 .llvm-libc-types.union_sigval
180 .llvm-libc-types.siginfo_t
181 .llvm-libc-types.stack_t
182 .llvm-libc-types.pid_t
191 .llvm-libc-macros.file_seek_macros
192 .llvm-libc-macros.stdio_macros
193 .llvm-libc-types.size_t
194 .llvm-libc-types.ssize_t
195 .llvm-libc-types.FILE
196 .llvm-libc-types.cookie_io_functions_t
201 DEF_FILE stdlib.h.def
205 .llvm-libc-macros.stdlib_macros
206 .llvm-libc-types.div_t
207 .llvm-libc-types.ldiv_t
208 .llvm-libc-types.lldiv_t
209 .llvm-libc-types.size_t
210 .llvm-libc-types.__bsearchcompare_t
211 .llvm-libc-types.__qsortcompare_t
212 .llvm-libc-types.__qsortrcompare_t
213 .llvm-libc-types.__atexithandler_t
218 DEF_FILE unistd.h.def
222 .llvm-libc-macros.file_seek_macros
223 .llvm-libc-macros.unistd_macros
224 .llvm-libc-types.__exec_argv_t
225 .llvm-libc-types.__exec_envp_t
226 .llvm-libc-types.off_t
227 .llvm-libc-types.pid_t
228 .llvm-libc-types.size_t
229 .llvm-libc-types.ssize_t
230 .llvm-libc-types.uid_t
231 .llvm-libc-types.__getoptargv_t
236 DEF_FILE pthread.h.def
240 .llvm-libc-types.__atfork_callback_t
241 .llvm-libc-types.__pthread_once_func_t
242 .llvm-libc-types.__pthread_start_t
243 .llvm-libc-types.__pthread_tss_dtor_t
244 .llvm-libc-types.pthread_attr_t
245 .llvm-libc-types.pthread_mutex_t
246 .llvm-libc-types.pthread_mutexattr_t
247 .llvm-libc-types.pthread_t
248 .llvm-libc-types.pthread_key_t
249 .llvm-libc-types.pthread_once_t
258 .llvm-libc-macros.sched_macros
259 .llvm-libc-types.cpu_set_t
260 .llvm-libc-types.pid_t
261 .llvm-libc-types.size_t
262 .llvm-libc-types.struct_sched_param
263 # Needed according to posix standard
264 .llvm-libc-types.time_t
265 .llvm-libc-types.struct_timespec
274 .llvm-libc-types.mode_t
275 .llvm-libc-types.pid_t
276 .llvm-libc-types.posix_spawnattr_t
277 .llvm-libc-types.posix_spawn_file_actions_t
280 # TODO: Not all platforms will have a include/sys directory. Add the sys
281 # directory and the targets for sys/*.h files conditional to the OS requiring
283 file(MAKE_DIRECTORY ${LIBC_INCLUDE_DIR}/sys)
287 DEF_FILE sys/auxv.h.def
291 .llvm-libc-macros.sys_auxv_macros
296 DEF_FILE sys/ioctl.h.def
300 .llvm-libc-macros.sys_ioctl_macros
305 DEF_FILE sys/mman.h.def
309 .llvm-libc-macros.sys_mman_macros
310 .llvm-libc-types.off_t
311 .llvm-libc-types.size_t
312 .llvm-libc-types.ssize_t
317 DEF_FILE sys/prctl.h.def
325 DEF_FILE sys/random.h.def
329 .llvm-libc-macros.sys_random_macros
330 .llvm-libc-types.size_t
331 .llvm-libc-types.ssize_t
336 DEF_FILE sys/resource.h.def
337 GEN_HDR sys/resource.h
340 .llvm-libc-macros.sys_resource_macros
341 .llvm-libc-types.rlim_t
342 .llvm-libc-types.struct_rlimit
347 DEF_FILE sys/stat.h.def
351 .llvm-libc-macros.sys_stat_macros
352 .llvm-libc-types.mode_t
353 .llvm-libc-types.dev_t
354 .llvm-libc-types.ino_t
355 .llvm-libc-types.nlink_t
356 .llvm-libc-types.uid_t
357 .llvm-libc-types.gid_t
358 .llvm-libc-types.off_t
359 .llvm-libc-types.struct_timespec
360 .llvm-libc-types.struct_timeval
361 .llvm-libc-types.blksize_t
362 .llvm-libc-types.blkcnt_t
363 .llvm-libc-types.struct_stat
368 DEF_FILE sys/select.h.def
372 .llvm-libc-macros.sys_select_macros
373 .llvm-libc-types.fd_set
374 .llvm-libc-types.sigset_t
375 .llvm-libc-types.suseconds_t
376 .llvm-libc-types.time_t
377 .llvm-libc-types.struct_timespec
378 .llvm-libc-types.struct_timeval
383 DEF_FILE sys/sendfile.h.def
384 GEN_HDR sys/sendfile.h
387 .llvm-libc-types.off_t
388 .llvm-libc-types.size_t
389 .llvm-libc-types.ssize_t
394 DEF_FILE sys/socket.h.def
398 .llvm-libc-macros.sys_socket_macros
399 .llvm-libc-types.struct_sockaddr
400 .llvm-libc-types.sa_family_t
405 DEF_FILE sys/syscall.h.def
406 GEN_HDR sys/syscall.h
408 syscall_numbers=../config/${LIBC_TARGET_OS}/syscall_numbers.h.inc
410 ../config/${LIBC_TARGET_OS}/syscall_numbers.h.inc
415 DEF_FILE sys/time.h.def
419 .llvm-libc-types.struct_timeval
420 .llvm-libc-macros.sys_time_macros
425 DEF_FILE sys/types.h.def
429 .llvm-libc-types.blkcnt_t
430 .llvm-libc-types.blksize_t
431 .llvm-libc-types.clockid_t
432 .llvm-libc-types.dev_t
433 .llvm-libc-types.gid_t
434 .llvm-libc-types.ino_t
435 .llvm-libc-types.mode_t
436 .llvm-libc-types.nlink_t
437 .llvm-libc-types.off_t
438 .llvm-libc-types.pid_t
439 .llvm-libc-types.pthread_attr_t
440 .llvm-libc-types.pthread_key_t
441 .llvm-libc-types.pthread_mutex_t
442 .llvm-libc-types.pthread_mutexattr_t
443 .llvm-libc-types.pthread_once_t
444 .llvm-libc-types.pthread_t
445 .llvm-libc-types.size_t
446 .llvm-libc-types.ssize_t
447 .llvm-libc-types.suseconds_t
448 .llvm-libc-types.time_t
449 .llvm-libc-types.uid_t
454 DEF_FILE sys/utsname.h.def
455 GEN_HDR sys/utsname.h
458 .llvm-libc-types.struct_utsname
463 DEF_FILE sys/wait.h.def
467 .llvm-libc-macros.sys_wait_macros
468 .llvm-libc-types.pid_t
469 .llvm-libc-types.struct_rusage
470 .llvm-libc-types.siginfo_t
475 DEF_FILE termios.h.def
479 .llvm-libc-macros.termios_macros
480 .llvm-libc-types.cc_t
481 .llvm-libc-types.pid_t
482 .llvm-libc-types.speed_t
483 .llvm-libc-types.struct_termios
484 .llvm-libc-types.tcflag_t
493 .llvm-libc-macros.wchar_macros
494 .llvm-libc-types.size_t
495 .llvm-libc-types.wint_t
496 .llvm-libc-types.wchar_t
499 if(LIBC_TARGET_ARCHITECTURE_IS_GPU)
500 file(MAKE_DIRECTORY ${LIBC_INCLUDE_DIR}/gpu)
504 DEF_FILE gpu/rpc.h.def
508 .llvm-libc-types.rpc_opcodes_t
512 if(NOT LLVM_LIBC_FULL_BUILD)
513 # We don't install headers in non-fullbuild mode.
517 function(get_all_install_header_targets out_var)
518 set(all_deps ${ARGN})
519 foreach(target IN LISTS ARGN)
520 get_target_property(deps ${target} DEPS)
524 list(APPEND all_deps ${deps})
525 get_all_install_header_targets(nested_deps ${deps})
526 list(APPEND all_deps ${nested_deps})
528 list(REMOVE_DUPLICATES all_deps)
529 set(${out_var} ${all_deps} PARENT_SCOPE)
530 endfunction(get_all_install_header_targets)
532 get_all_install_header_targets(all_install_header_targets ${TARGET_PUBLIC_HEADERS})
533 add_library(libc-headers INTERFACE)
534 add_dependencies(libc-headers ${all_install_header_targets})
535 target_include_directories(libc-headers SYSTEM INTERFACE ${LIBC_INCLUDE_DIR})
537 foreach(target IN LISTS all_install_header_targets)
538 get_target_property(header_file ${target} HEADER_FILE_PATH)
540 message(FATAL_ERROR "Installable header file '${target}' does not have the "
541 "HEADER_FILE_PATH property set.")
543 file(RELATIVE_PATH relative_path ${LIBC_INCLUDE_DIR} ${header_file})
544 get_filename_component(nested_dir ${relative_path} DIRECTORY)
545 install(FILES ${header_file}
546 DESTINATION ${LIBC_INSTALL_INCLUDE_DIR}/${nested_dir}
547 COMPONENT libc-headers)
548 # The GPU optionally provides the supported declarations externally so
549 # offloading languages like CUDA and OpenMP know what is supported by libc. We
550 # install these in the compiler's resource directory at a preset location.
551 if(LIBC_TARGET_ARCHITECTURE_IS_GPU AND PACKAGE_VERSION)
552 get_target_property(decls_file ${target} DECLS_FILE_PATH)
556 get_clang_resource_dir(resource_dir SUBDIR include)
557 file(RELATIVE_PATH relative_path ${LIBC_INCLUDE_DIR} ${decls_file})
558 get_filename_component(nested_dir ${relative_path} DIRECTORY)
560 ${CMAKE_INSTALL_PREFIX}/${resource_dir}/llvm_libc_wrappers/${nested_dir})
561 install(FILES ${decls_file}
562 DESTINATION ${install_dir}
563 COMPONENT libc-headers)