1############################################################################
2# FindTurboJpeg.txt
3# Copyright (C) 2016  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 turbojpeg include file and library
24#
25#  TURBOJPEG_FOUND - system has turbojpeg
26#  TURBOJPEG_INCLUDE_DIRS - the turbojpeg include directory
27#  TURBOJPEG_LIBRARIES - The libraries needed to use turbojpeg
28
29find_path(TURBOJPEG_INCLUDE_DIRS
30	NAMES turbojpeg.h
31	PATH_SUFFIXES include
32)
33if(TURBOJPEG_INCLUDE_DIRS)
34	set(HAVE_TURBOJPEG_H 1)
35endif()
36
37find_library(TURBOJPEG_LIBRARIES
38	NAMES turbojpeg turbojpeg-static
39	PATH_SUFFIXES bin lib
40)
41
42if(TURBOJPEG_INCLUDE_DIRS AND TURBOJPEG_LIBRARIES AND NOT MSVC)
43	include(CheckCSourceCompiles)
44	include(CMakePushCheckState)
45
46	cmake_push_check_state(RESET)
47	list(APPEND CMAKE_REQUIRED_INCLUDES ${TURBOJPEG_INCLUDE_DIRS})
48	list(APPEND CMAKE_REQUIRED_LIBRARIES ${TURBOJPEG_LIBRARIES})
49	set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror")
50	check_c_source_compiles("
51#include <turbojpeg.h>
52int main(int argc, char *argv[]) {
53	tjhandle handle = 0;
54	const unsigned char *srcPlanes = 0;
55	const int *strides = 0;
56	unsigned char *jpegBuf = 0;
57	unsigned long jpegSize = 0;
58	int width = 0, height = 0, subsamp = 0, jpegQual = 0, flags = 0;
59	return tjCompressFromYUVPlanes(handle, &srcPlanes, width, strides, height, subsamp, &jpegBuf, &jpegSize, jpegQual, flags);
60}" TURBOJPEG_USE_CONST_BUFFERS)
61	cmake_pop_check_state()
62endif()
63
64include(FindPackageHandleStandardArgs)
65find_package_handle_standard_args(TurboJpeg
66	DEFAULT_MSG
67	TURBOJPEG_INCLUDE_DIRS TURBOJPEG_LIBRARIES
68)
69
70mark_as_advanced(TURBOJPEG_INCLUDE_DIRS TURBOJPEG_LIBRARIES TURBOJPEG_USE_CONST_BUFFERS)
71