Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr/gitroot/simgrid/simgrid
[simgrid.git] / tools / cmake / Modules / FindLuaSimgrid.cmake
1 # Search for the Lua 5.3 include files and libraries
2
3 #  Input variable:
4 #     LUA_HINT: path to Lua installation -- only needed for non-standard installs
5 #  Output variable:
6 #     HAVE_LUA         : if Lua was found
7 #     LUA_LIBRARY      : the path to the dynamic library
8 #     LUA_INCLUDE_DIR  : where to find lua.h
9 #     LUA_VERSION_MAJOR: First part of the version (often, 5)
10 #     LUA_VERSION_MINOR: Second part of the version (3 when we have 5.3)
11
12 find_path(LUA_INCLUDE_DIR lua.h
13   HINTS
14     ENV LUA_HINT
15   PATH_SUFFIXES include/lua53 include/lua5.3 include/lua-5.3 include/lua include
16   PATHS
17   ~/Library/Frameworks
18   /Library/Frameworks
19   /sw # Fink
20   /opt/local # DarwinPorts
21   /opt/csw # Blastwave
22   /opt
23 )
24
25 find_library(LUA_LIBRARY
26   NAMES # I don't want a lua.a
27     lua53.so     lua5.3.so     lua-5.3.so
28     lua53.dynlib lua5.3.dynlib lua-5.3.dynlib
29     lua53.dll    lua5.3.dll    lua-5.3.dll
30     lua.so lua.dynlib lua.dll
31     lua53 lua5.3 lua-5.3 lua
32   HINTS
33     ENV LUA_HINT
34   PATH_SUFFIXES lib
35   PATHS
36   ~/Library/Frameworks
37   /Library/Frameworks
38   /sw
39   /opt/local
40   /opt/csw
41   /opt
42 )
43 if (NOT LUA_LIBRARY) 
44   message(FATAL_ERROR "Error: Lua library not found. Please install that package (and set LUA_HINT) or disable Lua.")
45 endif()
46 if (NOT LUA_INCLUDE_DIR OR NOT EXISTS "${LUA_INCLUDE_DIR}/lua.h")
47   message(FATAL_ERROR "Error: Lua header file not found. Please install that package (and set LUA_HINT) or disable Lua.")
48 endif()
49
50 # Extract the version info out of the header file
51 file(STRINGS "${LUA_INCLUDE_DIR}/lua.h" lua_version_str REGEX "^#define[ \t]+LUA_VERSION_MAJOR[ \t]+\"[456]+\"")
52   string(REGEX REPLACE "^#define[ \t]+LUA_VERSION_MAJOR[ \t]+\"([^\"]+)\"" "\\1" LUA_VERSION_MAJOR "${lua_version_str}")
53 file(STRINGS "${LUA_INCLUDE_DIR}/lua.h" lua_version_str REGEX "^#define[ \t]+LUA_VERSION_MINOR[ \t]+\"[0123456789]+\"")
54   string(REGEX REPLACE "^#define[ \t]+LUA_VERSION_MINOR[ \t]+\"([^\"]+)\"" "\\1" LUA_VERSION_MINOR "${lua_version_str}")
55 unset(lua_version_str)
56   
57 # Check that we have a sufficient version of Lua
58 if(LUA_VERSION_MAJOR EQUAL 5 AND LUA_VERSION_MINOR EQUAL 3)
59   set(HAVE_LUA 1)
60     
61   include_directories(${LUA_INCLUDE_DIR})
62 else()
63   message(FATAL_ERROR "Error: Lua version 5.3 is required, but version ${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR} found instead.")
64 endif()
65
66 message(STATUS "Lua version: ${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}")
67 message(STATUS "Lua library: ${LUA_LIBRARY}")
68 mark_as_advanced(LUA_INCLUDE_DIR)
69 mark_as_advanced(LUA_LIBRARY)