IF(IS_DIRECTORY ${CUDA_TOOLKIT_ROOT_DIR})
    MESSAGE("Using CUDA_TOOLKIT_ROOT_DIR=${CUDA_TOOLKIT_ROOT_DIR}")
    INCLUDE_DIRECTORIES(SYSTEM ${CUDA_TOOLKIT_ROOT_DIR}/include)
	IF(WIN32)
		LINK_DIRECTORIES(${CUDA_TOOLKIT_ROOT_DIR}/lib ${CUDA_TOOLKIT_ROOT_DIR}/lib/x64)
	ELSE()
		LINK_DIRECTORIES(SYSTEM ${CUDA_TOOLKIT_ROOT_DIR}/lib64)
	ENDIF()
ELSE()
    FIND_PACKAGE(CUDA REQUIRED)
    INCLUDE_DIRECTORIES(SYSTEM ${CUDA_INCLUDE_DIRS})
    EXECUTE_PROCESS(
        COMMAND arch
        COMMAND tr -d '\n'
        OUTPUT_VARIABLE ARCH)
    SET(CUDA_RT /usr/local/cuda/targets/${ARCH}-linux)

    LINK_DIRECTORIES(${CUDA_RT}/lib)
ENDIF()
