Rewrites FindFreetype using LibFindMacros

coverity_scan^2
Roman Proskuryakov 9 years ago
parent 78bac93021
commit bd804d30a4

@ -8,62 +8,93 @@
#------------------------------------------------------------------- #-------------------------------------------------------------------
# - Try to find FreeType # - Try to find FreeType
#
# This module accepts the following env variable
# FREETYPE_SDK - Can be set to custom install path
#
# Once done, this will define # Once done, this will define
# #
# FREETYPE_FOUND - system has FreeType # Freetype_FOUND - system has FreeType
# FREETYPE_INCLUDE_DIRS - the FreeType include directories # Freetype_INCLUDE_DIRS - the FreeType include directories
# FREETYPE_LIBRARIES - link these to use FreeType # Freetype_LIBRARIES - link these to use FreeType
# Freetype_VERSION - version of FreeType
include(FindPkgMacros) #
findpkg_begin(FREETYPE) # libfreetype internals:
#
# ======================================
# new versions (2.5.2)
#
# file structure:
# <prefix>/include/freetype2/ft2build.h
# <prefix>/include/freetype2/freetype.h
# used as:
# #include <ft2build.h>
# #include <freetype.h>
# requires:
# -I <prefix>/include/freetype2/
#
# ======================================
# old versions (2.4.8, 2.3.5)
#
# file structure:
# <prefix>/include/ft2build.h
# <prefix>/include/freetype2/freetype/freetype.h
# used as:
# #include <ft2build.h>
# #include <freetype/freetype.h>
# requires:
# -I <prefix>/include/ -I <prefix>/include/freetype2/
#
# ======================================
# Get path, convert backslashes as ${ENV_${var}} include(LibFindMacros)
getenv_path(FREETYPE_HOME) include(PreprocessorUtils)
# construct search paths set(_REGULAR_INSTALL_PATHS
set(FREETYPE_PREFIX_PATH ${FREETYPE_HOME} ${ENV_FREETYPE_HOME}) /usr/X11R6
create_search_paths(FREETYPE) /usr/local/X11R6
# redo search if prefix path changed /usr/local/X11
clear_if_changed(FREETYPE_PREFIX_PATH /usr/freeware
FREETYPE_LIBRARY_FWK ENV GTKMM_BASEPATH
FREETYPE_LIBRARY_REL [HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path]
FREETYPE_LIBRARY_DBG [HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path]
FREETYPE_INCLUDE_DIR
) )
set(FREETYPE_LIBRARY_NAMES freetype2311 freetype239 freetype238 freetype235 freetype219 freetype) libfind_pkg_detect(Freetype freetype2
get_debug_names(FREETYPE_LIBRARY_NAMES) FIND_PATH ft2build.h
HINTS $ENV{FREETYPE_SDK}
use_pkgconfig(FREETYPE_PKGC freetype2) PATHS ${_REGULAR_INSTALL_PATHS}
PATH_SUFFIXES include freetype2
# prefer static library over framework FIND_LIBRARY freetype freetype2311 freetype239 freetype238 freetype235 freetype219
set(CMAKE_FIND_FRAMEWORK "LAST") HINTS $ENV{FREETYPE_SDK}
PATHS ${_REGULAR_INSTALL_PATHS}
message(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}") PATH_SUFFIXES lib
findpkg_framework(FREETYPE) )
message(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}") find_path(Freetype_OLD_INCLUDE_DIR
# in new versions of freetype old_include_dir equals to include_dir
find_path(FREETYPE_INCLUDE_DIR NAMES freetype/freetype.h HINTS ${FREETYPE_INC_SEARCH_PATH} ${FREETYPE_PKGC_INCLUDE_DIRS} PATH_SUFFIXES freetype2) # see explanation above
find_path(FREETYPE_FT2BUILD_INCLUDE_DIR NAMES ft2build.h HINTS ${FREETYPE_INC_SEARCH_PATH} ${FREETYPE_PKGC_INCLUDE_DIRS}) NAMES freetype/freetype.h freetype.h
PATHS ${Freetype_INCLUDE_DIR}
PATH_SUFFIXES freetype2
NO_DEFAULT_PATH
)
if (SYMBIAN) # get version from freetype.h
set(ORIGINAL_CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH}) find_file(Freetype_HEADER
set(CMAKE_PREFIX_PATH ${CMAKE_SYSYEM_OUT_DIR}) NAMES freetype.h
message(STATUS "Lib will be searched in Symbian out dir: ${CMAKE_SYSYEM_OUT_DIR}") PATH_SUFFIXES freetype
endif (SYMBIAN) PATHS ${Freetype_OLD_INCLUDE_DIR}
find_library(FREETYPE_LIBRARY_REL NAMES ${FREETYPE_LIBRARY_NAMES} HINTS ${FREETYPE_LIB_SEARCH_PATH} ${FREETYPE_PKGC_LIBRARY_DIRS} PATH_SUFFIXES "" release relwithdebinfo minsizerel) )
find_library(FREETYPE_LIBRARY_DBG NAMES ${FREETYPE_LIBRARY_NAMES_DBG} HINTS ${FREETYPE_LIB_SEARCH_PATH} ${FREETYPE_PKGC_LIBRARY_DIRS} PATH_SUFFIXES "" debug) if (Freetype_HEADER)
if (SYMBIAN) get_version_from_n_defines(Freetype_VERSION
set(CMAKE_PREFIX_PATH ${ORIGINAL_CMAKE_PREFIX_PATH}) ${Freetype_HEADER}
endif (SYMBIAN) FREETYPE_MAJOR FREETYPE_MINOR FREETYPE_PATCH
)
endif()
make_library_set(FREETYPE_LIBRARY) set(Freetype_PROCESS_INCLUDES Freetype_INCLUDE_DIR Freetype_OLD_INCLUDE_DIR)
libfind_process(Freetype)
findpkg_finish(FREETYPE) if (Freetype_INCLUDE_DIRS)
mark_as_advanced(FREETYPE_FT2BUILD_INCLUDE_DIR) list(REMOVE_DUPLICATES Freetype_INCLUDE_DIRS)
if (NOT FREETYPE_FT2BUILD_INCLUDE_DIR STREQUAL FREETYPE_INCLUDE_DIR)
set(FREETYPE_INCLUDE_DIRS ${FREETYPE_INCLUDE_DIRS} ${FREETYPE_FT2BUILD_INCLUDE_DIR})
endif() endif()
# Reset framework finding
set(CMAKE_FIND_FRAMEWORK "FIRST")

Loading…
Cancel
Save