FindFreetype.cmake 4.81 KB
Newer Older
1 2 3 4 5 6
#.rst:
# FindFreetype
# ------------
#
# Locate FreeType library
#
7
# This module defines
8
#
9 10 11 12 13 14 15 16 17 18 19 20 21 22
# ::
#
#   FREETYPE_LIBRARIES, the library to link against
#   FREETYPE_FOUND, if false, do not try to link to FREETYPE
#   FREETYPE_INCLUDE_DIRS, where to find headers.
#   FREETYPE_VERSION_STRING, the version of freetype found (since CMake 2.8.8)
#   This is the concatenation of the paths:
#   FREETYPE_INCLUDE_DIR_ft2build
#   FREETYPE_INCLUDE_DIR_freetype2
#
#
#
# $FREETYPE_DIR is an environment variable that would correspond to the
# ./configure --prefix=$FREETYPE_DIR used in building FREETYPE.
23

24 25 26 27 28 29 30 31 32 33
#=============================================================================
# Copyright 2007-2009 Kitware, Inc.
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
34
# (To distribute this file outside of CMake, substitute the full
35 36
#  License text for the above reference.)

37
# Created by Eric Wing.
38 39 40
# Modifications by Alexander Neundorf.
# This file has been renamed to "FindFreetype.cmake" instead of the correct
# "FindFreeType.cmake" in order to be compatible with the one from KDE4, Alex.
41

42
# Ugh, FreeType seems to use some #include trickery which
43 44
# makes this harder than it should be. It looks like they
# put ft2build.h in a common/easier-to-find location which
45
# then contains a #include to a more specific header in a
46
# more specific location (#include <freetype/config/ftheader.h>).
47
# Then from there, they need to set a bunch of #define's
48 49
# so you can do something like:
# #include FT_FREETYPE_H
50
# Unfortunately, using CMake's mechanisms like include_directories()
51
# wants explicit full paths and this trickery doesn't work too well.
52
# I'm going to attempt to cut out the middleman and hope
53
# everything still works.
54 55 56
find_path(
  FREETYPE_INCLUDE_DIR_ft2build
  ft2build.h
57
  HINTS
58
    ENV FREETYPE_DIR
59
  PATHS
60
    /usr/X11R6
61 62 63
    /usr/local/X11R6
    /usr/local/X11
    /usr/freeware
64 65 66
    ENV GTKMM_BASEPATH
    [HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path]
    [HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path]
67 68 69 70
  PATH_SUFFIXES
    include/freetype2
    include
    freetype2
71 72
)

73 74
find_path(
  FREETYPE_INCLUDE_DIR_freetype2
75 76 77
  NAMES
    freetype/config/ftheader.h
    config/ftheader.h
78
  HINTS
79
    ENV FREETYPE_DIR
80
  PATHS
81
    /usr/X11R6
82 83 84
    /usr/local/X11R6
    /usr/local/X11
    /usr/freeware
85 86 87
    ENV GTKMM_BASEPATH
    [HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path]
    [HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path]
88 89 90 91
  PATH_SUFFIXES
    include/freetype2
    include
    freetype2
92 93
)

94
find_library(FREETYPE_LIBRARY
95 96 97 98
  NAMES
    freetype
    libfreetype
    freetype219
99
  HINTS
100
    ENV FREETYPE_DIR
101
  PATHS
102 103 104 105 106 107 108
    /usr/X11R6
    /usr/local/X11R6
    /usr/local/X11
    /usr/freeware
    ENV GTKMM_BASEPATH
    [HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path]
    [HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path]
109 110
  PATH_SUFFIXES
    lib
111 112
)

113
# set the user variables
114 115
if(FREETYPE_INCLUDE_DIR_ft2build AND FREETYPE_INCLUDE_DIR_freetype2)
  set(FREETYPE_INCLUDE_DIRS "${FREETYPE_INCLUDE_DIR_ft2build};${FREETYPE_INCLUDE_DIR_freetype2}")
116
  list(REMOVE_DUPLICATES FREETYPE_INCLUDE_DIRS)
117
endif()
118
set(FREETYPE_LIBRARIES "${FREETYPE_LIBRARY}")
119

120 121 122 123 124 125 126
if(EXISTS "${FREETYPE_INCLUDE_DIR_freetype2}/freetype/freetype.h")
  set(FREETYPE_H "${FREETYPE_INCLUDE_DIR_freetype2}/freetype/freetype.h")
elseif(EXISTS "${FREETYPE_INCLUDE_DIR_freetype2}/freetype.h")
  set(FREETYPE_H "${FREETYPE_INCLUDE_DIR_freetype2}/freetype.h")
endif()

if(FREETYPE_INCLUDE_DIR_freetype2 AND FREETYPE_H)
127 128
  file(STRINGS "${FREETYPE_H}" freetype_version_str
       REGEX "^#[\t ]*define[\t ]+FREETYPE_(MAJOR|MINOR|PATCH)[\t ]+[0-9]+$")
129

130 131 132 133 134 135 136 137 138 139 140 141
  unset(FREETYPE_VERSION_STRING)
  foreach(VPART MAJOR MINOR PATCH)
    foreach(VLINE ${freetype_version_str})
      if(VLINE MATCHES "^#[\t ]*define[\t ]+FREETYPE_${VPART}[\t ]+([0-9]+)$")
        set(FREETYPE_VERSION_PART "${CMAKE_MATCH_1}")
        if(FREETYPE_VERSION_STRING)
          set(FREETYPE_VERSION_STRING "${FREETYPE_VERSION_STRING}.${FREETYPE_VERSION_PART}")
        else()
          set(FREETYPE_VERSION_STRING "${FREETYPE_VERSION_PART}")
        endif()
        unset(FREETYPE_VERSION_PART)
      endif()
142
    endforeach()
143
  endforeach()
144
endif()
145 146


147
# handle the QUIETLY and REQUIRED arguments and set FREETYPE_FOUND to TRUE if
148
# all listed variables are TRUE
149
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
150 151

find_package_handle_standard_args(
152 153 154 155 156 157 158
  Freetype
  REQUIRED_VARS
    FREETYPE_LIBRARY
    FREETYPE_INCLUDE_DIRS
  VERSION_VAR
    FREETYPE_VERSION_STRING
)
159

160 161 162 163 164
mark_as_advanced(
  FREETYPE_LIBRARY
  FREETYPE_INCLUDE_DIR_freetype2
  FREETYPE_INCLUDE_DIR_ft2build
)