Skip to content

Commit

Permalink
Building Lua (static) as external project
Browse files Browse the repository at this point in the history
  • Loading branch information
shehzan10 committed Dec 23, 2015
1 parent c7f1589 commit 47be094
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
41 changes: 41 additions & 0 deletions CMakeModules/build_lua.cmake
Original file line number Diff line number Diff line change
@@ -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}" <SOURCE_DIR>
-DCMAKE_SOURCE_DIR:PATH=<SOURCE_DIR>
-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=<INSTALL_DIR>
-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)
21 changes: 21 additions & 0 deletions CMakeModules/lua_MSVC.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
commit 4b61e31e44bac6b09bb70d3dbcd1b470b754bb71
Author: Shehzan Mohammed <[email protected]>
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

0 comments on commit 47be094

Please sign in to comment.