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_OS_IS_GPU)
8 include(GetClangResourceDir)
11 add_subdirectory(llvm-libc-macros)
12 add_subdirectory(llvm-libc-types)
20 macro(add_header_macro TARGET_NAME YAML_FILE DEF_FILE GEN_HDR DEPENDS)
21 if (LIBC_USE_NEW_HEADER_GEN)
24 YAML_FILE ${YAML_FILE}
43 ../libc/newhdrgen/yaml/ctype.yaml
48 .llvm-libc-types.locale_t
53 ../libc/newhdrgen/yaml/dirent.yaml
58 .llvm-libc-types.ino_t
60 .llvm-libc-types.struct_dirent
65 ../libc/newhdrgen/yaml/fcntl.yaml
69 .llvm-libc-macros.fcntl_macros
70 .llvm-libc-types.mode_t
71 .llvm-libc-types.struct_flock
72 .llvm-libc-types.struct_flock64
73 .llvm-libc-types.off64_t
74 .llvm-libc-types.pid_t
75 .llvm-libc-types.off_t
81 ../libc/newhdrgen/yaml/dlfcn.yaml
85 .llvm-libc-macros.dlfcn_macros
91 ../libc/newhdrgen/yaml/features.yaml
96 .llvm-libc-macros.features_macros
101 ../libc/newhdrgen/yaml/fenv.yaml
106 .llvm-libc-macros.fenv_macros
107 .llvm-libc-types.fenv_t
108 .llvm-libc-types.fexcept_t
113 ../libc/newhdrgen/yaml/inttypes.yaml
118 .llvm-libc-types.imaxdiv_t
119 .llvm-libc-macros.inttypes_macros
124 ../libc/newhdrgen/yaml/float.yaml
128 .llvm-libc-macros.float_macros
133 ../libc/newhdrgen/yaml/stdint.yaml
137 .llvm-libc-macros.stdint_macros
142 ../libc/newhdrgen/yaml/limits.yaml
146 .llvm-libc-macros.limits_macros
151 ../libc/newhdrgen/yaml/malloc.yaml
156 .llvm-libc-macros.malloc_macros
161 ../libc/newhdrgen/yaml/math.yaml
166 .llvm-libc-macros.float16_macros
167 .llvm-libc-macros.math_macros
168 .llvm-libc-macros.math_function_macros
169 .llvm-libc-types.double_t
170 .llvm-libc-types.float_t
171 .llvm-libc-types.float128
176 ../libc/newhdrgen/yaml/stdfix.yaml
180 .llvm-libc-macros.stdfix_macros
181 .llvm-libc-types.stdfix-types
184 # TODO: This should be conditional on POSIX networking being included.
185 file(MAKE_DIRECTORY ${LIBC_INCLUDE_DIR}/arpa)
189 ../libc/newhdrgen/yaml/arpa/inet.yaml
198 ../libc/newhdrgen/yaml/assert.yaml
203 .llvm-libc-macros.assert_macros
208 ../libc/newhdrgen/yaml/complex.yaml
213 .llvm-libc-macros.complex_macros
218 ../libc/newhdrgen/yaml/setjmp.yaml
223 .llvm-libc-types.jmp_buf
228 ../libc/newhdrgen/yaml/string.yaml
233 .llvm-libc-macros.null_macro
234 .llvm-libc-types.size_t
239 ../libc/newhdrgen/yaml/strings.yaml
244 .llvm-libc-types.size_t
249 ../libc/newhdrgen/yaml/search.yaml
254 .llvm-libc-types.ACTION
255 .llvm-libc-types.ENTRY
256 .llvm-libc-types.struct_hsearch_data
257 .llvm-libc-types.size_t
258 .llvm-libc-types.__lsearchcompare_t
263 ../libc/newhdrgen/yaml/time.yaml
268 .llvm-libc-macros.time_macros
269 .llvm-libc-types.clock_t
270 .llvm-libc-types.time_t
271 .llvm-libc-types.struct_tm
272 .llvm-libc-types.struct_timespec
273 .llvm-libc-types.struct_timeval
274 .llvm-libc-types.clockid_t
279 ../libc/newhdrgen/yaml/threads.yaml
284 .llvm-libc-types.__call_once_func_t
285 .llvm-libc-types.once_flag
286 .llvm-libc-types.cnd_t
287 .llvm-libc-types.mtx_t
288 .llvm-libc-types.thrd_t
289 .llvm-libc-types.thrd_start_t
290 .llvm-libc-types.tss_t
291 .llvm-libc-types.tss_dtor_t
296 ../libc/newhdrgen/yaml/errno.yaml
300 .llvm-libc-macros.generic_error_number_macros
301 .llvm-libc-macros.error_number_macros
306 ../libc/newhdrgen/yaml/signal.yaml
310 .llvm-libc-macros.signal_macros
311 .llvm-libc-types.sig_atomic_t
312 .llvm-libc-types.sigset_t
313 .llvm-libc-types.struct_sigaction
314 .llvm-libc-types.union_sigval
315 .llvm-libc-types.siginfo_t
316 .llvm-libc-types.stack_t
317 .llvm-libc-types.pid_t
322 ../libc/newhdrgen/yaml/stdbit.yaml
327 .llvm-libc-macros.stdbit_macros
332 ../libc/newhdrgen/yaml/stdckdint.yaml
337 .llvm-libc-macros.stdckdint_macros
342 ../libc/newhdrgen/yaml/stdio.yaml
346 .llvm-libc-macros.file_seek_macros
347 .llvm-libc-macros.stdio_macros
348 .llvm-libc-types.FILE
349 .llvm-libc-types.cookie_io_functions_t
350 .llvm-libc-types.off_t
351 .llvm-libc-types.size_t
352 .llvm-libc-types.ssize_t
358 ../libc/newhdrgen/yaml/stdlib.yaml
363 .llvm-libc-macros.stdlib_macros
364 .llvm-libc-types.div_t
365 .llvm-libc-types.ldiv_t
366 .llvm-libc-types.lldiv_t
367 .llvm-libc-types.size_t
368 .llvm-libc-types.__bsearchcompare_t
369 .llvm-libc-types.__qsortcompare_t
370 .llvm-libc-types.__qsortrcompare_t
371 .llvm-libc-types.__atexithandler_t
372 .llvm-libc-types.locale_t
377 ../libc/newhdrgen/yaml/unistd.yaml
382 .llvm-libc-macros.file_seek_macros
383 .llvm-libc-macros.unistd_macros
384 .llvm-libc-types.__exec_argv_t
385 .llvm-libc-types.__exec_envp_t
386 .llvm-libc-types.off_t
387 .llvm-libc-types.pid_t
388 .llvm-libc-types.size_t
389 .llvm-libc-types.ssize_t
390 .llvm-libc-types.uid_t
391 .llvm-libc-types.__getoptargv_t
396 ../libc/newhdrgen/yaml/pthread.yaml
401 .llvm-libc-types.__atfork_callback_t
402 .llvm-libc-types.__pthread_once_func_t
403 .llvm-libc-types.__pthread_start_t
404 .llvm-libc-types.__pthread_tss_dtor_t
405 .llvm-libc-types.pthread_attr_t
406 .llvm-libc-types.pthread_condattr_t
407 .llvm-libc-types.pthread_key_t
408 .llvm-libc-types.pthread_mutex_t
409 .llvm-libc-types.pthread_mutexattr_t
410 .llvm-libc-types.pthread_once_t
411 .llvm-libc-types.pthread_rwlock_t
412 .llvm-libc-types.pthread_rwlockattr_t
413 .llvm-libc-types.pthread_spinlock_t
414 .llvm-libc-types.pthread_t
419 ../libc/newhdrgen/yaml/sched.yaml
424 .llvm-libc-macros.sched_macros
425 .llvm-libc-types.cpu_set_t
426 .llvm-libc-types.pid_t
427 .llvm-libc-types.size_t
428 .llvm-libc-types.struct_sched_param
429 # Needed according to posix standard
430 .llvm-libc-types.time_t
431 .llvm-libc-types.struct_timespec
436 ../libc/newhdrgen/yaml/spawn.yaml
441 .llvm-libc-types.mode_t
442 .llvm-libc-types.pid_t
443 .llvm-libc-types.posix_spawnattr_t
444 .llvm-libc-types.posix_spawn_file_actions_t
449 ../libc/newhdrgen/yaml/link.yaml
454 .llvm-libc-macros.link_macros
459 ../libc/newhdrgen/yaml/elf.yaml
463 .llvm-libc-macros.elf_macros
466 # TODO: Not all platforms will have a include/sys directory. Add the sys
467 # directory and the targets for sys/*.h files conditional to the OS requiring
469 file(MAKE_DIRECTORY ${LIBC_INCLUDE_DIR}/sys)
473 ../libc/newhdrgen/yaml/sys/auxv.yaml
478 .llvm-libc-macros.sys_auxv_macros
483 ../libc/newhdrgen/yaml/sys/epoll.yaml
488 .llvm-libc-types.struct_epoll_event
489 .llvm-libc-types.struct_epoll_data
490 .llvm-libc-types.sigset_t
491 .llvm-libc-macros.sys_epoll_macros
496 ../libc/newhdrgen/yaml/sys/ioctl.yaml
501 .llvm-libc-macros.sys_ioctl_macros
506 ../libc/newhdrgen/yaml/sys/mman.yaml
511 .llvm-libc-macros.sys_mman_macros
512 .llvm-libc-types.off_t
513 .llvm-libc-types.size_t
514 .llvm-libc-types.ssize_t
519 ../libc/newhdrgen/yaml/sys/prctl.yaml
531 .llvm-libc-macros.sys_queue_macros
536 ../libc/newhdrgen/yaml/sys/random.yaml
541 .llvm-libc-macros.sys_random_macros
542 .llvm-libc-types.size_t
543 .llvm-libc-types.ssize_t
548 ../libc/newhdrgen/yaml/sys/resource.yaml
553 .llvm-libc-macros.sys_resource_macros
554 .llvm-libc-types.rlim_t
555 .llvm-libc-types.struct_rlimit
560 ../libc/newhdrgen/yaml/sys/stat.yaml
565 .llvm-libc-macros.sys_stat_macros
566 .llvm-libc-types.mode_t
567 .llvm-libc-types.dev_t
568 .llvm-libc-types.ino_t
569 .llvm-libc-types.nlink_t
570 .llvm-libc-types.uid_t
571 .llvm-libc-types.gid_t
572 .llvm-libc-types.off_t
573 .llvm-libc-types.struct_timespec
574 .llvm-libc-types.struct_timeval
575 .llvm-libc-types.blksize_t
576 .llvm-libc-types.blkcnt_t
577 .llvm-libc-types.struct_stat
582 ../libc/newhdrgen/yaml/sys/select.yaml
587 .llvm-libc-macros.sys_select_macros
588 .llvm-libc-types.fd_set
589 .llvm-libc-types.sigset_t
590 .llvm-libc-types.suseconds_t
591 .llvm-libc-types.time_t
592 .llvm-libc-types.struct_timespec
593 .llvm-libc-types.struct_timeval
598 ../libc/newhdrgen/yaml/sys/sendfile.yaml
603 .llvm-libc-types.off_t
604 .llvm-libc-types.size_t
605 .llvm-libc-types.ssize_t
610 ../libc/newhdrgen/yaml/sys/socket.yaml
615 .llvm-libc-macros.sys_socket_macros
616 .llvm-libc-types.sa_family_t
617 .llvm-libc-types.socklen_t
618 .llvm-libc-types.struct_iovec
619 .llvm-libc-types.struct_msghdr
620 .llvm-libc-types.struct_sockaddr
621 .llvm-libc-types.struct_sockaddr_un
626 ../libc/newhdrgen/yaml/sys/statvfs.yaml
631 .llvm-libc-types.struct_statvfs
636 ../libc/newhdrgen/yaml/sys/syscall.yaml
644 ../libc/newhdrgen/yaml/sys/time.yaml
649 .llvm-libc-types.struct_timeval
650 .llvm-libc-macros.sys_time_macros
655 ../libc/newhdrgen/yaml/sys/types.yaml
660 .llvm-libc-types.blkcnt_t
661 .llvm-libc-types.blksize_t
662 .llvm-libc-types.clockid_t
663 .llvm-libc-types.dev_t
664 .llvm-libc-types.gid_t
665 .llvm-libc-types.ino_t
666 .llvm-libc-types.mode_t
667 .llvm-libc-types.nlink_t
668 .llvm-libc-types.off_t
669 .llvm-libc-types.pid_t
670 .llvm-libc-types.pthread_attr_t
671 .llvm-libc-types.pthread_key_t
672 .llvm-libc-types.pthread_mutex_t
673 .llvm-libc-types.pthread_mutexattr_t
674 .llvm-libc-types.pthread_once_t
675 .llvm-libc-types.pthread_t
676 .llvm-libc-types.size_t
677 .llvm-libc-types.ssize_t
678 .llvm-libc-types.suseconds_t
679 .llvm-libc-types.time_t
680 .llvm-libc-types.uid_t
685 ../libc/newhdrgen/yaml/sys/utsname.yaml
690 .llvm-libc-types.struct_utsname
695 ../libc/newhdrgen/yaml/sys/wait.yaml
700 .llvm-libc-macros.sys_wait_macros
701 .llvm-libc-types.pid_t
702 .llvm-libc-types.struct_rusage
703 .llvm-libc-types.siginfo_t
708 ../libc/newhdrgen/yaml/termios.yaml
713 .llvm-libc-macros.termios_macros
714 .llvm-libc-types.cc_t
715 .llvm-libc-types.pid_t
716 .llvm-libc-types.speed_t
717 .llvm-libc-types.struct_termios
718 .llvm-libc-types.tcflag_t
723 ../libc/newhdrgen/yaml/uchar.yaml
728 .llvm-libc-types.mbstate_t
729 .llvm-libc-types.char8_t
730 .llvm-libc-types.char16_t
731 .llvm-libc-types.char32_t
736 ../libc/newhdrgen/yaml/wchar.yaml
741 .llvm-libc-macros.wchar_macros
742 .llvm-libc-types.mbstate_t
743 .llvm-libc-types.size_t
744 .llvm-libc-types.wint_t
745 .llvm-libc-types.wchar_t
750 ../libc/newhdrgen/yaml/locale.yaml
755 .llvm-libc-macros.locale_macros
756 .llvm-libc-types.locale_t
757 .llvm-libc-types.struct_lconv
760 if(LIBC_TARGET_OS_IS_GPU)
761 file(MAKE_DIRECTORY ${LIBC_INCLUDE_DIR}/gpu)
765 ../libc/newhdrgen/yaml/gpu/rpc.yaml
770 .llvm-libc-types.rpc_opcodes_t
774 if(NOT LLVM_LIBC_FULL_BUILD)
775 # We don't install headers in non-fullbuild mode.
779 function(get_all_install_header_targets out_var)
780 set(all_deps ${ARGN})
781 foreach(target IN LISTS ARGN)
782 get_target_property(deps ${target} DEPS)
786 list(APPEND all_deps ${deps})
787 get_all_install_header_targets(nested_deps ${deps})
788 list(APPEND all_deps ${nested_deps})
790 list(REMOVE_DUPLICATES all_deps)
791 set(${out_var} ${all_deps} PARENT_SCOPE)
792 endfunction(get_all_install_header_targets)
794 get_all_install_header_targets(all_install_header_targets ${TARGET_PUBLIC_HEADERS})
795 add_library(libc-headers INTERFACE)
796 add_dependencies(libc-headers ${all_install_header_targets})
797 target_include_directories(libc-headers SYSTEM INTERFACE ${LIBC_INCLUDE_DIR})
799 foreach(target IN LISTS all_install_header_targets)
800 get_target_property(header_file ${target} HEADER_FILE_PATH)
802 message(FATAL_ERROR "Installable header file '${target}' does not have the "
803 "HEADER_FILE_PATH property set.")
805 file(RELATIVE_PATH relative_path ${LIBC_INCLUDE_DIR} ${header_file})
806 get_filename_component(nested_dir ${relative_path} DIRECTORY)
807 install(FILES ${header_file}
808 DESTINATION ${LIBC_INSTALL_INCLUDE_DIR}/${nested_dir}
809 COMPONENT libc-headers)
810 # The GPU optionally provides the supported declarations externally so
811 # offloading languages like CUDA and OpenMP know what is supported by libc. We
812 # install these in the compiler's resource directory at a preset location.
813 if(LIBC_TARGET_OS_IS_GPU AND PACKAGE_VERSION)
814 get_target_property(decls_file ${target} DECLS_FILE_PATH)
818 get_clang_resource_dir(resource_dir SUBDIR include)
819 file(RELATIVE_PATH relative_path ${LIBC_INCLUDE_DIR} ${decls_file})
820 get_filename_component(nested_dir ${relative_path} DIRECTORY)
822 ${CMAKE_INSTALL_PREFIX}/${resource_dir}/llvm_libc_wrappers/${nested_dir})
823 install(FILES ${decls_file}
824 DESTINATION ${install_dir}
825 COMPONENT libc-headers)
829 if(LLVM_LIBC_FULL_BUILD)
830 add_custom_target(install-libc-headers
832 COMMAND "${CMAKE_COMMAND}"
833 -DCMAKE_INSTALL_COMPONENT=libc-headers
834 -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
835 # Stripping is a no-op for headers
836 add_custom_target(install-libc-headers-stripped DEPENDS install-libc-headers)