2010-09-12 23:17:37 +08:00
###############################################################################
#
# FindNPP.cmake
#
# CUDA_NPP_LIBRARY_ROOT_DIR -- Path to the NPP dorectory.
# CUDA_NPP_INCLUDES -- NPP Include directories.
# CUDA_NPP_LIBRARIES -- NPP libraries.
2010-11-25 02:44:11 +08:00
# NPP_VERSION -- NPP version in format "major.minor.build".
#
2010-11-27 01:24:12 +08:00
# If not found automatically, please set CUDA_NPP_LIBRARY_ROOT_DIR
# in CMake or set enviroment varivabe $CUDA_NPP_ROOT
2010-09-12 23:17:37 +08:00
#
# 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.
#
###############################################################################
cmake_policy ( PUSH )
2010-11-28 19:12:35 +08:00
cmake_minimum_required ( VERSION 2.8.0 )
2010-09-12 23:17:37 +08:00
cmake_policy ( POP )
if ( NOT "${CUDA_NPP_LIBRARY_ROOT_DIR}" STREQUAL "${CUDA_NPP_LIBRARY_ROOT_DIR_INTERNAL}" )
2010-11-27 01:24:12 +08:00
unset ( CUDA_NPP_INCLUDES CACHE )
unset ( CUDA_NPP_LIBRARIES CACHE )
2010-09-12 23:17:37 +08:00
endif ( )
2010-11-27 01:24:12 +08:00
2010-11-25 02:44:11 +08:00
if ( CMAKE_SIZEOF_VOID_P EQUAL 4 )
2010-11-27 01:24:12 +08:00
if ( UNIX OR APPLE )
set ( NPP_SUFFIX "32" )
else ( )
set ( NPP_SUFFIX "-mt" )
endif ( )
2010-11-25 02:44:11 +08:00
else ( CMAKE_SIZEOF_VOID_P EQUAL 4 )
2010-11-27 01:24:12 +08:00
if ( UNIX OR APPLE )
set ( NPP_SUFFIX "64" )
else ( )
set ( NPP_SUFFIX "-mt-x64" )
endif ( )
2010-11-25 02:44:11 +08:00
endif ( CMAKE_SIZEOF_VOID_P EQUAL 4 )
2010-09-12 23:17:37 +08:00
2010-11-25 02:44:11 +08:00
if ( NOT CUDA_NPP_LIBRARY_ROOT_DIR OR CUDA_NPP_LIBRARY_ROOT_DIR STREQUAL "" )
2010-11-27 01:24:12 +08:00
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." )
MESSAGE ( STATUS "NPP root directory: " ${ CUDA_NPP_LIBRARY_ROOT_DIR } )
2010-11-25 02:44:11 +08:00
endif ( )
2010-09-12 23:17:37 +08:00
# Search includes in our own paths.
2010-09-24 20:01:26 +08:00
find_path ( CUDA_NPP_INCLUDES npp.h PATHS "${CUDA_NPP_LIBRARY_ROOT_DIR}/common/npp/include" )
2010-09-12 23:17:37 +08:00
# Search default search paths, after we search our own set of paths.
find_path ( CUDA_NPP_INCLUDES device_functions.h )
2010-11-27 01:24:12 +08:00
mark_as_advanced ( CUDA_NPP_INCLUDES )
2010-09-12 23:17:37 +08:00
# Find NPP library
find_library ( CUDA_NPP_LIBRARIES
2010-11-27 01:24:12 +08:00
N A M E S " n p p " " n p p $ { N P P _ S U F F I X } " " l i b n p p $ { N P P _ S U F F I X } "
P A T H S " $ { C U D A _ N P P _ L I B R A R Y _ R O O T _ D I R } "
P A T H _ S U F F I X E S " c o m m o n / l i b " " c o m m o n / n p p / l i b "
D O C " N P P l i b r a r y "
)
2010-09-12 23:17:37 +08:00
2010-09-13 15:40:34 +08:00
# 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" )
2010-11-25 02:44:11 +08:00
mark_as_advanced ( CUDA_NPP_LIBRARIES )
if ( EXISTS ${ CUDA_NPP_INCLUDES } /nppversion.h )
2010-11-27 01:24:12 +08:00
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}" )
2010-11-25 02:44:11 +08:00
endif ( )
2010-11-25 18:42:09 +08:00
2010-09-14 16:58:39 +08:00
if ( NOT EXISTS ${ CUDA_NPP_LIBRARIES } OR NOT EXISTS ${ CUDA_NPP_INCLUDES } /npp.h )
2010-11-27 01:24:12 +08:00
set ( CUDA_NPP_FOUND FALSE )
message ( FATAL_ERROR "NPP headers/libraries are not found. Please specify CUDA_NPP_LIBRARY_ROOT_DIR in CMake or set $NPP_ROOT_DIR." )
2010-09-12 23:17:37 +08:00
endif ( )
2010-11-25 18:42:09 +08:00
include ( FindPackageHandleStandardArgs )
find_package_handle_standard_args ( NPP
2010-11-27 01:24:12 +08:00
R E Q U I R E D _ V A R S
C U D A _ N P P _ I N C L U D E S
C U D A _ N P P _ L I B R A R I E S
2010-11-28 19:12:35 +08:00
#Need cmake 2.8.3 to uncomment this.
#VERSION_VAR
2010-11-27 01:24:12 +08:00
N P P _ V E R S I O N )
2010-11-25 18:42:09 +08:00
2010-11-25 02:44:11 +08:00
if ( APPLE )
2010-11-27 01:24:12 +08:00
# 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 ( )
2010-11-25 18:42:09 +08:00
endif ( )
2010-11-25 02:44:11 +08:00
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 )
2010-09-12 23:17:37 +08:00