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