[libc-commits] [PATCH] D145409: [libc] Add ALIAS option to add_object_library rule.

Siva Chandra via Phabricator via libc-commits libc-commits at lists.llvm.org
Mon Mar 6 11:21:31 PST 2023


sivachandra created this revision.
sivachandra added a reviewer: lntue.
Herald added subscribers: libc-commits, jeroen.dobbelaere, ecnelises, tschuett.
Herald added projects: libc-project, All.
sivachandra requested review of this revision.

This ALIAS option is now used with threads/callonce target.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145409

Files:
  libc/cmake/modules/LLVMLibCObjectRules.cmake
  libc/src/__support/threads/CMakeLists.txt
  libc/src/__support/threads/linux/CMakeLists.txt


Index: libc/src/__support/threads/linux/CMakeLists.txt
===================================================================
--- libc/src/__support/threads/linux/CMakeLists.txt
+++ libc/src/__support/threads/linux/CMakeLists.txt
@@ -40,3 +40,15 @@
     -fno-omit-frame-pointer # This allows us to sniff out the thread args from
                             # the new thread's stack reliably.
 )
+
+add_object_library(
+  callonce
+  SRCS
+    callonce.cpp
+  HDRS
+    ../callonce.h
+  DEPENDS
+    libc.include.sys_syscall
+    libc.src.__support.CPP.atomic
+    libc.src.__support.OSUtil.osutil
+)
Index: libc/src/__support/threads/CMakeLists.txt
===================================================================
--- libc/src/__support/threads/CMakeLists.txt
+++ libc/src/__support/threads/CMakeLists.txt
@@ -54,16 +54,11 @@
   )
 endif()
 
-if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS}/callonce.cpp)
+if(TARGET libc.src.__support.threads.${LIBC_TARGET_OS}.callonce)
   add_object_library(
     callonce
-    SRCS
-      ${LIBC_TARGET_OS}/callonce.cpp
-    HDRS
-      callonce.h
+    ALIAS
     DEPENDS
-      libc.include.sys_syscall
-      libc.src.__support.CPP.atomic
-      libc.src.__support.OSUtil.osutil
+      .${LIBC_TARGET_OS}.callonce
   )
 endif()
Index: libc/cmake/modules/LLVMLibCObjectRules.cmake
===================================================================
--- libc/cmake/modules/LLVMLibCObjectRules.cmake
+++ libc/cmake/modules/LLVMLibCObjectRules.cmake
@@ -198,18 +198,39 @@
 #       <target_name>
 #       HDRS <list of header files>
 #       SRCS <list of source files>
-#       DEPENDS <list of dependencies>
+#       [ALIAS] <If this object library is an alias for another object library.>
+#       DEPENDS <list of dependencies; Should be a single item for ALIAS libraries>
 #       COMPILE_OPTIONS <optional list of special compile options for this target>
 #       FLAGS <optional list of flags>
 function(create_object_library fq_target_name)
   cmake_parse_arguments(
     "ADD_OBJECT"
-    "NO_GPU_BUNDLE" # No optional arguments
+    "ALIAS;NO_GPU_BUNDLE" # optional arguments
     "CXX_STANDARD" # Single value arguments
     "SRCS;HDRS;COMPILE_OPTIONS;DEPENDS;FLAGS" # Multivalue arguments
     ${ARGN}
   )
 
+  get_fq_deps_list(fq_deps_list ${ADD_OBJECT_DEPENDS})
+
+  if(ADD_OBJECT_ALIAS)
+    if(ADD_OBJECT_SRCS OR ADD_OBJECT_HDRS)
+      message(FATAL_ERROR
+              "${fq_target_name}: object library alias cannot have SRCS and/or HDRS.")
+    endif()
+    list(LENGTH fq_deps_list depends_size)
+    if(NOT ${depends_size} EQUAL 1)
+      message(FATAL_ERROR
+              "${fq_targe_name}: object library alias should have exactly one DEPENDS.")
+    endif()
+    add_library(
+      ${fq_target_name}
+      ALIAS
+      ${fq_deps_list}
+    )
+    return()
+  endif()
+
   if(NOT ADD_OBJECT_SRCS)
     message(FATAL_ERROR "'add_object_library' rule requires SRCS to be specified.")
   endif()
@@ -221,7 +242,6 @@
     set(internal_target_name ${fq_target_name})
   endif()
 
-  get_fq_deps_list(fq_deps_list ${ADD_OBJECT_DEPENDS})
   _get_common_compile_options(
     compile_options
     "${ADD_OBJECT_FLAGS}"


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145409.502740.patch
Type: text/x-patch
Size: 3182 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230306/6cfb3a5f/attachment.bin>


More information about the libc-commits mailing list