Skip to content

Commit 323504f

Browse files
committed
CufRuntime only supports static library
1 parent 3b57346 commit 323504f

File tree

4 files changed

+31
-32
lines changed

4 files changed

+31
-32
lines changed

flang-rt/cmake/modules/AddFlangRT.cmake

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,21 @@ function (add_flangrt_library name)
138138
add_library("${name_shared}" SHARED ${extra_args} ${ARG_ADDITIONAL_HEADERS} ${ARG_UNPARSED_ARGUMENTS})
139139
endif ()
140140

141+
# Provide a default target if building both and which exists in either setting.
142+
if (BUILD_SHARED_LIBS)
143+
if (build_shared)
144+
add_library(${name}.default ALIAS ${name_shared})
145+
else ()
146+
add_library(${name}.default ALIAS ${name})
147+
endif ()
148+
else ()
149+
if (build_static)
150+
add_library(${name}.default ALIAS ${name_static})
151+
else ()
152+
add_library(${name}.default ALIAS ${name})
153+
endif ()
154+
endif ()
155+
141156
foreach (tgtname IN LISTS libtargets)
142157
if (NOT WIN32)
143158
# Use same stem name for .a and .so. Common in UNIX environments.

flang-rt/cmake/modules/AddFlangRTOffload.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
macro(enable_cuda_compilation name files)
1010
if (FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT STREQUAL "CUDA")
11-
if (FLANG_RT_ENABLE_SHARED)
11+
if (NOT FLANG_RT_ENABLE_STATIC)
1212
message(FATAL_ERROR
13-
"FLANG_RT_ENABLE_SHARED is not supported for CUDA build of Flang-RT"
13+
"FLANG_RT_ENABLE_STATIC is required for CUDA build of Flang-RT"
1414
)
1515
endif()
1616

flang-rt/lib/flang_rt/CUDA/CMakeLists.txt

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@
66
#
77
#===------------------------------------------------------------------------===#
88

9-
# libCufRuntime depends on a certain version of CUDA. To be able to have
10-
# multiple build of this library with different CUDA version, the version is
11-
# added to the library name.
12-
set(CUFRT_LIBNAME CufRuntime_cuda_${CUDAToolkit_VERSION_MAJOR})
139

14-
add_flangrt_library(${CUFRT_LIBNAME}
10+
add_flangrt_library(CufRuntime STATIC
1511
allocatable.cpp
1612
allocator.cpp
1713
descriptor.cpp
@@ -20,21 +16,19 @@ add_flangrt_library(${CUFRT_LIBNAME}
2016
memory.cpp
2117
registration.cpp
2218
)
23-
target_include_directories(${CUFRT_LIBNAME} PRIVATE ${CUDAToolkit_INCLUDE_DIRS})
2419

25-
if (BUILD_SHARED_LIBS)
26-
set(CUDA_RT_TARGET CUDA::cudart)
27-
else()
28-
set(CUDA_RT_TARGET CUDA::cudart_static)
29-
endif()
30-
31-
target_link_libraries(${CUFRT_LIBNAME}
32-
PRIVATE
33-
flang_rt
34-
${CUDA_RT_TARGET}
20+
# libCufRuntime depends on a certain version of CUDA. To be able to have
21+
# multiple build of this library with different CUDA version, the version is
22+
# added to the library name.
23+
set_target_properties(CufRuntime
24+
PROPERTIES
25+
OUTPUT_NAME "CufRuntime_cuda_${CUDAToolkit_VERSION_MAJOR}"
3526
)
3627

37-
# Phony build target that does not include the CUDA version.
38-
add_custom_target(CufRuntime)
39-
add_dependencies(CufRuntime ${CUFRT_LIBNAME})
28+
target_include_directories(CufRuntime PRIVATE ${CUDAToolkit_INCLUDE_DIRS})
4029

30+
target_link_libraries(CufRuntime
31+
PUBLIC
32+
flang_rt
33+
CUDA::cudart_static
34+
)

flang-rt/unittests/Runtime/CUDA/CMakeLists.txt

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,7 @@ add_flangrt_unittest(FlangCufRuntimeTests
1212
Memory.cpp
1313
)
1414

15-
if (BUILD_SHARED_LIBS)
16-
set(CUDA_RT_TARGET CUDA::cudart)
17-
else()
18-
set(CUDA_RT_TARGET CUDA::cudart_static)
19-
endif()
20-
2115
target_link_libraries(FlangCufRuntimeTests
2216
PRIVATE
23-
${CUDA_RT_TARGET}
24-
CufRuntime_cuda_${CUDAToolkit_VERSION_MAJOR}
25-
flang_rt.unittest
17+
CufRuntime
2618
)
27-
28-
target_include_directories(FlangCufRuntimeTests PRIVATE ${CUDAToolkit_INCLUDE_DIRS})

0 commit comments

Comments
 (0)