when Lua is not found, fallback to compiling the one that comes bundled in our sources
authorkoda
Mon, 07 May 2012 14:53:08 +0200
changeset 7031 d5ea24399a48
parent 7030 09984acadece
child 7032 5685ca1ec9bf
when Lua is not found, fallback to compiling the one that comes bundled in our sources
CMakeLists.txt
cmake_modules/FindLua.cmake
hedgewars/CMakeLists.txt
misc/liblua/CMakeLists.txt
--- a/CMakeLists.txt	Mon May 07 11:59:09 2012 +0200
+++ b/CMakeLists.txt	Mon May 07 14:53:08 2012 +0200
@@ -120,8 +120,6 @@
 	set(pascal_compiler_flags_cmn "-Ff~/Library/Frameworks" ${pascal_compiler_flags_cmn})
 	#set deployment target
 	set(pascal_compiler_flags_cmn "-k-macosx_version_min" "-k${minimum_macosx_version}" "-XR${CMAKE_OSX_SYSROOT}" ${pascal_compiler_flags_cmn})
-	#link with liblua.a (which requires readline)
-	set(pascal_compiler_flags_cmn "-k${CMAKE_BINARY_DIR}/bin/liblua.a" "-k-lreadline" ${pascal_compiler_flags_cmn})
 	#link with libsdlmain.a (when building an executable)
 	if(NOT BUILD_ENGINE_LIBRARY)
 		set(pascal_compiler_flags_cmn "-k${CMAKE_BINARY_DIR}/bin/libSDLmain.a" ${pascal_compiler_flags_cmn})
@@ -190,7 +188,12 @@
 	set(HAVE_NETSERVER false)
 endif(WITH_SERVER)
 
-add_subdirectory(misc/liblua)
+find_package(Lua)
+if(NOT ${LUA_FOUND})
+	add_subdirectory(misc/liblua)
+	#link with liblua.a (which requires readline)
+	set(pascal_compiler_flags_cmn "-k${CMAKE_BINARY_DIR}/bin/liblua.a" "-k-lreadline" ${pascal_compiler_flags_cmn})
+endif()
 add_subdirectory(hedgewars)
 
 #run cmake -DBUILD_ANDROID_PORT=1 to enable this
--- a/cmake_modules/FindLua.cmake	Mon May 07 11:59:09 2012 +0200
+++ b/cmake_modules/FindLua.cmake	Mon May 07 14:53:08 2012 +0200
@@ -1,5 +1,11 @@
 # Find the Lua library
-#
+# --------------------
+# On Android/Windows/OSX this just defines the name of the library that
+#  will be compiled from our bundled sources
+# On Linux it will try to load the system library and fallback to compiling
+#  the bundled one when nothing is found
+
+set(LUA_FOUND true)
 
 if (ANDROID)
 	SET(LUA_DEFAULT "liblua5.1.so")
@@ -14,10 +20,14 @@
 			FIND_LIBRARY(LUA_DEFAULT NAMES lua51 lua5.1 lua-5.1 lua PATHS /lib /usr/lib /usr/local/lib /usr/pkg/lib)
 			IF(${LUA_DEFAULT} MATCHES "LUA_DEFAULT-NOTFOUND")
 				#UNSET(LUA_DEFAULT)
-				MESSAGE(FATAL_ERROR "Couldn't find Lua 5.1 library!")
+				#MESSAGE(FATAL_ERROR "Couldn't find Lua 5.1 library!")
+				set(LUA_DEFAULT lua)
+				set(LUA_FOUND false)
+			ELSE()
+				message(STATUS "LibLua 5.1 found at ${LUA_DEFAULT}")
+				#remove the path (fpc doesn't like it - why?)
+				GET_FILENAME_COMPONENT(LUA_DEFAULT ${LUA_DEFAULT} NAME)
 			ENDIF()
-			#remove the path (fpc doesn't like it - why?)
-			GET_FILENAME_COMPONENT(LUA_DEFAULT ${LUA_DEFAULT} NAME)
                 ENDIF(APPLE)
 	ENDIF(WIN32)
 ENDIF(ANDROID)
--- a/hedgewars/CMakeLists.txt	Mon May 07 11:59:09 2012 +0200
+++ b/hedgewars/CMakeLists.txt	Mon May 07 14:53:08 2012 +0200
@@ -3,7 +3,6 @@
 find_package(SDL_net)
 find_package(SDL_ttf)
 find_package(SDL_mixer)
-find_package(Lua)
 
 include(${CMAKE_MODULE_PATH}/FindSDL_Extras.cmake)
 
@@ -188,7 +187,7 @@
             COMMAND "${pascal_compiler}"
             ARGS ${pascal_compiler_flags} -ohwengine.${build_arch} -P${build_arch}
             MAIN_DEPENDENCY ${hwengine_project}
-            DEPENDS ${engine_sources} SDLmain lua
+            DEPENDS ${engine_sources} SDLmain
             )
         add_custom_target(hwengine.${build_arch} ALL DEPENDS "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}")
     endforeach()
@@ -202,10 +201,19 @@
 
 
 add_custom_target(${engine_output_name} ALL DEPENDS "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}${CMAKE_EXECUTABLE_SUFFIX}")
-IF(NOT APPLE)
+
+#when system Lua is not found we need to compile it before engine
+if(NOT ${LUA_FOUND})
+    add_dependencies(${engine_output_name} lua)
+endif()
+
+#this command is a workaround to some inlining issues present in older
+# FreePascal versions and fixed in 2.6, That version is mandatory on OSX,
+# hence the command is not needed there
+if(NOT APPLE)
     add_custom_target(ENGINECLEAN COMMAND ${CMAKE_BUILD_TOOL} "clean" "${PROJECT_BINARY_DIR}" "${hedgewars_SOURCE_DIR}/hedgewars")
     add_dependencies(${engine_output_name} ENGINECLEAN)
-ENDIF()
+endif()
 
 install(PROGRAMS "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}${CMAKE_EXECUTABLE_SUFFIX}" DESTINATION ${target_dir})
 
--- a/misc/liblua/CMakeLists.txt	Mon May 07 11:59:09 2012 +0200
+++ b/misc/liblua/CMakeLists.txt	Mon May 07 14:53:08 2012 +0200
@@ -1,19 +1,17 @@
+#this file is included only when system Lua library is not found
+
 file(GLOB lua_src *.c *.h)
 set(LIBRARY_OUTPUT_PATH ${EXECUTABLE_OUTPUT_PATH})
 
-IF(APPLE)
-	set(build_type STATIC)
-	add_definitions(-DLUA_USE_LINUX)
-	add_library (lua ${build_type} ${lua_src})
-ENDIF(APPLE)
+if(WIN32)
+    add_definitions(-DLUA_BUILD_AS_DLL)
+    add_library(lua SHARED ${lua_src})
 
-IF(WIN32)
-	set(build_type SHARED)
-	add_definitions(-DLUA_BUILD_AS_DLL)
-	add_library (lua ${build_type} ${lua_src})
-
-	SET_TARGET_PROPERTIES(lua PROPERTIES PREFIX "")
-	install(TARGETS lua RUNTIME DESTINATION ${target_dir})
+    set_target_properties(lua PROPERTIES PREFIX "")
+    install(TARGETS lua RUNTIME DESTINATION ${target_dir})
+else(WIN32)
+    add_definitions(-DLUA_USE_LINUX)
+    add_library(lua STATIC ${lua_src})
 endif(WIN32)