From 49b69add60d6fcd56688e276c3a4010759dade05 Mon Sep 17 00:00:00 2001 From: Rolf Eike Beer Date: Wed, 25 Jan 2012 23:39:21 +0100 Subject: [PATCH] FindLua51: add version support --- Modules/FindLua51.cmake | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Modules/FindLua51.cmake b/Modules/FindLua51.cmake index 123fd5d05..b67dd4cec 100644 --- a/Modules/FindLua51.cmake +++ b/Modules/FindLua51.cmake @@ -2,7 +2,8 @@ # This module defines # LUA51_FOUND, if false, do not try to link to Lua # LUA_LIBRARIES -# LUA_INCLUDE_DIR, where to find lua.h +# LUA_INCLUDE_DIR, where to find lua.h +# LUA_VERSION_STRING, the version of Lua found (since CMake 2.8.8) # # Note that the expected include convention is # #include "lua.h" @@ -66,10 +67,19 @@ IF(LUA_LIBRARY) ENDIF(UNIX AND NOT APPLE) ENDIF(LUA_LIBRARY) +IF(LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/lua.h") + FILE(STRINGS "${LUA_INCLUDE_DIR}/lua.h" lua_version_str REGEX "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua .+\"") + + STRING(REGEX REPLACE "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua ([^\"]+)\".*" "\\1" LUA_VERSION_STRING "${lua_version_str}") + UNSET(lua_version_str) +ENDIF() + INCLUDE(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) # handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if # all listed variables are TRUE -FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua51 DEFAULT_MSG LUA_LIBRARIES LUA_INCLUDE_DIR) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua51 + REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR + VERSION_VAR LUA_VERSION_STRING) MARK_AS_ADVANCED(LUA_INCLUDE_DIR LUA_LIBRARIES LUA_LIBRARY LUA_MATH_LIBRARY)