Add check to avoid usage of broken LuaJIT < 2.0.0beta8
authorsapier <Sapier at GMX dot net>
Sat, 8 Feb 2014 14:45:09 +0000 (15:45 +0100)
committersapier <Sapier at GMX dot net>
Thu, 13 Feb 2014 22:28:01 +0000 (23:28 +0100)
CMakeLists.txt
src/CMakeLists.txt

index 80b34e41f0fe0e34f4ee1ed3a534ad68749fa7e4..8883896e7a6305902efae955050e80a09753760c 100644 (file)
@@ -134,7 +134,7 @@ if(NOT CUSTOM_ICONDIR STREQUAL "")
        set(ICONDIR "${CUSTOM_ICONDIR}")
        message(STATUS "Using ICONDIR=${ICONDIR}")
 endif()
-set(CUSTOM_LOCALEDIR "" CACHE STRING "Directory to install l10n files into")           
+set(CUSTOM_LOCALEDIR "" CACHE STRING "Directory to install l10n files into")
 if(NOT CUSTOM_LOCALEDIR STREQUAL "")
        set(LOCALEDIR "${CUSTOM_LOCALEDIR}")
        message(STATUS "Using LOCALEDIR=${LOCALEDIR}")
@@ -163,6 +163,7 @@ install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/fonts" DESTINATION "${SHAREDIR}")
 
 install(FILES "README.txt" DESTINATION "${DOCDIR}")
 install(FILES "doc/lua_api.txt" DESTINATION "${DOCDIR}")
+install(FILES "doc/menu_lua_api.txt" DESTINATION "${DOCDIR}")
 install(FILES "doc/mapformat.txt" DESTINATION "${DOCDIR}")
 install(FILES "minetest.conf.example" DESTINATION "${EXAMPLE_CONF_DIR}")
 
index 025b549cf208ed5c48d7d884e58ba5d8a8711d5a..0e4bbbb672caa2ac1d3eebb38691f39f8d00eef1 100644 (file)
@@ -1,6 +1,8 @@
 project(minetest)
 cmake_minimum_required( VERSION 2.6 )
 
+INCLUDE(CheckCSourceRuns)
+
 # Set some random things default to not being visible in the GUI
 mark_as_advanced(EXECUTABLE_OUTPUT_PATH LIBRARY_OUTPUT_PATH)
 mark_as_advanced(SQLITE3_INCLUDE_DIR SQLITE3_LIBRARY)
@@ -198,25 +200,66 @@ if(USE_FREETYPE)
        set(CGUITTFONT_LIBRARY cguittfont)
 endif(USE_FREETYPE)
 
-
-find_library(LUA_LIBRARY luajit
-               NAMES luajit-5.1)
-find_path(LUA_INCLUDE_DIR luajit.h
-       NAMES luajit.h
-       PATH_SUFFIXES luajit-2.0)
-message (STATUS "LuaJIT library: ${LUA_LIBRARY}")
-message (STATUS "LuaJIT headers: ${LUA_INCLUDE_DIR}")
+if (NOT DISABLE_LUAJIT)
+       find_library(LUA_LIBRARY luajit
+                       NAMES luajit-5.1)
+       find_path(LUA_INCLUDE_DIR luajit.h
+               NAMES luajit.h
+               PATH_SUFFIXES luajit-2.0)
+       message (STATUS "LuaJIT library: ${LUA_LIBRARY}")
+       message (STATUS "LuaJIT headers: ${LUA_INCLUDE_DIR}")
+else (NOT ${DISABLE_LUAJIT} MATCHES "1")
+       message (STATUS "LuaJIT detection disabled! (DISABLE_LUAJIT=1)")
+       set(LUA_LIBRARY "")
+       set(LUA_INCLUDE_DIR "")
+endif (NOT DISABLE_LUAJIT)
 
 set(USE_LUAJIT 0)
 if(LUA_LIBRARY AND LUA_INCLUDE_DIR)
-       message (STATUS "LuaJIT found.")
-       set(USE_LUAJIT 1)
-else(LUA_LIBRARY AND LUA_INCLUDE_DIR)
+       message (STATUS "LuaJIT found, checking for broken versions...")
+       set(BACKUP_REQUIRED_INCS CMAKE_REQUIRED_INCLUDES)
+       set(CMAKE_REQUIRED_INCLUDES "${CMAKE_REQUIRED_INCLUDES} ${LUA_INCLUDE_DIR}")
+       CHECK_C_SOURCE_RUNS("
+               #include <luajit.h>
+               #include <stdio.h>
+               #include <string.h>
+               
+               static char** broken_luajit_versions = (char *[]) {
+                               \"LuaJIT 2.0.0-beta7\",
+                               \"LuaJIT 2.0.0-beta6\",
+                               \"LuaJIT 2.0.0-beta5\",
+                               \"LuaJIT 2.0.0-beta4\",
+                               \"LuaJIT 2.0.0-beta3\",
+                               \"LuaJIT 2.0.0-beta2\",
+                               \"LuaJIT 2.0.0-beta1\"
+               };
+               int main(int argc,char** argv) {
+                       unsigned int i = 0;
+                       for (i=0; i < sizeof(broken_luajit_versions); i++) {
+                               if (strcmp(LUAJIT_VERSION,broken_luajit_versions[i]) == 0) {
+                                       return 1;
+                               }
+                       }
+                       return 0;
+               }
+               "
+               VALID_LUAJIT_VERSION)
+       set(CMAKE_REQUIRED_INCLUDES BACKUP_REQUIRED_INCS)
+       if (VALID_LUAJIT_VERSION)
+               message (STATUS "LuaJIT version ok")
+               set(USE_LUAJIT 1)
+       else (VALID_LUAJIT_VERSION)
+               message (STATUS "LuaJIT versions till 2.0.0beta7 known to be broken, update to at least beta8")
+               set(USE_LUAJIT 0)
+       endif (VALID_LUAJIT_VERSION)
+endif (LUA_LIBRARY AND LUA_INCLUDE_DIR)
+
+if(NOT USE_LUAJIT)
        message (STATUS "LuaJIT not found, using bundled Lua.")
        set(LUA_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/lua/src")
        set(LUA_LIBRARY "lua")
        add_subdirectory(lua)
-endif(LUA_LIBRARY AND LUA_INCLUDE_DIR)
+endif(NOT USE_LUAJIT)
 
 mark_as_advanced(LUA_LIBRARY)
 mark_as_advanced(LUA_INCLUDE_DIR)