diff --git a/CMakeLists.txt b/CMakeLists.txt index 68ff5e6c1..a97b77b7f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,6 +56,12 @@ ecbuild_add_option( FEATURE GEOTIFF CONDITION HAVE_CAIRO REQUIRED_PACKAGES GeoTIFF ) +ecbuild_add_option( FEATURE WEBP + DEFAULT OFF + DESCRIPTION "webp support [implies cairo]" + CONDITION HAVE_CAIRO + REQUIRED_PACKAGES WEBP ) + ecbuild_add_option( FEATURE NETCDF DEFAULT ON DESCRIPTION "enable netcdf support" @@ -274,6 +280,12 @@ if( HAVE_GEOTIFF ) list( APPEND MAGICS_EXTRA_DEFINITIONS HAVE_GEOTIFF ) endif() +if( HAVE_WEBP ) + list( APPEND MAGICS_EXTRA_INCLUDE_DIRS ${WEBP_INCLUDE_DIR} ) + list( APPEND MAGICS_EXTRA_LIBRARIES ${WEBP_LIBRARY} ) + list( APPEND MAGICS_EXTRA_DEFINITIONS HAVE_WEBP ) +endif() + list( APPEND MAGICS_EXTRA_LIBRARIES ${CMAKE_THREAD_LIBS_INIT} ) if( EC_OS_NAME MATCHES "windows" ) diff --git a/cmake/FindWebP.cmake b/cmake/FindWebP.cmake new file mode 100644 index 000000000..b22279e49 --- /dev/null +++ b/cmake/FindWebP.cmake @@ -0,0 +1,69 @@ +# (C) Copyright 2023- ECMWF. +# +# This software is licensed under the terms of the Apache Licence Version 2.0 +# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +# In applying this licence, ECMWF does not waive the privileges and immunities +# granted to it by virtue of its status as an intergovernmental organisation +# nor does it submit to any jurisdiction. + +# - Try to find the WebP includes and library +# This module defines +# +# WEBP_FOUND - System has WebP +# WEBP_INCLUDE_DIRS - the WebP include directories +# WEBP_LIBRARIES - the libraries needed to use WebP +# +# The following paths will be searched with priority if set in CMake or env +# +# WEBP_DIR - root folder of the WebP installation +# WEBP_PATH - root folder of the WebP installation +# +# Define WEBP_MIN_VERSION for which version desired. + +if( NOT WEBP_PATH ) + if ( NOT "$ENV{WEBP_PATH}" STREQUAL "" ) + set( WEBP_PATH "$ENV{WEBP_PATH}" ) + elseif ( NOT "$ENV{WEBP_DIR}" STREQUAL "" ) + set( WEBP_PATH "$ENV{WEBP_DIR}" ) + endif() +endif() + +if( NOT WEBP_PATH ) + + include(FindPkgConfig) + + if(WEBP_MIN_VERSION) + pkg_check_modules(PKWEBP ${_pkgconfig_REQUIRED} QUIET WEBP>=${WEBP_MIN_VERSION}) + else() + pkg_check_modules(PKWEBP ${_pkgconfig_REQUIRED} QUIET WEBP) + endif() + + if( PKG_CONFIG_FOUND AND PKWEBP_FOUND ) + + find_path(WEBP_INCLUDE_DIR encode.h HINTS ${PKWEBP_INCLUDEDIR} ${PKWEBP_INCLUDE_DIRS} PATH_SUFFIXES WEBP NO_DEFAULT_PATH ) + find_library(WEBP_LIBRARY webp HINTS ${PKWEBP_LIBDIR} ${PKWEBP_LIBRARY_DIRS} PATH_SUFFIXES WEBP NO_DEFAULT_PATH ) + + endif() + +endif() + +if( WEBP_PATH ) + + find_path(WEBP_INCLUDE_DIR NAMES encode.h PATHS ${WEBP_PATH} ${WEBP_PATH}/include PATH_SUFFIXES WEBP NO_DEFAULT_PATH ) + find_library(WEBP_LIBRARY NAMES webp PATHS ${WEBP_PATH} ${WEBP_PATH}/lib PATH_SUFFIXES WEBP NO_DEFAULT_PATH ) + +endif() + +find_path(WEBP_INCLUDE_DIR NAMES encode.h PATHS PATH_SUFFIXES WEBP ) +find_library( WEBP_LIBRARY NAMES webp PATHS PATH_SUFFIXES WEBP ) + + +# handle the QUIETLY and REQUIRED arguments and set GRIBAPI_FOUND +include(FindPackageHandleStandardArgs) +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} ) + +mark_as_advanced( WEBP_INCLUDE_DIR WEBP_LIBRARY )