[libc-commits] [libc] 6a6f3c9 - [libc] Remove hard dependencies on linux from macros headers

Joseph Huber via libc-commits libc-commits at lists.llvm.org
Tue Aug 29 09:38:49 PDT 2023


Author: Joseph Huber
Date: 2023-08-29T11:38:34-05:00
New Revision: 6a6f3c99a29cfb57ad2011f1601b249871053da6

URL: https://github.com/llvm/llvm-project/commit/6a6f3c99a29cfb57ad2011f1601b249871053da6
DIFF: https://github.com/llvm/llvm-project/commit/6a6f3c99a29cfb57ad2011f1601b249871053da6.diff

LOG: [libc] Remove hard dependencies on linux from macros headers

Currently all of this logic expects to include and link with the headers
in the `linux/` directory. This patch adds a wrapper macro to optionally
add the appropriate dependency if it exists. This is preliminary to
adding some GPU specific versions of these files.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D159021

Added: 
    

Modified: 
    libc/include/llvm-libc-macros/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/libc/include/llvm-libc-macros/CMakeLists.txt b/libc/include/llvm-libc-macros/CMakeLists.txt
index 58bbf5e2e43171..8a225889a6f1f8 100644
--- a/libc/include/llvm-libc-macros/CMakeLists.txt
+++ b/libc/include/llvm-libc-macros/CMakeLists.txt
@@ -1,173 +1,172 @@
-add_subdirectory(linux)
-
-add_header(
+# Helper function to set up dependencies if they exist.
+function(add_macro_header name)
+  cmake_parse_arguments(
+    "MACRO_HEADER"
+    "" # Optional arguments
+    "HDR" # Single value arguments
+    "" # Multi-value arguments
+    ${ARGN}
+  )
+  if(TARGET libc.include.llvm-libc-macros.${LIBC_TARGET_OS}.${name})
+    add_header(
+      ${name}
+      HDR
+        ${MACRO_HEADER_HDR}
+      DEPENDS
+        .${LIBC_TARGET_OS}.${name}
+    )
+  else()
+    add_header(
+      ${name}
+      HDR
+        ${MACRO_HEADER_HDR}
+    )
+  endif()
+endfunction(add_macro_header)
+
+if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
+  add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
+endif()
+
+add_macro_header(
   generic_error_number_macros
   HDR
     generic-error-number-macros.h
 )
 
-add_header(
+add_macro_header(
   null_macro
   HDR
     null-macro.h
 )
 
-add_header(
+add_macro_header(
   fcntl_macros
   HDR
     fcntl-macros.h
-  DEPENDS
-    .linux.fcntl_macros
 )
 
-add_header(
+add_macro_header(
   fenv_macros
   HDR
     fenv-macros.h
 )
 
-add_header(
+add_macro_header(
   file_seek_macros
   HDR
     file-seek-macros.h
 )
 
-add_header(
+add_macro_header(
   math_macros
   HDR
     math-macros.h
 )
 
-add_header(
+add_macro_header(
   sched_macros
   HDR
     sched-macros.h
-  DEPENDS
-    .linux.sched_macros
 )
 
-add_header(
+add_macro_header(
   signal_macros
   HDR
     signal-macros.h
-  DEPENDS
-    .linux.signal_macros
 )
 
-add_header(
+add_macro_header(
   stdio_macros
   HDR
     stdio-macros.h
 )
 
-add_header(
+add_macro_header(
   stdlib_macros
   HDR
     stdlib-macros.h
 )
 
-add_header(
+add_macro_header(
   sys_auxv_macros
   HDR
     sys-auxv-macros.h
 )
 
-add_header(
+add_macro_header(
   sys_ioctl_macros
   HDR
     sys-ioctl-macros.h
-  DEPENDS
-    .linux.sys_ioctl_macros
 )
 
-
-add_header(
+add_macro_header(
   sys_stat_macros
   HDR
     sys-stat-macros.h
-  DEPENDS
-    .linux.sys_stat_macros
 )
 
-add_header(
+add_macro_header(
   sys_mman_macros
   HDR
     sys-mman-macros.h
-  DEPENDS
-    .linux.sys_mman_macros
 )
 
-add_header(
+add_macro_header(
   sys_random_macros
   HDR
     sys-random-macros.h
-  DEPENDS
-    .linux.sys_random_macros
 )
 
-add_header(
+add_macro_header(
   sys_resource_macros
   HDR
     sys-resource-macros.h
-  DEPENDS
-    .linux.sys_resource_macros
 )
 
-add_header(
+add_macro_header(
   sys_select_macros
   HDR
     sys-select-macros.h
 )
 
-add_header(
+add_macro_header(
   sys_socket_macros
   HDR
     sys-socket-macros.h
-  DEPENDS
-    .linux.sys_socket_macros
 )
 
-add_header(
+add_macro_header(
   sys_time_macros
   HDR
     sys-time-macros.h
-  DEPENDS
-    .linux.sys_time_macros
 )
 
-add_header(
+add_macro_header(
   sys_wait_macros
   HDR
     sys-wait-macros.h
-  DEPENDS
-    .linux.sys_wait_macros
 )
 
-add_header(
+add_macro_header(
   termios_macros
   HDR
     termios-macros.h
-  DEPENDS
-    .linux.termios_macros
 )
 
-add_header(
+add_macro_header(
   time_macros
   HDR
     time-macros.h
-  DEPENDS
-    .linux.time_macros
 )
 
-add_header(
+add_macro_header(
   unistd_macros
   HDR
     unistd-macros.h
-  DEPENDS
-    .linux.unistd_macros
 )
 
-add_header(
+add_macro_header(
   wchar_macros
   HDR
     wchar-macros.h


        


More information about the libc-commits mailing list