diff --git a/CMakeLists.txt b/CMakeLists.txt index b0391bc3c7..d979d38422 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -299,10 +299,6 @@ set(WITH_TBB OFF CACHE BOOL "Include TBB support") set(WITH_EIGEN2 ON CACHE BOOL "Include Eigen2 support") set(WITH_CUDA OFF CACHE BOOL "Include NVidia Cuda Runtime support") -if (WITH_CUDA) - set(WITH_NPP OFF CACHE BOOL "Include Nvidia NPP support") -endif() - if(WIN32) set(WITH_VIDEOINPUT ON CACHE BOOL "Enable VideoInput support") endif() @@ -677,73 +673,6 @@ if (WITH_CUDA) endif() endif() - -############################### NPP ################################ - -if (WITH_NPP) - set(NPP_PATH "" CACHE PATH "Path to NPP folder") - if (NOT ${NPP_PATH} STREQUAL "") - set(NPP_DEFAULT_INCLUDE_DIRS ${NPP_PATH}) - set(NPP_DEFAULT_INCLUDE_DIRS ${NPP_DEFAULT_INCLUDE_DIRS}common/npp/include/) - - #message(STATUS "NPP DEFAULT INCLUDE DIRS: ${NPP_DEFAULT_INCLUDE_DIRS}") - find_path(NPP_INCLUDE_DIR "npp.h" PATHS NPP_DEFAULT_INCLUDE_DIRS DOC "The path to NPP headers") - #message(STATUS "npp: ${NPP_INCLUDE_DIR}") - - if (NPP_INCLUDE_DIR) - - #message(STATUS "PROC: ${CMAKE_SYSTEM_PROCESSOR}") - - set(X86_64 0) - set(X86 0) - - if(${CMAKE_SYSTEM_PROCESSOR} MATCHES amd64*) - set(X86_64 1) - elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES x86_64*) - set(X86_64 1) - elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES i686*) - set(X86 1) - elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES i386*) - set(X86 1) - elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES x86*) - set(X86 1) - endif() - - message (STATUS "x86 : ${X86}") - message (STATUS "x64 : ${X86_64}") - - if (UNIX AND X86) - set(NPP_LIB npp32) - elseif(UNIX AND X86_64) - set(NPP_LIB npp64) - elseif(WIN32 AND x86) - set(NPP_LIB npp-mt) - elseif(WIN32 AND X86_64) - set(NPP_LIB npp-mt-x64) - elseif(APPLE AND x86) - set(NPP_LIB npp32.dynlib) - elseif(APPLE AND x86_64) - set(NPP_LIB npp64.dynlib) - endif() - - set(NPP_LIB_DIR "${NPP_INCLUDE_DIR}/../../lib" CACHE PATH "Full path of NPP library directory") - - link_directories("${NPP_LIB_DIR}") - else() - message(STATUS "Could NOT find npp.h") - endif() - - if(NOT "${NPP_INCLUDE_DIR}" STREQUAL "") - include_directories("${NPP_INCLUDE_DIR}") - set(HAVE_NPP 1) - endif() - endif() -endif() - - - - - ############################### VideoInput ################################ if (WIN32 AND WITH_VIDEOINPUT) diff --git a/modules/gpu/CMakeLists.txt b/modules/gpu/CMakeLists.txt index 3ab293cf06..ceacd908bd 100644 --- a/modules/gpu/CMakeLists.txt +++ b/modules/gpu/CMakeLists.txt @@ -33,13 +33,14 @@ file(GLOB lib_hdrs "include/opencv2/${name}/*.h*") source_group("Include" FILES ${lib_hdrs}) if (HAVE_CUDA) - include_directories(${CUDA_INCLUDE_DIRS}) - link_directories(${CUDA_LIBRARIES}) + set(NPP_FIND_REQUIRED 1) + include(FindNPP.cmake) + include_directories(${CUDA_INCLUDE_DIRS} ${CUDA_NPP_INCLUDES}) + if (UNIX OR APPLE) set (CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} "-Xcompiler;-fPIC;") #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" "-fPIC") - endif() #set (CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} "-keep") @@ -99,7 +100,7 @@ set_target_properties(${the_target} PROPERTIES ) # Add the required libraries for linking: -target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${IPP_LIBS} ${DEPS} ${CUDA_LIBRARIES} ${NPP_LIB}) +target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${IPP_LIBS} ${DEPS} ${CUDA_LIBRARIES} ${CUDA_NPP_LIBRARIES}) if(MSVC) if(CMAKE_CROSSCOMPILING) diff --git a/modules/gpu/FindNPP.cmake b/modules/gpu/FindNPP.cmake new file mode 100644 index 0000000000..c3f8be2112 --- /dev/null +++ b/modules/gpu/FindNPP.cmake @@ -0,0 +1,103 @@ +############################################################################### +# +# FindNPP.cmake +# +# CUDA_NPP_LIBRARY_ROOT_DIR -- Path to the NPP dorectory. +# CUDA_NPP_INCLUDES -- NPP Include directories. +# CUDA_NPP_LIBRARIES -- NPP libraries. +# +# Author: Anatoly Baksheev, Itseez Ltd. +# +# The MIT License +# +# License for the specific language governing rights and limitations under +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# +############################################################################### + +# We need to have at least this version to support the VERSION_LESS argument to 'if' (2.6.2) and unset (2.6.3) +cmake_policy(PUSH) +cmake_minimum_required(VERSION 2.6.3) +cmake_policy(POP) + +if(NOT "${CUDA_NPP_LIBRARY_ROOT_DIR}" STREQUAL "${CUDA_NPP_LIBRARY_ROOT_DIR_INTERNAL}") + unset(CUDA_NPP_INCLUDES CACHE) + unset(CUDA_NPP_LIBRARIES CACHE) +endif() + +if(${CMAKE_SIZEOF_VOID_P} EQUAL 4) + if (UNIX OR APPLE) + set(NPP_SUFFIX "32") + else() + set(NPP_SUFFIX "-mt") + endif() +elseif(${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) + +if(NOT CUDA_NPP_LIBRARY_ROOT_DIR) + find_path(CUDA_NPP_LIBRARY_ROOT_DIR common/npp/include/npp.h DOC "NPP root directory." NO_DEFAULT_PATH) +endif (NOT CUDA_NPP_LIBRARY_ROOT_DIR) + +# Search includes in our own paths. +find_path(CUDA_NPP_INCLUDES npp.h PATHS "${CUDA_NPP_LIBRARY_ROOT_DIR}/common/npp/include" NO_DEFAULT_PATH) +# Search default search paths, after we search our own set of paths. +find_path(CUDA_NPP_INCLUDES device_functions.h) +mark_as_advanced(CUDA_NPP_INCLUDES) + +# Find NPP library +find_library(CUDA_NPP_LIBRARIES + NAMES libnpp${NPP_SUFFIX} + PATHS "${CUDA_NPP_LIBRARY_ROOT_DIR}/common/lib" + DOC "NPP library" + NO_DEFAULT_PATH + ) +# Search default search paths, after we search our own set of paths. +find_library(CUDA_NPP_LIBRARIES NAMES libnpp${NPP_SUFFIX} DOC "NPP library") +mark_as_advanced(CUDA_NPP_LIBRARIES) + +if(NOT EXISTS ${CUDA_NPP_LIBRARIES} OR NOT EXISTS ${CUDA_NPP_INCLUDES}/npp.h) + 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 or CUDA_NPP_LIBRARY_ROOT_DIR not specified.") + endif() + + set(CUDA_FOUND FALSE) + unset(CUDA_NPP_INCLUDES CACHE) + unset(CUDA_NPP_LIBRARIES CACHE) +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) +endif() +