Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[cmake] cleanups in the Lua detection
[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 lua53 lua5.3 lua-5.3 lua
27   HINTS
28     ENV LUA_HINT
29   PATH_SUFFIXES lib
30   PATHS
31   ~/Library/Frameworks
32   /Library/Frameworks
33   /sw
34   /opt/local
35   /opt/csw
36   /opt
37 )
38 if (NOT LUA_LIBRARY) 
39   message(FATAL_ERROR "Error: Lua library not found. Please install that package (and set LUA_HINT) or disable Lua.")
40 endif()
41 if (NOT LUA_INCLUDE_DIR OR NOT EXISTS "${LUA_INCLUDE_DIR}/lua.h")
42   message(FATAL_ERROR "Error: Lua header file not found. Please install that package (and set LUA_HINT) or disable Lua.")
43 endif()
44
45 # Extract the version info out of the header file
46 file(STRINGS "${LUA_INCLUDE_DIR}/lua.h" lua_version_str REGEX "^#define[ \t]+LUA_VERSION_MAJOR[ \t]+\"[456]+\"")
47   string(REGEX REPLACE "^#define[ \t]+LUA_VERSION_MAJOR[ \t]+\"([^\"]+)\"" "\\1" LUA_VERSION_MAJOR "${lua_version_str}")
48 file(STRINGS "${LUA_INCLUDE_DIR}/lua.h" lua_version_str REGEX "^#define[ \t]+LUA_VERSION_MINOR[ \t]+\"[0123456789]+\"")
49   string(REGEX REPLACE "^#define[ \t]+LUA_VERSION_MINOR[ \t]+\"([^\"]+)\"" "\\1" LUA_VERSION_MINOR "${lua_version_str}")
50 unset(lua_version_str)
51   
52 # Check that we have a sufficient version of Lua
53 if(LUA_VERSION_MAJOR EQUAL 5 AND LUA_VERSION_MINOR EQUAL 3)
54   set(HAVE_LUA 1)
55     
56   include_directories(${LUA_INCLUDE_DIR})
57 else()
58   message(FATAL_ERROR "Error: Lua version 5.3 is required, but version ${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR} found instead.")
59 endif()
60
61 message(STATUS "Lua version: ${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}")
62 message(STATUS "Lua library: ${LUA_LIBRARY}")