1############################################################################
2# FindXv.txt
3# Copyright (C) 2014  Belledonne Communications, Grenoble France
4#
5############################################################################
6#
7# This program is free software; you can redistribute it and/or
8# modify it under the terms of the GNU General Public License
9# as published by the Free Software Foundation; either version 2
10# of the License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
19# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20#
21############################################################################
22#
23# - Find the Xv include file and library
24#
25#  XV_FOUND - system has Xv
26#  XV_INCLUDE_DIRS - the Xv include directory
27#  XV_LIBRARIES - The libraries needed to use Xv
28
29include(CheckIncludeFile)
30include(CheckSymbolExists)
31
32find_package(X11 REQUIRED)
33
34set(_XV_ROOT_PATHS
35	${CMAKE_INSTALL_PREFIX}
36)
37
38find_path(XV_H_INCLUDE_DIR
39	NAMES X11/extensions/Xv.h
40	HINTS _XV_ROOT_PATHS
41	PATH_SUFFIXES include
42)
43find_path(XVLIB_H_INCLUDE_DIR
44	NAMES X11/extensions/Xvlib.h
45	HINTS _XV_ROOT_PATHS
46	PATH_SUFFIXES include
47)
48if(XV_H_INCLUDE_DIR)
49	set(HAVE_X11_EXTENSIONS_XV_H 1)
50endif()
51if(XVLIB_H_INCLUDE_DIR)
52	set(HAVE_X11_EXTENSIONS_XVLIB_H 1)
53endif()
54if(XV_H_INCLUDE_DIR AND XVLIB_H_INCLUDE_DIR)
55	set(XV_INCLUDE_DIRS ${XV_H_INCLUDE_DIR} ${XVLIB_H_INCLUDE_DIR})
56endif()
57
58set(XV_INCLUDE_DIRS ${XV_INCLUDE_DIRS} ${X11_INCLUDE_DIRS})
59list(REMOVE_DUPLICATES XV_INCLUDE_DIRS)
60
61find_library(XV_LIBRARIES
62	NAMES Xv
63	HINTS _XV_ROOT_PATHS
64	PATH_SUFFIXES bin lib
65)
66
67if(XV_LIBRARIES)
68	cmake_push_check_state(RESET)
69	list(APPEND CMAKE_REQUIRED_INCLUDES ${XV_INCLUDE_DIRS})
70	list(APPEND CMAKE_REQUIRED_LIBRARIES ${XV_LIBRARIES})
71	check_symbol_exists(XvCreateImage "X11/Xlib.h;X11/extensions/Xv.h;X11/extensions/Xvlib.h" HAVE_XV_CREATE_IMAGE)
72	cmake_pop_check_state()
73endif()
74
75set(XV_LIBRARIES ${XV_LIBRARIES} ${X11_LIBRARIES})
76list(REMOVE_DUPLICATES XV_LIBRARIES)
77
78include(FindPackageHandleStandardArgs)
79find_package_handle_standard_args(Xv
80	DEFAULT_MSG
81	XV_INCLUDE_DIRS HAVE_X11_EXTENSIONS_XV_H HAVE_X11_EXTENSIONS_XVLIB_H XV_LIBRARIES HAVE_XV_CREATE_IMAGE
82)
83
84mark_as_advanced(XV_INCLUDE_DIRS HAVE_X11_EXTENSIONS_XV_H HAVE_X11_EXTENSIONS_XVLIB_H XV_LIBRARIES HAVE_XV_CREATE_IMAGE)
85