[Offload] Use libc 'hand-in-hand' module to find RPC header (#117928)

Summary:
We should now use the official™ way to include the files from
`libc/shared`. This required some code to make sure that it's not
included twice if multiple people use it as well as a sanity check on
the directory.
This commit is contained in:
Joseph Huber 2024-11-27 20:14:13 -06:00 committed by GitHub
parent 4a3f46de50
commit a24aa7dfa5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 10 deletions

View File

@ -45,6 +45,8 @@ set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)
list(INSERT CMAKE_MODULE_PATH 0
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
"${CMAKE_CURRENT_SOURCE_DIR}/../runtimes/cmake/Modules"
"${LLVM_COMMON_CMAKE_UTILS}"
"${LLVM_COMMON_CMAKE_UTILS}/Modules"
)

View File

@ -22,17 +22,16 @@ if (NOT LLVM_LINK_LLVM_DYLIB)
endif()
# Include the RPC server from the `libc` project if availible.
include(FindLibcCommonUtils)
if(TARGET llvmlibc_rpc_server AND ${LIBOMPTARGET_GPU_LIBC_SUPPORT})
target_link_libraries(PluginCommon PRIVATE llvmlibc_rpc_server)
target_link_libraries(PluginCommon PRIVATE llvmlibc_rpc_server llvm-libc-common-utilities)
target_compile_definitions(PluginCommon PRIVATE LIBOMPTARGET_RPC_SUPPORT)
elseif(${LIBOMPTARGET_GPU_LIBC_SUPPORT})
find_library(llvmlibc_rpc_server NAMES llvmlibc_rpc_server
PATHS ${LIBOMPTARGET_LLVM_LIBRARY_DIR} NO_DEFAULT_PATH)
if(llvmlibc_rpc_server)
target_link_libraries(PluginCommon PRIVATE ${llvmlibc_rpc_server})
target_link_libraries(PluginCommon PRIVATE ${llvmlibc_rpc_server} llvm-libc-common-utilities)
target_compile_definitions(PluginCommon PRIVATE LIBOMPTARGET_RPC_SUPPORT)
# We may need to get the headers directly from the 'libc' source directory.
target_include_directories(PluginCommon PRIVATE ${CMAKE_SOURCE_DIR}/../libc/)
endif()
endif()

View File

@ -6,9 +6,14 @@
#
#===--------------------------------------------------------------------===//
add_library(llvm-libc-common-utilities INTERFACE)
# TODO: Reorganize the libc shared section so that it can be included without
# adding the root "libc" directory to the include path.
target_include_directories(llvm-libc-common-utilities INTERFACE ${CMAKE_CURRENT_LIST_DIR}/../../../libc)
target_compile_definitions(llvm-libc-common-utilities INTERFACE LIBC_NAMESPACE=__llvm_libc_common_utils)
target_compile_features(llvm-libc-common-utilities INTERFACE cxx_std_17)
if(NOT TARGET llvm-libc-common-utilities)
set(libc_path ${CMAKE_CURRENT_LIST_DIR}/../../../libc)
if (EXISTS ${libc_path} AND IS_DIRECTORY ${libc_path})
add_library(llvm-libc-common-utilities INTERFACE)
# TODO: Reorganize the libc shared section so that it can be included without
# adding the root "libc" directory to the include path.
target_include_directories(llvm-libc-common-utilities INTERFACE ${libc_path})
target_compile_definitions(llvm-libc-common-utilities INTERFACE LIBC_NAMESPACE=__llvm_libc_common_utils)
target_compile_features(llvm-libc-common-utilities INTERFACE cxx_std_17)
endif()
endif()