Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
remove 51 from the name of FindLua51Simgrid: we now need v5.3, not v5.1
[simgrid.git] / tools / cmake / Modules / FindLuaSimgrid.cmake
diff --git a/tools/cmake/Modules/FindLuaSimgrid.cmake b/tools/cmake/Modules/FindLuaSimgrid.cmake
new file mode 100644 (file)
index 0000000..fe6f2b6
--- /dev/null
@@ -0,0 +1,48 @@
+include(./FindLua)
+find_program(HAVE_LUA_BIN NAMES lua)
+mark_as_advanced(HAVE_LUA_BIN)
+
+message(STATUS "Looking for lua.h")
+if(LUA_INCLUDE_DIR)
+  message(STATUS "Looking for lua.h - found")
+else()
+  message(STATUS "Looking for lua.h - not found")
+endif()
+
+if(HAVE_LUA_BIN)
+  message(STATUS "Found Lua: ${HAVE_LUA_BIN}")
+endif()
+
+set(LIB_LUA_NAME "")
+
+foreach(lib_path ${LUA_LIBRARIES})
+  if(NOT LIB_LUA_NAME)
+    string(REGEX MATCH "liblua.*$" LIB_LUA_NAME "${lib_path}")
+    string(REPLACE ".${LIB_EXE}" "" LIB_LUA_NAME "${LIB_LUA_NAME}")
+    string(REPLACE "lib" "" LIB_LUA_NAME "${LIB_LUA_NAME}")
+    if(LIB_LUA_NAME)
+      string(REPLACE "/lib${LIB_LUA_NAME}.${LIB_EXE}" "" LUA_LIBRARY_DIR ${lib_path})
+    endif()
+  endif()
+endforeach(lib_path ${LUA_LIBRARIES})
+
+message(STATUS "Looking for lib lua")
+if(LUA_LIBRARY_DIR)
+  message(STATUS "Looking for lib lua - found")
+  message(STATUS "Lua version: ${LUA_VERSION_STRING}")
+  message(STATUS "Lib path   : ${LUA_LIBRARY_DIR}")
+else()
+  message(STATUS "Looking for lib lua - not found")
+endif()
+
+if(LUA_FOUND)
+  if(LUA_VERSION_MAJOR EQUAL 5 AND LUA_VERSION_MINOR EQUAL 3)
+    set(HAVE_LUA 1)
+    include_directories(${LUA_INCLUDE_DIR})
+    link_directories(${LUA_LIBRARY_DIR})
+  else()
+    message(FATAL_ERROR "Error: Lua version 5.3 is required, but version ${LUA_VERSION_STRING} found instead.")
+  endif()
+else()
+  message(FATAL_ERROR "Error: Lua version 5.3 is required, but Lua not found.")
+endif()