diff --git a/cmake/celerity-config.cmake.in b/cmake/celerity-config.cmake.in index c77c20c40..ba47a04d2 100644 --- a/cmake/celerity-config.cmake.in +++ b/cmake/celerity-config.cmake.in @@ -24,7 +24,11 @@ find_dependency(spdlog REQUIRED) find_dependency(small_vector REQUIRED) find_dependency(libenvpp REQUIRED) if(@CELERITY_ENABLE_CUDA_BACKEND@) - find_dependency(CUDAToolkit REQUIRED) + if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.17") + find_dependency(CUDAToolkit REQUIRED) + else() + find_dependency(CUDA REQUIRED) + endif() endif() if(CELERITY_SYCL_IMPL STREQUAL "hipSYCL") diff --git a/src/backend/CMakeLists.txt b/src/backend/CMakeLists.txt index 7ff07b617..19cf3a3b6 100644 --- a/src/backend/CMakeLists.txt +++ b/src/backend/CMakeLists.txt @@ -1,12 +1,25 @@ +set(CUDA_OR_CUDA_TOOLKIT_FOUND FALSE) +if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.17") + find_package(CUDAToolkit) + set(CUDA_OR_CUDA_TOOLKIT_FOUND ${CUDAToolkit_FOUND}) +else() + find_package(CUDA) + set(CUDA_OR_CUDA_TOOLKIT_FOUND ${CUDA_FOUND}) +endif() + find_package(CUDAToolkit QUIET) # find_package(LevelZero QUIET) # TODO: Need find module? # find_package(ROCM QUIET) # TODO: Need find module? # TODO: Make conditional on CELERITY_SYCL_IMPL? -option(CELERITY_ENABLE_CUDA_BACKEND "Enable optimized code paths for CUDA backends" ${CUDAToolkit_FOUND}) +option(CELERITY_ENABLE_CUDA_BACKEND "Enable optimized code paths for CUDA backends" ${CUDA_OR_CUDA_TOOLKIT_FOUND}) if(CELERITY_ENABLE_CUDA_BACKEND AND NOT CUDAToolkit_FOUND) # Run find_package again to emit error message - find_package(CUDAToolkit REQUIRED) + if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.17") + find_package(CUDAToolkit REQUIRED) + else() + find_package(CUDA REQUIRED) + endif() endif() add_library(celerity_backends STATIC backend.cc generic_backend.cc) @@ -17,7 +30,12 @@ add_sycl_to_target(TARGET celerity_backends SOURCES) if(CELERITY_ENABLE_CUDA_BACKEND) target_sources(celerity_backends PRIVATE cuda_backend.cc) - target_link_libraries(celerity_backends PUBLIC CUDA::cudart) + if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.17") + target_link_libraries(celerity_backends PUBLIC CUDA::cudart) + else() + target_link_libraries(celerity_backends PUBLIC ${CUDA_LIBRARIES}) + target_include_directories(celerity_backends PUBLIC ${CUDA_INCLUDE_DIRS}) + endif() target_compile_definitions(celerity_backends PUBLIC "CELERITY_DETAIL_BACKEND_CUDA_ENABLED=1") message(STATUS "CUDA backend enabled") endif()