Add test for libwebp at configure time (#2658)

This commit is contained in:
Adrià Arrufat 2022-08-29 23:55:36 +09:00 committed by GitHub
parent 9b8f5d88f8
commit da2f45b2e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 55 additions and 11 deletions

View File

@ -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()

View 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})

View 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);
}

View File

@ -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>