Skip to content

Commit a24aa7d

Browse files
authoredNov 28, 2024
[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.
1 parent 4a3f46d commit a24aa7d

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed
 

‎offload/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)
4545
list(INSERT CMAKE_MODULE_PATH 0
4646
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
4747
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
48+
"${CMAKE_CURRENT_SOURCE_DIR}/../runtimes/cmake/Modules"
49+
"${LLVM_COMMON_CMAKE_UTILS}"
4850
"${LLVM_COMMON_CMAKE_UTILS}/Modules"
4951
)
5052

‎offload/plugins-nextgen/common/CMakeLists.txt

+3-4
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,16 @@ if (NOT LLVM_LINK_LLVM_DYLIB)
2222
endif()
2323

2424
# Include the RPC server from the `libc` project if availible.
25+
include(FindLibcCommonUtils)
2526
if(TARGET llvmlibc_rpc_server AND ${LIBOMPTARGET_GPU_LIBC_SUPPORT})
26-
target_link_libraries(PluginCommon PRIVATE llvmlibc_rpc_server)
27+
target_link_libraries(PluginCommon PRIVATE llvmlibc_rpc_server llvm-libc-common-utilities)
2728
target_compile_definitions(PluginCommon PRIVATE LIBOMPTARGET_RPC_SUPPORT)
2829
elseif(${LIBOMPTARGET_GPU_LIBC_SUPPORT})
2930
find_library(llvmlibc_rpc_server NAMES llvmlibc_rpc_server
3031
PATHS ${LIBOMPTARGET_LLVM_LIBRARY_DIR} NO_DEFAULT_PATH)
3132
if(llvmlibc_rpc_server)
32-
target_link_libraries(PluginCommon PRIVATE ${llvmlibc_rpc_server})
33+
target_link_libraries(PluginCommon PRIVATE ${llvmlibc_rpc_server} llvm-libc-common-utilities)
3334
target_compile_definitions(PluginCommon PRIVATE LIBOMPTARGET_RPC_SUPPORT)
34-
# We may need to get the headers directly from the 'libc' source directory.
35-
target_include_directories(PluginCommon PRIVATE ${CMAKE_SOURCE_DIR}/../libc/)
3635
endif()
3736
endif()
3837

‎runtimes/cmake/Modules/FindLibcCommonUtils.cmake

+11-6
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@
66
#
77
#===--------------------------------------------------------------------===//
88

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

0 commit comments

Comments
 (0)
Please sign in to comment.