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
52 ../libc/newhdrgen/yaml/dirent.yaml
57 .llvm-libc-types.ino_t
59 .llvm-libc-types.struct_dirent
64 ../libc/newhdrgen/yaml/fcntl.yaml
68 .llvm-libc-macros.fcntl_macros
69 .llvm-libc-types.mode_t
70 .llvm-libc-types.struct_flock
71 .llvm-libc-types.struct_flock64
72 .llvm-libc-types.off64_t
73 .llvm-libc-types.pid_t
74 .llvm-libc-types.off_t
80 ../libc/newhdrgen/yaml/dlfcn.yaml
84 .llvm-libc-macros.dlfcn_macros
90 ../libc/newhdrgen/yaml/features.yaml
95 .llvm-libc-macros.features_macros
100 ../libc/newhdrgen/yaml/fenv.yaml
105 .llvm-libc-macros.fenv_macros
106 .llvm-libc-types.fenv_t
107 .llvm-libc-types.fexcept_t
112 ../libc/newhdrgen/yaml/inttypes.yaml
117 .llvm-libc-types.imaxdiv_t
118 .llvm-libc-macros.inttypes_macros
123 ../libc/newhdrgen/yaml/float.yaml
127 .llvm-libc-macros.float_macros
132 ../libc/newhdrgen/yaml/stdint.yaml
136 .llvm-libc-macros.stdint_macros
141 ../libc/newhdrgen/yaml/limits.yaml
145 .llvm-libc-macros.limits_macros
150 ../libc/newhdrgen/yaml/math.yaml
155 .llvm-libc-macros.float16_macros
156 .llvm-libc-macros.math_macros
157 .llvm-libc-macros.math_function_macros
158 .llvm-libc-types.double_t
159 .llvm-libc-types.float_t
160 .llvm-libc-types.float128
165 ../libc/newhdrgen/yaml/stdfix.yaml
169 .llvm-libc-macros.stdfix_macros
172 # TODO: This should be conditional on POSIX networking being included.
173 file(MAKE_DIRECTORY ${LIBC_INCLUDE_DIR}/arpa)
177 ../libc/newhdrgen/yaml/arpa/inet.yaml
186 ../libc/newhdrgen/yaml/assert.yaml
191 .llvm-libc-macros.assert_macros
196 ../libc/newhdrgen/yaml/setjmp.yaml
201 .llvm-libc-types.jmp_buf
206 ../libc/newhdrgen/yaml/string.yaml
211 .llvm-libc-macros.null_macro
212 .llvm-libc-types.size_t
217 ../libc/newhdrgen/yaml/strings.yaml
222 .llvm-libc-types.size_t
227 ../libc/newhdrgen/yaml/search.yaml
232 .llvm-libc-types.ACTION
233 .llvm-libc-types.ENTRY
234 .llvm-libc-types.struct_hsearch_data
235 .llvm-libc-types.size_t
240 ../libc/newhdrgen/yaml/time.yaml
245 .llvm-libc-macros.time_macros
246 .llvm-libc-types.clock_t
247 .llvm-libc-types.time_t
248 .llvm-libc-types.struct_tm
249 .llvm-libc-types.struct_timespec
250 .llvm-libc-types.struct_timeval
251 .llvm-libc-types.clockid_t
256 ../libc/newhdrgen/yaml/threads.yaml
261 .llvm-libc-types.__call_once_func_t
262 .llvm-libc-types.once_flag
263 .llvm-libc-types.cnd_t
264 .llvm-libc-types.mtx_t
265 .llvm-libc-types.thrd_t
266 .llvm-libc-types.thrd_start_t
267 .llvm-libc-types.tss_t
268 .llvm-libc-types.tss_dtor_t
273 ../libc/newhdrgen/yaml/errno.yaml
277 .llvm-libc-macros.generic_error_number_macros
278 .llvm-libc-macros.error_number_macros
283 ../libc/newhdrgen/yaml/signal.yaml
287 .llvm-libc-macros.signal_macros
288 .llvm-libc-types.sig_atomic_t
289 .llvm-libc-types.sigset_t
290 .llvm-libc-types.struct_sigaction
291 .llvm-libc-types.union_sigval
292 .llvm-libc-types.siginfo_t
293 .llvm-libc-types.stack_t
294 .llvm-libc-types.pid_t
299 ../libc/newhdrgen/yaml/stdbit.yaml
304 .llvm-libc-macros.stdbit_macros
309 ../libc/newhdrgen/yaml/stdckdint.yaml
314 .llvm-libc-macros.stdckdint_macros
319 ../libc/newhdrgen/yaml/stdio.yaml
323 .llvm-libc-macros.file_seek_macros
324 .llvm-libc-macros.stdio_macros
325 .llvm-libc-types.FILE
326 .llvm-libc-types.cookie_io_functions_t
327 .llvm-libc-types.off_t
328 .llvm-libc-types.size_t
329 .llvm-libc-types.ssize_t
335 ../libc/newhdrgen/yaml/stdlib.yaml
340 .llvm-libc-macros.stdlib_macros
341 .llvm-libc-types.div_t
342 .llvm-libc-types.ldiv_t
343 .llvm-libc-types.lldiv_t
344 .llvm-libc-types.size_t
345 .llvm-libc-types.__bsearchcompare_t
346 .llvm-libc-types.__qsortcompare_t
347 .llvm-libc-types.__qsortrcompare_t
348 .llvm-libc-types.__atexithandler_t
353 ../libc/newhdrgen/yaml/unistd.yaml
358 .llvm-libc-macros.file_seek_macros
359 .llvm-libc-macros.unistd_macros
360 .llvm-libc-types.__exec_argv_t
361 .llvm-libc-types.__exec_envp_t
362 .llvm-libc-types.off_t
363 .llvm-libc-types.pid_t
364 .llvm-libc-types.size_t
365 .llvm-libc-types.ssize_t
366 .llvm-libc-types.uid_t
367 .llvm-libc-types.__getoptargv_t
372 ../libc/newhdrgen/yaml/pthread.yaml
377 .llvm-libc-types.__atfork_callback_t
378 .llvm-libc-types.__pthread_once_func_t
379 .llvm-libc-types.__pthread_start_t
380 .llvm-libc-types.__pthread_tss_dtor_t
381 .llvm-libc-types.pthread_attr_t
382 .llvm-libc-types.pthread_condattr_t
383 .llvm-libc-types.pthread_key_t
384 .llvm-libc-types.pthread_mutex_t
385 .llvm-libc-types.pthread_mutexattr_t
386 .llvm-libc-types.pthread_once_t
387 .llvm-libc-types.pthread_rwlock_t
388 .llvm-libc-types.pthread_rwlockattr_t
389 .llvm-libc-types.pthread_t
394 ../libc/newhdrgen/yaml/sched.yaml
399 .llvm-libc-macros.sched_macros
400 .llvm-libc-types.cpu_set_t
401 .llvm-libc-types.pid_t
402 .llvm-libc-types.size_t
403 .llvm-libc-types.struct_sched_param
404 # Needed according to posix standard
405 .llvm-libc-types.time_t
406 .llvm-libc-types.struct_timespec
411 ../libc/newhdrgen/yaml/spawn.yaml
416 .llvm-libc-types.mode_t
417 .llvm-libc-types.pid_t
418 .llvm-libc-types.posix_spawnattr_t
419 .llvm-libc-types.posix_spawn_file_actions_t
422 # TODO: Not all platforms will have a include/sys directory. Add the sys
423 # directory and the targets for sys/*.h files conditional to the OS requiring
425 file(MAKE_DIRECTORY ${LIBC_INCLUDE_DIR}/sys)
429 ../libc/newhdrgen/yaml/sys/auxv.yaml
434 .llvm-libc-macros.sys_auxv_macros
439 ../libc/newhdrgen/yaml/sys/epoll.yaml
444 .llvm-libc-types.struct_epoll_event
445 .llvm-libc-types.struct_epoll_data
446 .llvm-libc-types.sigset_t
447 .llvm-libc-macros.sys_epoll_macros
452 ../libc/newhdrgen/yaml/sys/ioctl.yaml
457 .llvm-libc-macros.sys_ioctl_macros
462 ../libc/newhdrgen/yaml/sys/mman.yaml
467 .llvm-libc-macros.sys_mman_macros
468 .llvm-libc-types.off_t
469 .llvm-libc-types.size_t
470 .llvm-libc-types.ssize_t
475 ../libc/newhdrgen/yaml/sys/prctl.yaml
487 .llvm-libc-macros.sys_queue_macros
492 ../libc/newhdrgen/yaml/sys/random.yaml
497 .llvm-libc-macros.sys_random_macros
498 .llvm-libc-types.size_t
499 .llvm-libc-types.ssize_t
504 ../libc/newhdrgen/yaml/sys/resource.yaml
509 .llvm-libc-macros.sys_resource_macros
510 .llvm-libc-types.rlim_t
511 .llvm-libc-types.struct_rlimit
516 ../libc/newhdrgen/yaml/sys/stat.yaml
521 .llvm-libc-macros.sys_stat_macros
522 .llvm-libc-types.mode_t
523 .llvm-libc-types.dev_t
524 .llvm-libc-types.ino_t
525 .llvm-libc-types.nlink_t
526 .llvm-libc-types.uid_t
527 .llvm-libc-types.gid_t
528 .llvm-libc-types.off_t
529 .llvm-libc-types.struct_timespec
530 .llvm-libc-types.struct_timeval
531 .llvm-libc-types.blksize_t
532 .llvm-libc-types.blkcnt_t
533 .llvm-libc-types.struct_stat
538 ../libc/newhdrgen/yaml/sys/select.yaml
543 .llvm-libc-macros.sys_select_macros
544 .llvm-libc-types.fd_set
545 .llvm-libc-types.sigset_t
546 .llvm-libc-types.suseconds_t
547 .llvm-libc-types.time_t
548 .llvm-libc-types.struct_timespec
549 .llvm-libc-types.struct_timeval
554 ../libc/newhdrgen/yaml/sys/sendfile.yaml
559 .llvm-libc-types.off_t
560 .llvm-libc-types.size_t
561 .llvm-libc-types.ssize_t
566 ../libc/newhdrgen/yaml/sys/socket.yaml
571 .llvm-libc-macros.sys_socket_macros
572 .llvm-libc-types.sa_family_t
573 .llvm-libc-types.socklen_t
574 .llvm-libc-types.struct_sockaddr
575 .llvm-libc-types.struct_sockaddr_un
580 ../libc/newhdrgen/yaml/sys/statvfs.yaml
585 .llvm-libc-types.struct_statvfs
590 ../libc/newhdrgen/yaml/sys/syscall.yaml
598 ../libc/newhdrgen/yaml/sys/time.yaml
603 .llvm-libc-types.struct_timeval
604 .llvm-libc-macros.sys_time_macros
609 ../libc/newhdrgen/yaml/sys/types.yaml
614 .llvm-libc-types.blkcnt_t
615 .llvm-libc-types.blksize_t
616 .llvm-libc-types.clockid_t
617 .llvm-libc-types.dev_t
618 .llvm-libc-types.gid_t
619 .llvm-libc-types.ino_t
620 .llvm-libc-types.mode_t
621 .llvm-libc-types.nlink_t
622 .llvm-libc-types.off_t
623 .llvm-libc-types.pid_t
624 .llvm-libc-types.pthread_attr_t
625 .llvm-libc-types.pthread_key_t
626 .llvm-libc-types.pthread_mutex_t
627 .llvm-libc-types.pthread_mutexattr_t
628 .llvm-libc-types.pthread_once_t
629 .llvm-libc-types.pthread_t
630 .llvm-libc-types.size_t
631 .llvm-libc-types.ssize_t
632 .llvm-libc-types.suseconds_t
633 .llvm-libc-types.time_t
634 .llvm-libc-types.uid_t
639 ../libc/newhdrgen/yaml/sys/utsname.yaml
644 .llvm-libc-types.struct_utsname
649 ../libc/newhdrgen/yaml/sys/wait.yaml
654 .llvm-libc-macros.sys_wait_macros
655 .llvm-libc-types.pid_t
656 .llvm-libc-types.struct_rusage
657 .llvm-libc-types.siginfo_t
662 ../libc/newhdrgen/yaml/termios.yaml
667 .llvm-libc-macros.termios_macros
668 .llvm-libc-types.cc_t
669 .llvm-libc-types.pid_t
670 .llvm-libc-types.speed_t
671 .llvm-libc-types.struct_termios
672 .llvm-libc-types.tcflag_t
677 ../libc/newhdrgen/yaml/uchar.yaml
682 .llvm-libc-types.mbstate_t
683 .llvm-libc-types.char8_t
684 .llvm-libc-types.char16_t
685 .llvm-libc-types.char32_t
690 ../libc/newhdrgen/yaml/wchar.yaml
695 .llvm-libc-macros.wchar_macros
696 .llvm-libc-types.mbstate_t
697 .llvm-libc-types.size_t
698 .llvm-libc-types.wint_t
699 .llvm-libc-types.wchar_t
702 if(LIBC_TARGET_OS_IS_GPU)
703 file(MAKE_DIRECTORY ${LIBC_INCLUDE_DIR}/gpu)
707 ../libc/newhdrgen/yaml/gpu/rpc.yaml
712 .llvm-libc-types.rpc_opcodes_t
716 if(NOT LLVM_LIBC_FULL_BUILD)
717 # We don't install headers in non-fullbuild mode.
721 function(get_all_install_header_targets out_var)
722 set(all_deps ${ARGN})
723 foreach(target IN LISTS ARGN)
724 get_target_property(deps ${target} DEPS)
728 list(APPEND all_deps ${deps})
729 get_all_install_header_targets(nested_deps ${deps})
730 list(APPEND all_deps ${nested_deps})
732 list(REMOVE_DUPLICATES all_deps)
733 set(${out_var} ${all_deps} PARENT_SCOPE)
734 endfunction(get_all_install_header_targets)
736 get_all_install_header_targets(all_install_header_targets ${TARGET_PUBLIC_HEADERS})
737 add_library(libc-headers INTERFACE)
738 add_dependencies(libc-headers ${all_install_header_targets})
739 target_include_directories(libc-headers SYSTEM INTERFACE ${LIBC_INCLUDE_DIR})
741 foreach(target IN LISTS all_install_header_targets)
742 get_target_property(header_file ${target} HEADER_FILE_PATH)
744 message(FATAL_ERROR "Installable header file '${target}' does not have the "
745 "HEADER_FILE_PATH property set.")
747 file(RELATIVE_PATH relative_path ${LIBC_INCLUDE_DIR} ${header_file})
748 get_filename_component(nested_dir ${relative_path} DIRECTORY)
749 install(FILES ${header_file}
750 DESTINATION ${LIBC_INSTALL_INCLUDE_DIR}/${nested_dir}
751 COMPONENT libc-headers)
752 # The GPU optionally provides the supported declarations externally so
753 # offloading languages like CUDA and OpenMP know what is supported by libc. We
754 # install these in the compiler's resource directory at a preset location.
755 if(LIBC_TARGET_OS_IS_GPU AND PACKAGE_VERSION)
756 get_target_property(decls_file ${target} DECLS_FILE_PATH)
760 get_clang_resource_dir(resource_dir SUBDIR include)
761 file(RELATIVE_PATH relative_path ${LIBC_INCLUDE_DIR} ${decls_file})
762 get_filename_component(nested_dir ${relative_path} DIRECTORY)
764 ${CMAKE_INSTALL_PREFIX}/${resource_dir}/llvm_libc_wrappers/${nested_dir})
765 install(FILES ${decls_file}
766 DESTINATION ${install_dir}
767 COMPONENT libc-headers)
771 if(LLVM_LIBC_FULL_BUILD)
772 add_custom_target(install-libc-headers
774 COMMAND "${CMAKE_COMMAND}"
775 -DCMAKE_INSTALL_COMPONENT=libc-headers
776 -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
777 # Stripping is a no-op for headers
778 add_custom_target(install-libc-headers-stripped DEPENDS install-libc-headers)