Skip to content

Commit

Permalink
[libc] Add ALIAS option to add_object_library rule.
Browse files Browse the repository at this point in the history
This ALIAS option is now used with threads/callonce target.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D145409
  • Loading branch information
Siva Chandra Reddy committed Mar 6, 2023
1 parent 9f8c974 commit 772e37f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
26 changes: 23 additions & 3 deletions libc/cmake/modules/LLVMLibCObjectRules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -198,18 +198,39 @@ endfunction()
# <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()
Expand All @@ -221,7 +242,6 @@ function(create_object_library fq_target_name)
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}"
Expand Down
11 changes: 3 additions & 8 deletions libc/src/__support/threads/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,11 @@ if(TARGET libc.src.__support.threads.${LIBC_TARGET_OS}.thread)
)
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()
12 changes: 12 additions & 0 deletions libc/src/__support/threads/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,15 @@ add_object_library(
-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
)

0 comments on commit 772e37f

Please sign in to comment.