FindSDL: Add version support for FindSDL_ttf

This commit is contained in:
Benjamin Eikel 2012-09-04 16:11:10 +02:00 committed by Brad King
parent a28c24726b
commit 4541c07864
1 changed files with 18 additions and 1 deletions

View File

@ -58,13 +58,30 @@ find_library(SDL_TTF_LIBRARY
PATH_SUFFIXES lib
)
if(SDL_TTF_INCLUDE_DIR AND EXISTS "${SDL_TTF_INCLUDE_DIR}/SDL_ttf.h")
file(STRINGS "${SDL_TTF_INCLUDE_DIR}/SDL_ttf.h" SDL_TTF_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_TTF_MAJOR_VERSION[ \t]+[0-9]+$")
file(STRINGS "${SDL_TTF_INCLUDE_DIR}/SDL_ttf.h" SDL_TTF_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_TTF_MINOR_VERSION[ \t]+[0-9]+$")
file(STRINGS "${SDL_TTF_INCLUDE_DIR}/SDL_ttf.h" SDL_TTF_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_TTF_PATCHLEVEL[ \t]+[0-9]+$")
string(REGEX REPLACE "^#define[ \t]+SDL_TTF_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_TTF_VERSION_MAJOR "${SDL_TTF_VERSION_MAJOR_LINE}")
string(REGEX REPLACE "^#define[ \t]+SDL_TTF_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_TTF_VERSION_MINOR "${SDL_TTF_VERSION_MINOR_LINE}")
string(REGEX REPLACE "^#define[ \t]+SDL_TTF_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL_TTF_VERSION_PATCH "${SDL_TTF_VERSION_PATCH_LINE}")
set(SDL_TTF_VERSION_STRING ${SDL_TTF_VERSION_MAJOR}.${SDL_TTF_VERSION_MINOR}.${SDL_TTF_VERSION_PATCH})
unset(SDL_TTF_VERSION_MAJOR_LINE)
unset(SDL_TTF_VERSION_MINOR_LINE)
unset(SDL_TTF_VERSION_PATCH_LINE)
unset(SDL_TTF_VERSION_MAJOR)
unset(SDL_TTF_VERSION_MINOR)
unset(SDL_TTF_VERSION_PATCH)
endif()
set(SDL_TTF_LIBRARIES ${SDL_TTF_LIBRARY})
set(SDL_TTF_INCLUDE_DIRS ${SDL_TTF_INCLUDE_DIR})
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL_ttf
REQUIRED_VARS SDL_TTF_LIBRARIES SDL_TTF_INCLUDE_DIRS)
REQUIRED_VARS SDL_TTF_LIBRARIES SDL_TTF_INCLUDE_DIRS
VERSION_VAR SDL_TTF_VERSION_STRING)
# for backward compatiblity
set(SDLTTF_LIBRARY ${SDL_TTF_LIBRARIES})