Code

Cmake: Find Dependencies rebuilt
[inkscape.git] / CMakeScripts / FindFreetype2.cmake
1 # - Try to find FREETYPE2
2 # Once done this will define
3 #
4 #  FREETYPE2_FOUND - system has FREETYPE2
5 #  FREETYPE2_INCLUDE_DIRS - the FREETYPE2 include directory
6 #  FREETYPE2_LIBRARIES - Link these to use FREETYPE2
7 #  FREETYPE2_DEFINITIONS - Compiler switches required for using FREETYPE2
8 #
9 #  Copyright (c) 2008 Joshua L. Blocher <verbalshadow@gmail.com>
10 #
11 #  Redistribution and use is allowed according to the terms of the New
12 #  BSD license.
13 #  For details see the accompanying COPYING-CMAKE-SCRIPTS file.
14 #
17 if (FREETYPE2_LIBRARIES AND FREETYPE2_INCLUDE_DIRS)
18   # in cache already
19   set(FREETYPE2_FOUND TRUE)
20 else (FREETYPE2_LIBRARIES AND FREETYPE2_INCLUDE_DIRS)
21   # use pkg-config to get the directories and then use these values
22   # in the FIND_PATH() and FIND_LIBRARY() calls
23   if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
24     include(UsePkgConfig)
25     pkgconfig(freetype2 _FREETYPE2_INCLUDEDIR _FREETYPE2_LIBDIR _FREETYPE2_LDFLAGS _FREETYPE2_CFLAGS)
26   else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
27     find_package(PkgConfig)
28     if (PKG_CONFIG_FOUND)
29       pkg_check_modules(_FREETYPE2 freetype2)
30     endif (PKG_CONFIG_FOUND)
31   endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
32   find_path(FREETYPE2_INCLUDE_DIR
33     NAMES
34       freetype/freetype.h
35     PATHS
36       ${_FREETYPE2_INCLUDEDIR}
37       /usr/include
38       /usr/local/include
39       /opt/local/include
40       /sw/include
41     PATH_SUFFIXES
42       freetype2
43   )
45   find_library(FREETYPE_LIBRARY
46     NAMES
47       freetype
48     PATHS
49       ${_FREETYPE2_LIBDIR}
50       /usr/lib
51       /usr/local/lib
52       /opt/local/lib
53       /sw/lib
54   )
56   if (FREETYPE_LIBRARY)
57     set(FREETYPE_FOUND TRUE)
58   endif (FREETYPE_LIBRARY)
60   set(FREETYPE2_INCLUDE_DIRS
61     ${FREETYPE2_INCLUDE_DIR}
62   )
64   if (FREETYPE_FOUND)
65     set(FREETYPE2_LIBRARIES
66       ${FREETYPE2_LIBRARIES}
67       ${FREETYPE_LIBRARY}
68     )
69   endif (FREETYPE_FOUND)
71   if (FREETYPE2_INCLUDE_DIRS AND FREETYPE2_LIBRARIES)
72      set(FREETYPE2_FOUND TRUE)
73   endif (FREETYPE2_INCLUDE_DIRS AND FREETYPE2_LIBRARIES)
75   if (FREETYPE2_FOUND)
76     if (NOT FREETYPE2_FIND_QUIETLY)
77       message(STATUS "Found FREETYPE2: ${FREETYPE2_LIBRARIES}")
78     endif (NOT FREETYPE2_FIND_QUIETLY)
79   else (FREETYPE2_FOUND)
80     if (FREETYPE2_FIND_REQUIRED)
81       message(FATAL_ERROR "Could not find FREETYPE2")
82     endif (FREETYPE2_FIND_REQUIRED)
83   endif (FREETYPE2_FOUND)
85   # show the FREETYPE2_INCLUDE_DIRS and FREETYPE2_LIBRARIES variables only in the advanced view
86   mark_as_advanced(FREETYPE2_INCLUDE_DIRS FREETYPE2_LIBRARIES)
88 endif (FREETYPE2_LIBRARIES AND FREETYPE2_INCLUDE_DIRS)