From d6686240d5938869c12b60f06dd8b394a4f352df Mon Sep 17 00:00:00 2001 From: Anatoly Baksheev Date: Wed, 24 Nov 2010 18:44:11 +0000 Subject: [PATCH] added version detection for NPP --- modules/gpu/CMakeLists.txt | 7 ++-- modules/gpu/FindNPP.cmake | 69 ++++++++++++++++++++++++-------------- samples/CMakeLists.txt | 2 +- 3 files changed, 48 insertions(+), 30 deletions(-) diff --git a/modules/gpu/CMakeLists.txt b/modules/gpu/CMakeLists.txt index 5e78ee0030..569447855e 100644 --- a/modules/gpu/CMakeLists.txt +++ b/modules/gpu/CMakeLists.txt @@ -32,9 +32,10 @@ source_group("Src\\Cuda" FILES ${lib_cuda} ${lib_cuda_hdrs}) file(GLOB lib_hdrs "include/opencv2/${name}/*.h*") source_group("Include" FILES ${lib_hdrs}) -if (HAVE_CUDA) - set(NPP_FIND_REQUIRED 1) - include(FindNPP.cmake) +if (HAVE_CUDA) + get_filename_component(_path_to_findnpp "${CMAKE_CURRENT_LIST_FILE}" PATH) + set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${_path_to_findnpp}) + find_package(NPP REQUIRED) include_directories(${CUDA_INCLUDE_DIRS} ${CUDA_NPP_INCLUDES}) diff --git a/modules/gpu/FindNPP.cmake b/modules/gpu/FindNPP.cmake index 04c3f5bce8..1bf018965b 100644 --- a/modules/gpu/FindNPP.cmake +++ b/modules/gpu/FindNPP.cmake @@ -5,6 +5,10 @@ # CUDA_NPP_LIBRARY_ROOT_DIR -- Path to the NPP dorectory. # CUDA_NPP_INCLUDES -- NPP Include directories. # CUDA_NPP_LIBRARIES -- NPP libraries. +# NPP_VERSION -- NPP version in format "major.minor.build". +# +# If not found automatically, please set CUDA_NPP_LIBRARY_ROOT_DIR or +# set enviroment varivabe $CUDA_NPP_ROOT # # Author: Anatoly Baksheev, Itseez Ltd. # @@ -41,24 +45,25 @@ if(NOT "${CUDA_NPP_LIBRARY_ROOT_DIR}" STREQUAL "${CUDA_NPP_LIBRARY_ROOT_DIR_INTE unset(CUDA_NPP_LIBRARIES CACHE) endif() -if(${CMAKE_SIZEOF_VOID_P} EQUAL 4) +if(CMAKE_SIZEOF_VOID_P EQUAL 4) if (UNIX OR APPLE) set(NPP_SUFFIX "32") else() set(NPP_SUFFIX "-mt") endif() -else(${CMAKE_SIZEOF_VOID_P} EQUAL 4) +else(CMAKE_SIZEOF_VOID_P EQUAL 4) if (UNIX OR APPLE) set(NPP_SUFFIX "64") else() set(NPP_SUFFIX "-mt-x64") endif() -endif(${CMAKE_SIZEOF_VOID_P} EQUAL 4) +endif(CMAKE_SIZEOF_VOID_P EQUAL 4) -if(NOT CUDA_NPP_LIBRARY_ROOT_DIR) - set(CUDA_NPP_LIBRARY_ROOT_DIR $ENV{CUDA_NPP_ROOT} CACHE PATH "NPP root directory." FORCE) +if(NOT CUDA_NPP_LIBRARY_ROOT_DIR OR CUDA_NPP_LIBRARY_ROOT_DIR STREQUAL "") + unset(CUDA_NPP_LIBRARY_ROOT_DIR CACHE) find_path(CUDA_NPP_LIBRARY_ROOT_DIR "common/npp/include/npp.h" PATHS ENV CUDA_NPP_ROOT DOC "NPP root directory.") -endif (NOT CUDA_NPP_LIBRARY_ROOT_DIR) + MESSAGE(STATUS "NPP root directory: " ${CUDA_NPP_LIBRARY_ROOT_DIR}) +endif() # Search includes in our own paths. find_path(CUDA_NPP_INCLUDES npp.h PATHS "${CUDA_NPP_LIBRARY_ROOT_DIR}/common/npp/include") @@ -76,30 +81,42 @@ find_library(CUDA_NPP_LIBRARIES # Search default search paths, after we search our own set of paths. find_library(CUDA_NPP_LIBRARIES NAMES npp${NPP_SUFFIX} libnpp${NPP_SUFFIX} DOC "NPP library") -mark_as_advanced(CUDA_NPP_LIBRARIES) +mark_as_advanced(CUDA_NPP_LIBRARIES) + +if(EXISTS ${CUDA_NPP_INCLUDES}/nppversion.h) + file( STRINGS ${CUDA_NPP_INCLUDES}/nppversion.h npp_major REGEX "#define NPP_VERSION_MAJOR.*") + file( STRINGS ${CUDA_NPP_INCLUDES}/nppversion.h npp_minor REGEX "#define NPP_VERSION_MINOR.*") + file( STRINGS ${CUDA_NPP_INCLUDES}/nppversion.h npp_build REGEX "#define NPP_VERSION_BUILD.*") + + string( REGEX REPLACE "#define NPP_VERSION_MAJOR[ \t]+|//.*" "" npp_major ${npp_major}) + string( REGEX REPLACE "#define NPP_VERSION_MINOR[ \t]+|//.*" "" npp_minor ${npp_minor}) + string( REGEX REPLACE "#define NPP_VERSION_BUILD[ \t]+|//.*" "" npp_build ${npp_build}) + + string( REGEX MATCH "[0-9]+" npp_major ${npp_major} ) + string( REGEX MATCH "[0-9]+" npp_minor ${npp_minor} ) + string( REGEX MATCH "[0-9]+" npp_build ${npp_build} ) + set( NPP_VERSION "${npp_major}.${npp_minor}.${npp_build}") + MESSAGE(STATUS "Npp version: " ${NPP_VERSION}) +endif() if(NOT EXISTS ${CUDA_NPP_LIBRARIES} OR NOT EXISTS ${CUDA_NPP_INCLUDES}/npp.h) - set(CUDA_FOUND FALSE) + set(CUDA_NPP_FOUND FALSE) unset(CUDA_NPP_INCLUDES CACHE) unset(CUDA_NPP_LIBRARIES CACHE) - - if(NPP_FIND_REQUIRED) - message(FATAL_ERROR "NPP headers/libraries are not found. Specify CUDA_NPP_LIBRARY_ROOT_DIR.") - elseif(NOT CUDA_FIND_QUIETLY) - message("NPP headers/libraries are not found. Please specify CUDA_NPP_LIBRARY_ROOT_DIR in CMake or set $NPP_ROOT_DIR.") - endif() -else() - if(APPLE) - # We need to add the path to cudart to the linker using rpath, since the - # library name for the cuda libraries is prepended with @rpath. - get_filename_component(_cuda_path_to_npp "${CUDA_NPP_LIBRARIES}" PATH) - if(_cuda_path_to_npp) - list(APPEND CUDA_NPP_LIBRARIES -Wl,-rpath "-Wl,${_cuda_path_to_npp}") - endif() - endif() - - set(CUDA_NPP_FOUND TRUE) - set(CUDA_NPP_LIBRARY_ROOT_DIR_INTERNAL "${CUDA_NPP_LIBRARY_ROOT_DIR}" CACHE INTERNAL "This is the value of the last time CUDA_NPP_LIBRARY_ROOT_DIR was set successfully." FORCE) + message(FATAL_ERROR "NPP headers/libraries are not found. Please specify CUDA_NPP_LIBRARY_ROOT_DIR in CMake or set $NPP_ROOT_DIR.") endif() + +if(APPLE) + # We need to add the path to cudart to the linker using rpath, since the + # library name for the cuda libraries is prepended with @rpath. + get_filename_component(_cuda_path_to_npp "${CUDA_NPP_LIBRARIES}" PATH) + if(_cuda_path_to_npp) + list(APPEND CUDA_NPP_LIBRARIES -Wl,-rpath "-Wl,${_cuda_path_to_npp}") + endif() +endif() + +set(CUDA_NPP_FOUND TRUE) +set(CUDA_NPP_LIBRARY_ROOT_DIR_INTERNAL "${CUDA_NPP_LIBRARY_ROOT_DIR}" CACHE INTERNAL "This is the value of the last time CUDA_NPP_LIBRARY_ROOT_DIR was set successfully." FORCE) + diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index f5735e91ea..7dac2a56c9 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -7,4 +7,4 @@ add_subdirectory(c) add_subdirectory(cpp) add_subdirectory(swig_python) add_subdirectory(octave) -#add_subdirectory(gpu) +add_subdirectory(gpu) -- GitLab