Skip to content

Commit b5a8077

Browse files
committed
Links CUDA libraries when CUDA is enabled
This commit ensures that the example project links against the CUDA runtime libraries when Open3D has been compiled with CUDA support. It checks for the BUILD_CUDA_MODULE definition in the INTERFACE_COMPILE_DEFINITIONS of the Open3D target and, if present, links against the necessary CUDA libraries.
1 parent c45b03a commit b5a8077

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

examples/cmake/open3d-cmake-find-package/CMakeLists.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,21 @@ endif()
1616
# Find installed Open3D, which exports Open3D::Open3D
1717
find_package(Open3D REQUIRED)
1818

19+
# Check if Open3D was built with CUDA support and link CUDA if needed
20+
get_target_property(OPEN3D_COMPILE_DEFS Open3D::Open3D INTERFACE_COMPILE_DEFINITIONS)
21+
if(OPEN3D_COMPILE_DEFS AND "BUILD_CUDA_MODULE" IN_LIST OPEN3D_COMPILE_DEFS)
22+
find_package(CUDAToolkit REQUIRED)
23+
set(CUDA_LIBS CUDA::cudart)
24+
if(WIN32)
25+
list(APPEND CUDA_LIBS CUDA::cuda_driver)
26+
endif()
27+
else()
28+
set(CUDA_LIBS)
29+
endif()
30+
1931
add_executable(Draw)
2032
target_sources(Draw PRIVATE Draw.cpp)
21-
target_link_libraries(Draw PRIVATE Open3D::Open3D)
33+
target_link_libraries(Draw PRIVATE Open3D::Open3D ${CUDA_LIBS})
2234

2335
# On Windows if BUILD_SHARED_LIBS is enabled, copy .dll files to the executable directory
2436
if(WIN32)

0 commit comments

Comments
 (0)