Skip to content

Commit e33e2bc

Browse files
committed
[offload] Fix building standalone against LLVM dylib
When building standalone, and only LLVM dylib is installed, there are no LLVM* library targets. Skip the respective dependencies if the targets are not present, and use the standard `llvm_config()` function to link to the dylib, provided it supplies the needed library, with a fallback to using the static library. Note that I had to change PluginCommon into a STATIC library, for compatibility with `llvm_config`.
1 parent 2c6bf6d commit e33e2bc

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

offload/plugins-nextgen/amdgpu/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,19 @@ target_sources(omptarget.rtl.amdgpu PRIVATE src/rtl.cpp)
88
target_include_directories(omptarget.rtl.amdgpu PRIVATE
99
${CMAKE_CURRENT_SOURCE_DIR}/utils)
1010

11+
set(USE_SHARED)
12+
if (LLVM_LINK_LLVM_DYLIB)
13+
set(USE_SHARED USE_SHARED)
14+
endif()
15+
llvm_config(omptarget.rtl.amdgpu ${USE_SHARED} FrontendOffloading)
16+
1117
if(hsa-runtime64_FOUND AND NOT "amdgpu" IN_LIST LIBOMPTARGET_DLOPEN_PLUGINS)
1218
message(STATUS "Building AMDGPU plugin linked against libhsa")
13-
target_link_libraries(omptarget.rtl.amdgpu PRIVATE hsa-runtime64::hsa-runtime64 LLVMFrontendOffloading)
19+
target_link_libraries(omptarget.rtl.amdgpu PRIVATE hsa-runtime64::hsa-runtime64)
1420
else()
1521
message(STATUS "Building AMDGPU plugin for dlopened libhsa")
1622
target_include_directories(omptarget.rtl.amdgpu PRIVATE dynamic_hsa)
1723
target_sources(omptarget.rtl.amdgpu PRIVATE dynamic_hsa/hsa.cpp)
18-
target_link_libraries(omptarget.rtl.amdgpu PRIVATE LLVMFrontendOffloading)
1924
endif()
2025

2126
# Configure testing for the AMDGPU plugin. We will build tests if we could a

offload/plugins-nextgen/common/CMakeLists.txt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
# NOTE: Don't try to build `PluginInterface` using `add_llvm_library` because we
22
# don't want to export `PluginInterface` while `add_llvm_library` requires that.
3-
add_library(PluginCommon OBJECT
3+
add_library(PluginCommon STATIC
44
src/PluginInterface.cpp
55
src/GlobalHandler.cpp
66
src/JIT.cpp
77
src/RPC.cpp
88
src/Utils/ELF.cpp
99
)
10-
add_dependencies(PluginCommon intrinsics_gen LLVMProfileData)
10+
add_dependencies(PluginCommon intrinsics_gen)
11+
if (TARGET LLVMProfileData)
12+
add_dependencies(PluginCommon LLVMProfileData)
13+
endif()
1114

1215
# Only enable JIT for those targets that LLVM can support.
1316
set(supported_jit_targets AMDGPU NVPTX)
@@ -43,7 +46,11 @@ target_compile_definitions(PluginCommon PRIVATE
4346

4447
target_compile_options(PluginCommon PUBLIC ${offload_compile_flags})
4548
target_link_options(PluginCommon PUBLIC ${offload_link_flags})
46-
target_link_libraries(PluginCommon PRIVATE LLVMProfileData)
49+
set(USE_SHARED)
50+
if (LLVM_LINK_LLVM_DYLIB)
51+
set(USE_SHARED USE_SHARED)
52+
endif()
53+
llvm_config(PluginCommon ${USE_SHARED} ProfileData)
4754

4855
target_include_directories(PluginCommon PUBLIC
4956
${CMAKE_CURRENT_SOURCE_DIR}/include

0 commit comments

Comments
 (0)