From 47be09431c2411482c6999d42f87b3e21428ca2d Mon Sep 17 00:00:00 2001 From: Shehzan Mohammed Date: Wed, 23 Dec 2015 15:04:01 -0500 Subject: [PATCH] Building Lua (static) as external project --- CMakeLists.txt | 6 ++++++ CMakeModules/build_lua.cmake | 41 ++++++++++++++++++++++++++++++++++++ CMakeModules/lua_MSVC.patch | 21 ++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 CMakeModules/build_lua.cmake create mode 100644 CMakeModules/lua_MSVC.patch diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..bd63c88 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,6 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +PROJECT(ArrayFire-Lua-Wrapper) + +SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules") + +INCLUDE(${CMAKE_MODULE_PATH}/build_lua.cmake) diff --git a/CMakeModules/build_lua.cmake b/CMakeModules/build_lua.cmake new file mode 100644 index 0000000..15a9269 --- /dev/null +++ b/CMakeModules/build_lua.cmake @@ -0,0 +1,41 @@ +INCLUDE(ExternalProject) + +SET(prefix ${CMAKE_BINARY_DIR}/third_party/lua) + +SET(lua_location "${prefix}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}lua${CMAKE_STATIC_LIBRARY_SUFFIX}") +IF(CMAKE_VERSION VERSION_LESS 3.2) + IF(CMAKE_GENERATOR MATCHES "Ninja") + MESSAGE(WARNING "Building forge with Ninja has known issues with CMake older than 3.2") + endif() + SET(byproducts) +ELSE() + SET(byproducts BYPRODUCTS ${lua_location}) +ENDIF() + +# FIXME Tag forge correctly during release +ExternalProject_Add( + lua-ext + GIT_REPOSITORY https://github.com/LuaDist/lua.git + GIT_TAG 5.3.2 + PATCH_COMMAND patch -p1 -t -N < ${CMAKE_MODULE_PATH}/lua_MSVC.patch + PREFIX "${prefix}" + INSTALL_DIR "${prefix}" + UPDATE_COMMAND "" + CONFIGURE_COMMAND ${CMAKE_COMMAND} -Wno-dev "-G${CMAKE_GENERATOR}" + -DCMAKE_SOURCE_DIR:PATH= + -DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER} + -DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER} + -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} + -DCMAKE_INSTALL_PREFIX:PATH= + -DBUILD_SHARED_LIBS=OFF + -DLUA_BUILD_AS_DLL=OFF + ${byproducts} + ) + +ExternalProject_Get_Property(lua-ext install_dir) +ADD_LIBRARY(lua IMPORTED STATIC) +SET_TARGET_PROPERTIES(lua PROPERTIES IMPORTED_LOCATION ${lua_location}) +ADD_DEPENDENCIES(lua lua-ext) +SET(LUA_INCLUDE_DIRECTORIES ${install_dir}/include) +SET(LUA_LIBRARIES lua) +SET(LUA_FOUND ON) diff --git a/CMakeModules/lua_MSVC.patch b/CMakeModules/lua_MSVC.patch new file mode 100644 index 0000000..e463320 --- /dev/null +++ b/CMakeModules/lua_MSVC.patch @@ -0,0 +1,21 @@ +commit 4b61e31e44bac6b09bb70d3dbcd1b470b754bb71 +Author: Shehzan Mohammed +Date: Wed Dec 23 15:01:27 2015 -0500 + + Lua MSVC snprintf patch + +diff --git a/src/lprefix.h b/src/lprefix.h +index 02daa83..b56f8f6 100644 +--- a/src/lprefix.h ++++ b/src/lprefix.h +@@ -39,6 +39,10 @@ + #define _CRT_SECURE_NO_WARNINGS /* avoid warnings about ISO C functions */ + #endif + ++#if _MSC_VER < 1900 ++#define snprintf sprintf_s ++#endif ++ + #endif /* } */ + + #endif