[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
Mon Jun 12 17:14:35 PDT 2023


phosek updated this revision to Diff 530725.
phosek marked 4 inline comments as done.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152592/new/

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,19 @@
                         "HEADER_FILE_PATH property set.")
   endif()
   file(RELATIVE_PATH relative_path ${LIBC_INCLUDE_BINARY_DIR} ${header_file})
-  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})
+  if(LIBC_ENABLE_USE_BY_CLANG)
+    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}")
   endif()
+  get_filename_component(nested_dir ${relative_path} DIRECTORY)
   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 ${LIBC_INCLUDE_DIR})
Index: libc/CMakeLists.txt
===================================================================
--- libc/CMakeLists.txt
+++ libc/CMakeLists.txt
@@ -19,16 +19,26 @@
 
 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)
+  set(LIBC_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/gnu-none-llvm)
+elseif(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND LIBC_ENABLE_USE_BY_CLANG)
+  set(LIBC_INCLUDE_DIR ${LLVM_BINARY_DIR}/include/${LLVM_DEFAULT_TARGET_TRIPLE})
+  set(LIBC_INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR}/${LLVM_DEFAULT_TARGET_TRIPLE})
   set(LIBC_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE})
 else()
   if(NOT LIBC_ENABLE_USE_BY_CLANG)
-    set(LIBC_LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
+    set(LIBC_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include)
+    set(LIBC_LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/lib)
   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()
+  set(LIBC_INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR})
 endif()
 
 if(LLVM_LIBC_FULL_BUILD OR LIBC_GPU_BUILD OR LIBC_GPU_ARCHITECTURES)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152592.530725.patch
Type: text/x-patch
Size: 3450 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230613/23092d12/attachment.bin>


More information about the libc-commits mailing list