# Find the Lua-52 library

FIND_PATH(LUA_INCLUDE_DIR
  NAMES lua.h
  PATHS
  /usr/local
  /usr
  PATH_SUFFIXES include/lua52 include/lua5.2 include/lua include
  HINTS
  $ENV{LUA52_ROOT}
  ${LUA52_ROOT})

FIND_LIBRARY(LUA_LIBRARY 
  NAMES lua52 lua5.2 lua-5.2 lua
  PATHS
  /usr/local
  /usr
  PATH_SUFFIXES lib64 lib
  HINTS
  $ENV{LUA52_ROOT}
  ${LUA52_ROOT})

IF(LUA_LIBRARY)
  # include the math library for Unix
  IF(UNIX AND NOT APPLE)
    FIND_LIBRARY(LUA_MATH_LIBRARY m)
    SET(LUA_LIBRARIES "${LUA_LIBRARY};${LUA_MATH_LIBRARY}" CACHE STRING "Lua Libraries")
  # For Windows and Mac, don't need to explicitly include the math library
  ELSE(UNIX AND NOT APPLE)
    SET(LUA_LIBRARIES "${LUA_LIBRARY}" CACHE STRING "Lua Libraries")
  ENDIF(UNIX AND NOT APPLE)
ENDIF(LUA_LIBRARY)

FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua52 DEFAULT_MSG LUA_LIBRARIES LUA_INCLUDE_DIR)
MARK_AS_ADVANCED(LUA_INCLUDE_DIR LUA_LIBRARIES LUA_LIBRARY LUA_MATH_LIBRARY)

