1# - Find LCMS2
2# Find the LCMS2 includes and library
3# This module defines
4#  LCMS2_INCLUDE_DIR, where to find lcms.h
5#  LCMS2_LIBRARIES, the libraries needed to use LCMS2.
6#  LCMS2_VERSION, The value of LCMS_VERSION defined in lcms.h
7#  LCMS2_FOUND, If false, do not try to use LCMS2.
8
9
10# Copyright (c) 2008, Adrian Page, <adrian@pagenet.plus.com>
11# Copyright (c) 2009, Cyrille Berger, <cberger@cberger.net>
12#
13# Redistribution and use is allowed according to the terms of the BSD license.
14# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
15
16
17# use pkg-config to get the directories and then use these values
18# in the FIND_PATH() and FIND_LIBRARY() calls
19if(NOT WIN32)
20   find_package(PkgConfig)
21   pkg_check_modules(PC_LCMS2 lcms2)
22   set(LCMS2_DEFINITIONS ${PC_LCMS2_CFLAGS_OTHER})
23endif()
24
25find_path(LCMS2_INCLUDE_DIR lcms2.h
26   PATHS
27   ${PC_LCMS2_INCLUDEDIR}
28   ${PC_LCMS2_INCLUDE_DIRS}
29   PATH_SUFFIXES lcms2 liblcms2
30)
31
32find_library(LCMS2_LIBRARIES NAMES lcms2 liblcms2 lcms-2 liblcms-2
33   PATHS
34   ${PC_LCMS2_LIBDIR}
35   ${PC_LCMS2_LIBRARY_DIRS}
36   PATH_SUFFIXES lcms2
37)
38
39if(LCMS2_INCLUDE_DIR AND LCMS2_LIBRARIES)
40   set(LCMS2_FOUND TRUE)
41else()
42   set(LCMS2_FOUND FALSE)
43endif()
44
45if(LCMS2_FOUND)
46   file(READ ${LCMS2_INCLUDE_DIR}/lcms2.h LCMS2_VERSION_CONTENT)
47   string(REGEX MATCH "#define LCMS_VERSION[ ]*[0-9]*\n" LCMS2_VERSION_MATCH ${LCMS2_VERSION_CONTENT})
48   if(LCMS2_VERSION_MATCH)
49      string(REGEX REPLACE "#define LCMS_VERSION[ ]*([0-9]*)\n" "\\1" LCMS2_VERSION ${LCMS2_VERSION_MATCH})
50      if(NOT LCMS2_FIND_QUIETLY)
51         string(SUBSTRING ${LCMS2_VERSION} 0 1 LCMS2_MAJOR_VERSION)
52         string(SUBSTRING ${LCMS2_VERSION} 1 2 LCMS2_MINOR_VERSION)
53         message(STATUS "Found lcms version ${LCMS2_MAJOR_VERSION}.${LCMS2_MINOR_VERSION}, ${LCMS2_LIBRARIES}")
54      endif()
55   else()
56      if(NOT LCMS2_FIND_QUIETLY)
57         message(STATUS "Found lcms2 but failed to find version ${LCMS2_LIBRARIES}")
58      endif()
59      set(LCMS2_VERSION NOTFOUND)
60   endif()
61else()
62   if(NOT LCMS2_FIND_QUIETLY)
63      if(LCMS2_FIND_REQUIRED)
64         message(FATAL_ERROR "Required package lcms2 NOT found")
65      else()
66         message(STATUS "lcms2 NOT found")
67      endif()
68   endif()
69endif()
70
71mark_as_advanced(LCMS2_INCLUDE_DIR LCMS2_LIBRARIES LCMS2_VERSION)
72