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
51 DEF_FILE features.h.def
55 .llvm-libc-macros.features_macros
64 .llvm-libc-macros.fenv_macros
65 .llvm-libc-types.fenv_t
66 .llvm-libc-types.fexcept_t
71 DEF_FILE inttypes.h.def
75 .llvm-libc-types.imaxdiv_t
84 .llvm-libc-macros.math_macros
85 .llvm-libc-types.double_t
86 .llvm-libc-types.float_t
89 # TODO: This should be conditional on POSIX networking being included.
90 file(MAKE_DIRECTORY ${LIBC_INCLUDE_DIR}/arpa)
94 DEF_FILE arpa/inet.h.def
102 DEF_FILE assert.h.def
110 DEF_FILE setjmp.h.def
114 .llvm-libc-types.jmp_buf
119 DEF_FILE string.h.def
123 .llvm-libc-macros.null_macro
124 .llvm-libc-types.size_t
129 DEF_FILE strings.h.def
133 .llvm-libc-types.size_t
142 .llvm-libc-macros.time_macros
143 .llvm-libc-types.clock_t
144 .llvm-libc-types.time_t
145 .llvm-libc-types.struct_tm
146 .llvm-libc-types.struct_timespec
147 .llvm-libc-types.struct_timeval
148 .llvm-libc-types.clockid_t
153 DEF_FILE threads.h.def
157 .llvm-libc-types.__call_once_func_t
158 .llvm-libc-types.once_flag
159 .llvm-libc-types.cnd_t
160 .llvm-libc-types.mtx_t
161 .llvm-libc-types.thrd_t
162 .llvm-libc-types.thrd_start_t
163 .llvm-libc-types.tss_t
164 .llvm-libc-types.tss_dtor_t
172 .llvm-libc-macros.generic_error_number_macros
177 DEF_FILE signal.h.def
179 platform_signal=../config/${LIBC_TARGET_OS}/signal.h.in
182 ../config/${LIBC_TARGET_OS}/signal.h.in
184 .llvm-libc-macros.signal_macros
185 .llvm-libc-types.sig_atomic_t
186 .llvm-libc-types.sigset_t
187 .llvm-libc-types.struct_sigaction
188 .llvm-libc-types.union_sigval
189 .llvm-libc-types.siginfo_t
190 .llvm-libc-types.stack_t
191 .llvm-libc-types.pid_t
200 .llvm-libc-macros.file_seek_macros
201 .llvm-libc-macros.stdio_macros
202 .llvm-libc-types.size_t
203 .llvm-libc-types.ssize_t
204 .llvm-libc-types.FILE
205 .llvm-libc-types.cookie_io_functions_t
210 DEF_FILE stdlib.h.def
214 .llvm-libc-macros.stdlib_macros
215 .llvm-libc-types.div_t
216 .llvm-libc-types.ldiv_t
217 .llvm-libc-types.lldiv_t
218 .llvm-libc-types.size_t
219 .llvm-libc-types.__bsearchcompare_t
220 .llvm-libc-types.__qsortcompare_t
221 .llvm-libc-types.__qsortrcompare_t
222 .llvm-libc-types.__atexithandler_t
227 DEF_FILE unistd.h.def
231 .llvm-libc-macros.file_seek_macros
232 .llvm-libc-macros.unistd_macros
233 .llvm-libc-types.__exec_argv_t
234 .llvm-libc-types.__exec_envp_t
235 .llvm-libc-types.off_t
236 .llvm-libc-types.pid_t
237 .llvm-libc-types.size_t
238 .llvm-libc-types.ssize_t
239 .llvm-libc-types.uid_t
240 .llvm-libc-types.__getoptargv_t
245 DEF_FILE pthread.h.def
249 .llvm-libc-types.__atfork_callback_t
250 .llvm-libc-types.__pthread_once_func_t
251 .llvm-libc-types.__pthread_start_t
252 .llvm-libc-types.__pthread_tss_dtor_t
253 .llvm-libc-types.pthread_attr_t
254 .llvm-libc-types.pthread_mutex_t
255 .llvm-libc-types.pthread_mutexattr_t
256 .llvm-libc-types.pthread_t
257 .llvm-libc-types.pthread_key_t
258 .llvm-libc-types.pthread_once_t
267 .llvm-libc-macros.sched_macros
268 .llvm-libc-types.cpu_set_t
269 .llvm-libc-types.pid_t
270 .llvm-libc-types.size_t
271 .llvm-libc-types.struct_sched_param
272 # Needed according to posix standard
273 .llvm-libc-types.time_t
274 .llvm-libc-types.struct_timespec
283 .llvm-libc-types.mode_t
284 .llvm-libc-types.pid_t
285 .llvm-libc-types.posix_spawnattr_t
286 .llvm-libc-types.posix_spawn_file_actions_t
289 # TODO: Not all platforms will have a include/sys directory. Add the sys
290 # directory and the targets for sys/*.h files conditional to the OS requiring
292 file(MAKE_DIRECTORY ${LIBC_INCLUDE_DIR}/sys)
296 DEF_FILE sys/auxv.h.def
300 .llvm-libc-macros.sys_auxv_macros
305 DEF_FILE sys/ioctl.h.def
309 .llvm-libc-macros.sys_ioctl_macros
314 DEF_FILE sys/mman.h.def
318 .llvm-libc-macros.sys_mman_macros
319 .llvm-libc-types.off_t
320 .llvm-libc-types.size_t
321 .llvm-libc-types.ssize_t
326 DEF_FILE sys/prctl.h.def
334 DEF_FILE sys/random.h.def
338 .llvm-libc-macros.sys_random_macros
339 .llvm-libc-types.size_t
340 .llvm-libc-types.ssize_t
345 DEF_FILE sys/resource.h.def
346 GEN_HDR sys/resource.h
349 .llvm-libc-macros.sys_resource_macros
350 .llvm-libc-types.rlim_t
351 .llvm-libc-types.struct_rlimit
356 DEF_FILE sys/stat.h.def
360 .llvm-libc-macros.sys_stat_macros
361 .llvm-libc-types.mode_t
362 .llvm-libc-types.dev_t
363 .llvm-libc-types.ino_t
364 .llvm-libc-types.nlink_t
365 .llvm-libc-types.uid_t
366 .llvm-libc-types.gid_t
367 .llvm-libc-types.off_t
368 .llvm-libc-types.struct_timespec
369 .llvm-libc-types.struct_timeval
370 .llvm-libc-types.blksize_t
371 .llvm-libc-types.blkcnt_t
372 .llvm-libc-types.struct_stat
377 DEF_FILE sys/select.h.def
381 .llvm-libc-macros.sys_select_macros
382 .llvm-libc-types.fd_set
383 .llvm-libc-types.sigset_t
384 .llvm-libc-types.suseconds_t
385 .llvm-libc-types.time_t
386 .llvm-libc-types.struct_timespec
387 .llvm-libc-types.struct_timeval
392 DEF_FILE sys/sendfile.h.def
393 GEN_HDR sys/sendfile.h
396 .llvm-libc-types.off_t
397 .llvm-libc-types.size_t
398 .llvm-libc-types.ssize_t
403 DEF_FILE sys/socket.h.def
407 .llvm-libc-macros.sys_socket_macros
408 .llvm-libc-types.struct_sockaddr
409 .llvm-libc-types.sa_family_t
414 DEF_FILE sys/syscall.h.def
415 GEN_HDR sys/syscall.h
417 syscall_numbers=../config/${LIBC_TARGET_OS}/syscall_numbers.h.inc
419 ../config/${LIBC_TARGET_OS}/syscall_numbers.h.inc
424 DEF_FILE sys/time.h.def
428 .llvm-libc-types.struct_timeval
429 .llvm-libc-macros.sys_time_macros
434 DEF_FILE sys/types.h.def
438 .llvm-libc-types.blkcnt_t
439 .llvm-libc-types.blksize_t
440 .llvm-libc-types.clockid_t
441 .llvm-libc-types.dev_t
442 .llvm-libc-types.gid_t
443 .llvm-libc-types.ino_t
444 .llvm-libc-types.mode_t
445 .llvm-libc-types.nlink_t
446 .llvm-libc-types.off_t
447 .llvm-libc-types.pid_t
448 .llvm-libc-types.pthread_attr_t
449 .llvm-libc-types.pthread_key_t
450 .llvm-libc-types.pthread_mutex_t
451 .llvm-libc-types.pthread_mutexattr_t
452 .llvm-libc-types.pthread_once_t
453 .llvm-libc-types.pthread_t
454 .llvm-libc-types.size_t
455 .llvm-libc-types.ssize_t
456 .llvm-libc-types.suseconds_t
457 .llvm-libc-types.time_t
458 .llvm-libc-types.uid_t
463 DEF_FILE sys/utsname.h.def
464 GEN_HDR sys/utsname.h
467 .llvm-libc-types.struct_utsname
472 DEF_FILE sys/wait.h.def
476 .llvm-libc-macros.sys_wait_macros
477 .llvm-libc-types.pid_t
478 .llvm-libc-types.struct_rusage
479 .llvm-libc-types.siginfo_t
484 DEF_FILE termios.h.def
488 .llvm-libc-macros.termios_macros
489 .llvm-libc-types.cc_t
490 .llvm-libc-types.pid_t
491 .llvm-libc-types.speed_t
492 .llvm-libc-types.struct_termios
493 .llvm-libc-types.tcflag_t
502 .llvm-libc-macros.wchar_macros
503 .llvm-libc-types.size_t
504 .llvm-libc-types.wint_t
505 .llvm-libc-types.wchar_t
508 if(LIBC_TARGET_ARCHITECTURE_IS_GPU)
509 file(MAKE_DIRECTORY ${LIBC_INCLUDE_DIR}/gpu)
513 DEF_FILE gpu/rpc.h.def
517 .llvm-libc-types.rpc_opcodes_t
521 if(NOT LLVM_LIBC_FULL_BUILD)
522 # We don't install headers in non-fullbuild mode.
526 function(get_all_install_header_targets out_var)
527 set(all_deps ${ARGN})
528 foreach(target IN LISTS ARGN)
529 get_target_property(deps ${target} DEPS)
533 list(APPEND all_deps ${deps})
534 get_all_install_header_targets(nested_deps ${deps})
535 list(APPEND all_deps ${nested_deps})
537 list(REMOVE_DUPLICATES all_deps)
538 set(${out_var} ${all_deps} PARENT_SCOPE)
539 endfunction(get_all_install_header_targets)
541 get_all_install_header_targets(all_install_header_targets ${TARGET_PUBLIC_HEADERS})
542 add_library(libc-headers INTERFACE)
543 add_dependencies(libc-headers ${all_install_header_targets})
544 target_include_directories(libc-headers SYSTEM INTERFACE ${LIBC_INCLUDE_DIR})
546 foreach(target IN LISTS all_install_header_targets)
547 get_target_property(header_file ${target} HEADER_FILE_PATH)
549 message(FATAL_ERROR "Installable header file '${target}' does not have the "
550 "HEADER_FILE_PATH property set.")
552 file(RELATIVE_PATH relative_path ${LIBC_INCLUDE_DIR} ${header_file})
553 get_filename_component(nested_dir ${relative_path} DIRECTORY)
554 install(FILES ${header_file}
555 DESTINATION ${LIBC_INSTALL_INCLUDE_DIR}/${nested_dir}
556 COMPONENT libc-headers)
557 # The GPU optionally provides the supported declarations externally so
558 # offloading languages like CUDA and OpenMP know what is supported by libc. We
559 # install these in the compiler's resource directory at a preset location.
560 if(LIBC_TARGET_ARCHITECTURE_IS_GPU AND PACKAGE_VERSION)
561 get_target_property(decls_file ${target} DECLS_FILE_PATH)
565 get_clang_resource_dir(resource_dir SUBDIR include)
566 file(RELATIVE_PATH relative_path ${LIBC_INCLUDE_DIR} ${decls_file})
567 get_filename_component(nested_dir ${relative_path} DIRECTORY)
569 ${CMAKE_INSTALL_PREFIX}/${resource_dir}/llvm_libc_wrappers/${nested_dir})
570 install(FILES ${decls_file}
571 DESTINATION ${install_dir}
572 COMPONENT libc-headers)