diff --git a/libc/cmake/modules/LLVMLibCObjectRules.cmake b/libc/cmake/modules/LLVMLibCObjectRules.cmake --- a/libc/cmake/modules/LLVMLibCObjectRules.cmake +++ b/libc/cmake/modules/LLVMLibCObjectRules.cmake @@ -198,18 +198,39 @@ # # HDRS # SRCS -# DEPENDS +# [ALIAS] +# DEPENDS # COMPILE_OPTIONS # 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}" diff --git a/libc/src/__support/threads/CMakeLists.txt b/libc/src/__support/threads/CMakeLists.txt --- a/libc/src/__support/threads/CMakeLists.txt +++ b/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() diff --git a/libc/src/__support/threads/linux/CMakeLists.txt b/libc/src/__support/threads/linux/CMakeLists.txt --- a/libc/src/__support/threads/linux/CMakeLists.txt +++ b/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 +)