[libc-commits] [PATCH] D152592: [libc] Place headers in the right include directory
Petr Hosek via Phabricator via libc-commits
libc-commits at lists.llvm.org
Fri Jun 9 15:44:51 PDT 2023
phosek created this revision.
phosek added reviewers: sivachandra, aidengrossman.
Herald added projects: libc-project, All.
Herald added a subscriber: libc-commits.
phosek requested review of this revision.
When LLVM_ENABLE_PER_TARGET_RUNTIME_DIR is enabled, place headers
in `include/<target>` directory, otherwise use `include/`.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D152592
Files:
libc/CMakeLists.txt
libc/include/CMakeLists.txt
Index: libc/include/CMakeLists.txt
===================================================================
--- libc/include/CMakeLists.txt
+++ 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)
Index: libc/CMakeLists.txt
===================================================================
--- libc/CMakeLists.txt
+++ 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)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152592.530104.patch
Type: text/x-patch
Size: 3315 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230609/1dec68e1/attachment.bin>
More information about the libc-commits
mailing list