diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt --- a/libc/CMakeLists.txt +++ b/libc/CMakeLists.txt @@ -20,15 +20,30 @@ set(LIBC_ENABLE_USE_BY_CLANG OFF CACHE BOOL "Whether or not to place libc in a build directory findable by a just built clang") if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND LIBC_ENABLE_USE_BY_CLANG) + if(LIBC_TARGET_ARCHITECTURE_IS_GPU) + set(LIBC_INCLUDE_DIR ${LLVM_BINARY_DIR}/include/gpu-none-llvm) + set(LIBC_INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR}/gpu-none-llvm) + else() + set(LIBC_INCLUDE_DIR ${LLVM_BINARY_DIR}/include/${LLVM_DEFAULT_TARGET_TRIPLE}) + set(LIBC_INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}) + endif() set(LIBC_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}) else() if(NOT LIBC_ENABLE_USE_BY_CLANG) + set(LIBC_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include) set(LIBC_LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) elseif(LLVM_LIBRARY_OUTPUT_INTDIR) + set(LIBC_INCLUDE_DIR ${LLVM_BINARY_DIR}/include) set(LIBC_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) else() + set(LIBC_INCLUDE_DIR ${CMAKE_BINARY_DIR}/include) set(LIBC_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}) endif() + if(LIBC_TARGET_ARCHITECTURE_IS_GPU) + set(LIBC_INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR}/gpu-none-llvm) + else() + set(LIBC_INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR}) + endif() endif() if(LLVM_LIBC_FULL_BUILD OR LIBC_GPU_BUILD OR LIBC_GPU_ARCHITECTURES) diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt --- a/libc/include/CMakeLists.txt +++ b/libc/include/CMakeLists.txt @@ -508,8 +508,7 @@ endfunction(get_all_install_header_targets) get_all_install_header_targets(all_install_header_targets ${TARGET_PUBLIC_HEADERS}) -add_custom_target(libc-headers) -add_dependencies(libc-headers ${all_install_header_targets}) +add_library(libc-headers INTERFACE) foreach(target IN LISTS all_install_header_targets) get_target_property(header_file ${target} HEADER_FILE_PATH) if(NOT header_file) @@ -517,13 +516,17 @@ "HEADER_FILE_PATH property set.") endif() file(RELATIVE_PATH relative_path ${LIBC_INCLUDE_BINARY_DIR} ${header_file}) + set(dst "${LIBC_INCLUDE_DIR}/${relative_path}") + add_custom_command(OUTPUT ${dst} + DEPENDS ${header_file} + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${header_file} ${dst} + COMMENT "Copying C header ${header_file}") + list(APPEND _all_includes "${dst}") get_filename_component(nested_dir ${relative_path} DIRECTORY) - # The GPU headers are installed to 'gpu-none-llvm/' to prevent shadowing the - # system headers. - if(LIBC_TARGET_ARCHITECTURE_IS_GPU) - set(nested_dir gpu-none-llvm/${nested_dir}) - endif() install(FILES ${header_file} - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${nested_dir} + DESTINATION ${LIBC_INSTALL_INCLUDE_DIR}/${nested_dir} COMPONENT libc-headers) endforeach() +add_custom_target(copy-libc-headers ALL DEPENDS ${_all_includes}) +add_dependencies(libc-headers ${all_install_header_targets} copy-libc-headers) +target_include_directories(libc-headers SYSTEM INTERFACE ${LLVM_BINARY_DIR}/include)