1#
2# Find the GMIC includes and library
3#
4
5# This module defines
6# GMIC_INCLUDE_DIR, where to find *.h etc
7# GMIC_LIBRARY, the libraries
8# GMIC_FOUND, If false, do not try to use GMIC.
9
10set(GMIC_VERSION_NEEDED 270)
11set(GMIC_DEPENDENCIES_FOUND TRUE)
12
13include(LibFindMacros)
14
15# Use pkg-config to get hints about paths
16libfind_pkg_check_modules(GMIC_PKGCONF GMIC)
17
18# Include dir
19find_path(GMIC_INCLUDE_DIR
20  NAMES gmic.h
21  HINTS ${GMIC_PKGCONF_INCLUDE_DIRS}
22  PATH_SUFFIXES GMIC
23)
24
25# Finally the library itself
26find_library(GMIC_LIBRARY
27  NAMES gmic
28  HINTS ${GMIC_PKGCONF_LIBRARY_DIRS}
29)
30
31if(GMIC_LIBRARY AND GMIC_INCLUDE_DIR)
32  set(CMAKE_REQUIRED_INCLUDES ${GMIC_INCLUDE_DIR})
33  check_cxx_source_compiles("
34  #include <gmic.h>
35  #if gmic_version < ${GMIC_VERSION_NEEDED} || gmic_version >= 1000
36  #error OLD_VERSION
37  #endif
38  int main() { return 0; }
39  " GMIC_VERSION_OK)
40
41  if(NOT GMIC_VERSION_OK)
42    message(STATUS "Found GMIC but version < ${GMIC_VERSION_NEEDED}. Compressed lut will not be available")
43  else()
44    if(WIN32)
45      find_library(FFTW_LIBRARY NAMES fftw3)
46      if(NOT FFTW_LIBRARY)
47        message(STATUS "missing GMIC dependency fftw3")
48      else()
49        list(APPEND GMIC_LIBRARY ${FFTW_LIBRARY})
50      endif(NOT FFTW_LIBRARY)
51      # workaround for msys2 gmic 2.9.0-3. Should be reviewed when gmic 2.9.3 is available
52      find_library(OPENCV_CORE_LIBRARY NAMES libopencv_core)
53      find_library(OPENCV_VIDEOIO_LIBRARY NAMES libopencv_videoio)
54      if(NOT OPENCV_CORE_LIBRARY OR NOT OPENCV_VIDEOIO_LIBRARY)
55        message(STATUS "missing GMIC dependencies OpenCV")
56        set(GMIC_DEPENDENCIES_FOUND FALSE)
57      else()
58        list(APPEND GMIC_LIBRARY ${OPENCV_CORE_LIBRARY})
59        list(APPEND GMIC_LIBRARY ${OPENCV_VIDEOIO_LIBRARY})
60      endif(NOT OPENCV_CORE_LIBRARY OR NOT OPENCV_VIDEOIO_LIBRARY)
61    endif(WIN32)
62
63    # workaround for msys2 gmic 2.9.0-3. Should be reviewed when gmic 2.9.3 is available
64    if(GMIC_DEPENDENCIES_FOUND)
65
66      # Set the include dir variables and the libraries and let libfind_process do the rest.
67      # NOTE: Singular variables for this library, plural for libraries this lib depends on.
68      set(GMIC_PROCESS_INCLUDES ${GMIC_INCLUDE_DIR})
69      set(GMIC_PROCESS_LIBS ${GMIC_LIBRARY})
70      libfind_process(GMIC)
71
72      if(GMIC_FOUND)
73        set(GMIC_INCLUDE_DIRS ${GMIC_INCLUDE_DIR})
74        set(GMIC_LIBRARIES ${GMIC_LIBRARY})
75      else()
76        message(STATUS "GMIC not found")
77      endif(GMIC_FOUND)
78
79    else()
80      message(STATUS "GMIC dependencies not found")
81    endif(GMIC_DEPENDENCIES_FOUND)
82
83  endif(NOT GMIC_VERSION_OK)
84else()
85  message(STATUS "GMIC not found")
86endif(GMIC_LIBRARY AND GMIC_INCLUDE_DIR)
87