go-libwebp

Experimental translation from libwebp to Go source.
Log | Files | Refs | README | LICENSE

deps.cmake (5169B)


      1 #  Copyright (c) 2021 Google LLC.
      2 #
      3 #  Use of this source code is governed by a BSD-style license
      4 #  that can be found in the LICENSE file in the root of the source
      5 #  tree. An additional intellectual property rights grant can be found
      6 #  in the file PATENTS.  All contributing project authors may
      7 #  be found in the AUTHORS file in the root of the source tree.
      8 
      9 # Generate the config.h to compile with specific intrinsics / libs.
     10 
     11 # Check for compiler options.
     12 include(CheckCSourceCompiles)
     13 check_c_source_compiles(
     14   "
     15     int main(void) {
     16       (void)__builtin_bswap16(0);
     17       return 0;
     18     }
     19   "
     20   HAVE_BUILTIN_BSWAP16)
     21 check_c_source_compiles(
     22   "
     23     int main(void) {
     24       (void)__builtin_bswap32(0);
     25       return 0;
     26     }
     27   "
     28   HAVE_BUILTIN_BSWAP32)
     29 check_c_source_compiles(
     30   "
     31     int main(void) {
     32       (void)__builtin_bswap64(0);
     33       return 0;
     34     }
     35   "
     36   HAVE_BUILTIN_BSWAP64)
     37 
     38 # Check for libraries.
     39 if(WEBP_USE_THREAD)
     40   find_package(Threads)
     41   if(Threads_FOUND)
     42     # work around cmake bug on QNX (https://cmake.org/Bug/view.php?id=11333)
     43     if(CMAKE_USE_PTHREADS_INIT AND NOT CMAKE_SYSTEM_NAME STREQUAL "QNX")
     44       set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread")
     45     endif()
     46     list(APPEND WEBP_DEP_LIBRARIES Threads::Threads)
     47   endif()
     48   set(WEBP_USE_THREAD ${Threads_FOUND})
     49 endif()
     50 
     51 # TODO: this seems unused, check with autotools.
     52 set(LT_OBJDIR ".libs/")
     53 
     54 # Only useful for vwebp, so useless for now.
     55 find_package(OpenGL)
     56 set(WEBP_HAVE_GL ${OPENGL_FOUND})
     57 
     58 # Check if we need to link to the C math library. We do not look for it as it is
     59 # not found when cross-compiling, while it is here.
     60 check_c_source_compiles(
     61   "
     62     #include <math.h>
     63     int main(int argc, char** argv) {
     64       return (int)pow(argc, 2.5);
     65     }
     66   "
     67   HAVE_MATH_LIBRARY)
     68 if(NOT HAVE_MATH_LIBRARY)
     69   message(STATUS "Adding -lm flag.")
     70   list(APPEND SHARPYUV_DEP_LIBRARIES m)
     71   list(APPEND WEBP_DEP_LIBRARIES m)
     72 endif()
     73 
     74 # Find the standard image libraries.
     75 set(WEBP_DEP_IMG_LIBRARIES)
     76 set(WEBP_DEP_IMG_INCLUDE_DIRS)
     77 if(WEBP_FIND_IMG_LIBS)
     78   foreach(I_LIB PNG JPEG TIFF)
     79     # Disable tiff when compiling in static mode as it is failing on Ubuntu.
     80     if(WEBP_LINK_STATIC AND ${I_LIB} STREQUAL "TIFF")
     81       message(STATUS "TIFF is disabled when statically linking.")
     82       continue()
     83     endif()
     84     find_package(${I_LIB})
     85     set(WEBP_HAVE_${I_LIB} ${${I_LIB}_FOUND})
     86     if(${I_LIB}_FOUND)
     87       list(APPEND WEBP_DEP_IMG_LIBRARIES ${${I_LIB}_LIBRARIES})
     88       list(APPEND WEBP_DEP_IMG_INCLUDE_DIRS ${${I_LIB}_INCLUDE_DIR}
     89            ${${I_LIB}_INCLUDE_DIRS})
     90     endif()
     91   endforeach()
     92   if(WEBP_DEP_IMG_INCLUDE_DIRS)
     93     list(REMOVE_DUPLICATES WEBP_DEP_IMG_INCLUDE_DIRS)
     94   endif()
     95 
     96   # GIF detection, gifdec isn't part of the imageio lib.
     97   include(CMakePushCheckState)
     98   set(WEBP_DEP_GIF_LIBRARIES)
     99   set(WEBP_DEP_GIF_INCLUDE_DIRS)
    100   find_package(GIF)
    101   set(WEBP_HAVE_GIF ${GIF_FOUND})
    102   if(GIF_FOUND)
    103     # GIF find_package only locates the header and library, it doesn't fail
    104     # compile tests when detecting the version, but falls back to 3 (as of at
    105     # least cmake 3.7.2). Make sure the library links to avoid incorrect
    106     # detection when cross compiling.
    107     cmake_push_check_state()
    108     set(CMAKE_REQUIRED_LIBRARIES ${GIF_LIBRARIES})
    109     set(CMAKE_REQUIRED_INCLUDES ${GIF_INCLUDE_DIR})
    110     check_c_source_compiles(
    111       "
    112       #include <gif_lib.h>
    113       int main(void) {
    114         (void)DGifOpenFileHandle;
    115         return 0;
    116       }
    117       "
    118       GIF_COMPILES)
    119     cmake_pop_check_state()
    120     if(GIF_COMPILES)
    121       list(APPEND WEBP_DEP_GIF_LIBRARIES ${GIF_LIBRARIES})
    122       list(APPEND WEBP_DEP_GIF_INCLUDE_DIRS ${GIF_INCLUDE_DIR})
    123     else()
    124       unset(GIF_FOUND)
    125     endif()
    126   endif()
    127 endif()
    128 
    129 # Check for specific headers.
    130 include(CheckIncludeFiles)
    131 check_include_files(GLUT/glut.h HAVE_GLUT_GLUT_H)
    132 check_include_files(GL/glut.h HAVE_GL_GLUT_H)
    133 check_include_files(OpenGL/glut.h HAVE_OPENGL_GLUT_H)
    134 check_include_files(shlwapi.h HAVE_SHLWAPI_H)
    135 check_include_files(unistd.h HAVE_UNISTD_H)
    136 check_include_files(wincodec.h HAVE_WINCODEC_H)
    137 check_include_files(windows.h HAVE_WINDOWS_H)
    138 
    139 # Windows specifics
    140 if(HAVE_WINCODEC_H)
    141   list(APPEND WEBP_DEP_LIBRARIES shlwapi ole32 windowscodecs)
    142 endif()
    143 
    144 # Check for SIMD extensions.
    145 include(${CMAKE_CURRENT_LIST_DIR}/cpu.cmake)
    146 
    147 # Define extra info.
    148 set(PACKAGE ${PROJECT_NAME})
    149 set(PACKAGE_NAME ${PROJECT_NAME})
    150 
    151 # Read from configure.ac.
    152 file(READ ${CMAKE_CURRENT_SOURCE_DIR}/configure.ac CONFIGURE_AC)
    153 string(REGEX MATCHALL "\\[([0-9a-z\\.:/]*)\\]" CONFIGURE_AC_PACKAGE_INFO
    154              ${CONFIGURE_AC})
    155 function(strip_bracket VAR)
    156   string(LENGTH ${${VAR}} TMP_LEN)
    157   math(EXPR TMP_LEN ${TMP_LEN}-2)
    158   string(SUBSTRING ${${VAR}} 1 ${TMP_LEN} TMP_SUB)
    159   set(${VAR} ${TMP_SUB} PARENT_SCOPE)
    160 endfunction()
    161 
    162 list(GET CONFIGURE_AC_PACKAGE_INFO 1 PACKAGE_VERSION)
    163 strip_bracket(PACKAGE_VERSION)
    164 list(GET CONFIGURE_AC_PACKAGE_INFO 2 PACKAGE_BUGREPORT)
    165 strip_bracket(PACKAGE_BUGREPORT)
    166 list(GET CONFIGURE_AC_PACKAGE_INFO 3 PACKAGE_URL)
    167 strip_bracket(PACKAGE_URL)
    168 
    169 # Build more info.
    170 set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
    171 set(PACKAGE_TARNAME ${PACKAGE_NAME})
    172 set(VERSION ${PACKAGE_VERSION})