Skip to content

Commit

Permalink
Cmake cuda find_package cuda is deprecated. (#5953)
Browse files Browse the repository at this point in the history
* find_package cuda is deprecated. CMAKE_CUDA_COMPILED was added to cmake 3.11.

* Disable gpu_people if cuda >=12.0

* If cmake is newer than 3.17 use the CUDAToolkit package instead of CUDA.

* Use the default and reason variables.

* Search for CUDA quietly in find_packages calls.

Print message if not found

---------

Co-authored-by: = <=>
  • Loading branch information
larshg committed Mar 5, 2024
1 parent 99ff2dd commit 1bf96dc
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 16 deletions.
27 changes: 24 additions & 3 deletions cmake/pcl_find_cuda.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,32 @@ if(MSVC)
set(CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE OFF CACHE BOOL "CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE")
endif()

set(CUDA_FIND_QUIETLY TRUE)
find_package(CUDA 9.0)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.11)
include(CheckLanguage)
check_language(CUDA)
if(CMAKE_CUDA_COMPILER)
enable_language(CUDA)

if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.17)
find_package(CUDAToolkit QUIET)
else()
set(CUDA_FIND_QUIETLY TRUE)
find_package(CUDA 9.0)
endif()

set(CUDA_FOUND TRUE)
set(CUDA_VERSION_STRING ${CMAKE_CUDA_COMPILER_VERSION})
else()
message(STATUS "No CUDA compiler found")
endif()
else()
set(CUDA_FIND_QUIETLY TRUE)
find_package(CUDA 9.0)
endif()

if(CUDA_FOUND)
message(STATUS "Found CUDA Toolkit v${CUDA_VERSION_STRING}")

enable_language(CUDA)
set(HAVE_CUDA TRUE)

if (CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA")
Expand Down Expand Up @@ -60,4 +79,6 @@ if(CUDA_FOUND)
target_include_directories(pcl_cuda INTERFACE ${CUDA_TOOLKIT_INCLUDE})

endif ()
else()
message(STATUS "CUDA was not found.")
endif()
36 changes: 23 additions & 13 deletions gpu/people/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ set(SUBSYS_PATH gpu/people)
set(SUBSYS_DESC "Point cloud people library")
set(SUBSYS_DEPS common features filters geometry gpu_containers gpu_utils io kdtree octree search segmentation surface visualization)

PCL_SUBSYS_OPTION(build ${SUBSYS_NAME} ${SUBSYS_DESC} OFF)
if(${CUDA_VERSION_STRING} VERSION_GREATER_EQUAL "12.0")
set(DEFAULT FALSE)
set(REASON "gpu_people uses textures which was removed in CUDA 12")
else()
set(DEFAULT TRUE)
endif()

PCL_SUBSYS_OPTION(build ${SUBSYS_NAME} ${SUBSYS_DESC} ${DEFAULT} ${REASON})
PCL_SUBSYS_DEPEND(build NAME ${SUBSYS_NAME} DEPS ${SUBSYS_DEPS})
mark_as_advanced("BUILD_${SUBSYS_NAME}")

Expand All @@ -13,19 +20,22 @@ if(NOT build)
return()
endif()

#find NPP
unset(CUDA_npp_LIBRARY CACHE)
find_cuda_helper_libs(nppc)
find_cuda_helper_libs(npps)
if(CUDA_VERSION VERSION_GREATER "9.0" OR CUDA_VERSION VERSION_EQUAL "9.0")
find_cuda_helper_libs(nppim)
find_cuda_helper_libs(nppidei)
set(CUDA_npp_LIBRARY ${CUDA_nppc_LIBRARY} ${CUDA_nppim_LIBRARY} ${CUDA_nppidei_LIBRARY} ${CUDA_npps_LIBRARY} CACHE STRING "npp library")
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.17)
set(CUDA_npp_LIBRARY CUDA::nppc CUDA::nppim CUDA::nppidei CUDA::npps CACHE STRING "npp library")
else()
find_cuda_helper_libs(nppi)
set(CUDA_npp_LIBRARY ${CUDA_nppc_LIBRARY} ${CUDA_nppi_LIBRARY} ${CUDA_npps_LIBRARY} CACHE STRING "npp library")
#find NPP
unset(CUDA_npp_LIBRARY CACHE)
find_cuda_helper_libs(nppc)
find_cuda_helper_libs(npps)
if(CUDA_VERSION VERSION_GREATER_EQUAL "9.0")
find_cuda_helper_libs(nppim)
find_cuda_helper_libs(nppidei)
set(CUDA_npp_LIBRARY ${CUDA_nppc_LIBRARY} ${CUDA_nppim_LIBRARY} ${CUDA_nppidei_LIBRARY} ${CUDA_npps_LIBRARY} CACHE STRING "npp library")
else()
find_cuda_helper_libs(nppi)
set(CUDA_npp_LIBRARY ${CUDA_nppc_LIBRARY} ${CUDA_nppi_LIBRARY} ${CUDA_npps_LIBRARY} CACHE STRING "npp library")
endif()
endif()

#Label_skeleton

file(GLOB srcs src/*.cpp src/*.h*)
Expand All @@ -46,7 +56,7 @@ include_directories(
set(LIB_NAME "pcl_${SUBSYS_NAME}")

PCL_CUDA_ADD_LIBRARY(${LIB_NAME} COMPONENT ${SUBSYS_NAME} SOURCES ${srcs} ${hdrs} ${srcs_cuda})
target_link_libraries(${LIB_NAME} pcl_cuda pcl_common pcl_search pcl_surface pcl_segmentation pcl_features pcl_sample_consensus pcl_gpu_utils pcl_gpu_containers "${CUDA_CUDART_LIBRARY}" ${CUDA_npp_LIBRARY})
target_link_libraries(${LIB_NAME} pcl_cuda pcl_common pcl_search pcl_surface pcl_segmentation pcl_features pcl_sample_consensus pcl_gpu_utils pcl_gpu_containers ${CUDA_CUDART_LIBRARY} ${CUDA_npp_LIBRARY})

if(UNIX OR APPLE)
target_compile_options(${LIB_NAME} INTERFACE $<$<COMPILE_LANGUAGE:CUDA>:"-Xcompiler=-fPIC">)
Expand Down

0 comments on commit 1bf96dc

Please sign in to comment.