mirror of
https://github.com/davisking/dlib.git
synced 2024-11-01 10:14:53 +08:00
Add test for libwebp at configure time (#2658)
This commit is contained in:
parent
9b8f5d88f8
commit
da2f45b2e5
@ -13,22 +13,40 @@
|
||||
|
||||
unset(WEBP_FOUND)
|
||||
|
||||
FIND_PATH(WEBP_INCLUDE_DIR NAMES webp/decode.h)
|
||||
find_path(WEBP_INCLUDE_DIR NAMES webp/decode.h)
|
||||
|
||||
if(NOT WEBP_INCLUDE_DIR)
|
||||
unset(WEBP_FOUND)
|
||||
else()
|
||||
MARK_AS_ADVANCED(WEBP_INCLUDE_DIR)
|
||||
mark_as_advanced(WEBP_INCLUDE_DIR)
|
||||
|
||||
# Look for the library.
|
||||
FIND_LIBRARY(WEBP_LIBRARY NAMES webp)
|
||||
MARK_AS_ADVANCED(WEBP_LIBRARY)
|
||||
find_library(WEBP_LIBRARY NAMES webp)
|
||||
mark_as_advanced(WEBP_LIBRARY)
|
||||
|
||||
# handle the QUIETLY and REQUIRED arguments and set WEBP_FOUND to TRUE if
|
||||
# all listed variables are TRUE
|
||||
INCLUDE(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(WebP DEFAULT_MSG WEBP_LIBRARY WEBP_INCLUDE_DIR)
|
||||
include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
|
||||
find_package_handle_standard_args(WebP DEFAULT_MSG WEBP_LIBRARY WEBP_INCLUDE_DIR)
|
||||
|
||||
SET(WEBP_LIBRARIES ${WEBP_LIBRARY})
|
||||
SET(WEBP_INCLUDE_DIRS ${WEBP_INCLUDE_DIR})
|
||||
set(WEBP_LIBRARIES ${WEBP_LIBRARY})
|
||||
set(WEBP_INCLUDE_DIRS ${WEBP_INCLUDE_DIR})
|
||||
endif()
|
||||
|
||||
if(WEBP_FOUND)
|
||||
set(WEBP_TEST_CMAKE_FLAGS
|
||||
"-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}"
|
||||
"-DCMAKE_INCLUDE_PATH=${CMAKE_INCLUDE_PATH}"
|
||||
"-DCMAKE_LIBRARY_PATH=${CMAKE_LIBRARY_PATH}")
|
||||
|
||||
try_compile(test_for_libwebp_worked
|
||||
${PROJECT_BINARY_DIR}/test_for_libwebp_build
|
||||
${CMAKE_CURRENT_LIST_DIR}/test_for_libwebp
|
||||
test_if_libwebp_is_broken
|
||||
CMAKE_FLAGS "${WEBP_TEST_CMAKE_FLAGS}")
|
||||
|
||||
if(NOT test_for_libwebp_worked)
|
||||
set(WEBP_FOUND 0)
|
||||
message (STATUS "System copy of libwebp is either too old or broken. Will disable WebP support.")
|
||||
endif()
|
||||
endif()
|
||||
|
7
dlib/cmake_utils/test_for_libwebp/CMakeLists.txt
Normal file
7
dlib/cmake_utils/test_for_libwebp/CMakeLists.txt
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
cmake_minimum_required(VERSION 3.8.0)
|
||||
project(test_if_libwebp_is_broken)
|
||||
|
||||
include_directories(${WEBP_INCLUDE_DIR})
|
||||
add_executable(libwebp_test libwebp_test.cpp)
|
||||
target_link_libraries(libwebp_test ${WEBP_LIBRARY})
|
22
dlib/cmake_utils/test_for_libwebp/libwebp_test.cpp
Normal file
22
dlib/cmake_utils/test_for_libwebp/libwebp_test.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright (C) 2019 Davis E. King (davis@dlib.net), Nils Labugt
|
||||
// License: Boost Software License See LICENSE.txt for the full license.
|
||||
|
||||
#include <webp/encode.h>
|
||||
#include <webp/decode.h>
|
||||
#include <iostream>
|
||||
|
||||
// This code doesn't really make a lot of sense. It's just calling all the libjpeg functions to make
|
||||
// sure they can be compiled and linked.
|
||||
int main()
|
||||
{
|
||||
std::cerr << "This program is just for build system testing. Don't actually run it." << std::endl;
|
||||
std::abort();
|
||||
|
||||
uint8_t* data;
|
||||
size_t output_size = 0;
|
||||
int width, height, stride;
|
||||
float quality;
|
||||
output_size = WebPEncodeRGB(data, width, height, stride, quality, &data);
|
||||
WebPDecodeRGBInto(data, output_size, data, output_size, stride);
|
||||
WebPFree(data);
|
||||
}
|
@ -6,9 +6,6 @@
|
||||
// only do anything with this file if DLIB_WEBP_SUPPORT is defined
|
||||
#ifdef DLIB_WEBP_SUPPORT
|
||||
|
||||
#include "../array2d.h"
|
||||
#include "../pixel.h"
|
||||
#include "../dir_nav.h"
|
||||
#include "webp_loader.h"
|
||||
|
||||
#include <webp/decode.h>
|
||||
|
Loading…
Reference in New Issue
Block a user