From b309d277a5bbedc228b7342c09e87c86c620778d Mon Sep 17 00:00:00 2001 From: Pavan Yalamanchili Date: Tue, 22 Dec 2015 20:21:33 -0500 Subject: [PATCH] First attempt at building the arrayfire package on linux --- src/Lua/arrayfire/CMakeLists.txt | 64 +++++++++++++++++++++++++++++++ src/Lua/arrayfire/arrayfire.cpp | 5 ++- src/Lua/arrayfire/export.h | 5 +++ src/Lua/arrayfire/funcs.h | 4 +- src/Lua/arrayfire/graphics.h | 4 +- src/Lua/arrayfire/lua_compat.h | 20 ++++++++++ src/Lua/arrayfire/methods.h | 4 +- src/Lua/arrayfire/template/args.h | 7 +++- src/Lua/arrayfire/utils.cpp | 6 +-- src/Lua/arrayfire/utils.h | 3 +- 10 files changed, 112 insertions(+), 10 deletions(-) create mode 100644 src/Lua/arrayfire/CMakeLists.txt create mode 100644 src/Lua/arrayfire/export.h create mode 100644 src/Lua/arrayfire/lua_compat.h diff --git a/src/Lua/arrayfire/CMakeLists.txt b/src/Lua/arrayfire/CMakeLists.txt new file mode 100644 index 0000000..7fd6803 --- /dev/null +++ b/src/Lua/arrayfire/CMakeLists.txt @@ -0,0 +1,64 @@ +cmake_minimum_required(VERSION 2.8) +SET(AF_LUA_VERSION_MAJOR 0) +SET(AF_LUA_VERSION 0) + +SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON) +FIND_PACKAGE(ArrayFire REQUIRED) +FIND_PACKAGE(Lua REQUIRED) + +FILE(GLOB src + "*.hpp" + "*.h" + "*.cpp" + ) + +FILE(GLOB funcs_src + "funcs/*.cpp" + ) + +SOURCE_GROUP(funcs FILES ${funcs_src}) + +FILE(GLOB graphics_src + "graphics/*.cpp" + ) + +SOURCE_GROUP(graphics FILES ${graphics_src}) + +FILE(GLOB methods_src + "methods/*.cpp" + ) + +SOURCE_GROUP(methods FILES ${methods_src}) + +FILE(GLOB template_src + "template/*.cpp") + +SOURCE_GROUP(template FILES ${template_src}) + +# OS Definitions +IF(UNIX) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -pthread -Wno-comment") + ADD_DEFINITIONS(-Wall -std=c++11 -fvisibility=hidden) +ELSE(${UNIX}) #Windows + ADD_DEFINITIONS(-DAFDLL) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /bigobj") + SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /bigobj") +ENDIF() + +INCLUDE_DIRECTORIES(${ArrayFire_INCLUDE_DIRS}) +INCLUDE_DIRECTORIES(${LUA_INCLUDE_DIR}) + +ADD_LIBRARY(arrayfire SHARED + ${src} + ${funcs_src} + ${graphics_src} + ${methods_src}) + +TARGET_LINK_LIBRARIES(arrayfire + ${ArrayFire_Unified_LIBRARIES} + ${LUA_LIBRARIES} + ) + +SET_TARGET_PROPERTIES(arrayfire PROPERTIES + PREFIX "") diff --git a/src/Lua/arrayfire/arrayfire.cpp b/src/Lua/arrayfire/arrayfire.cpp index b6648d3..b5469b2 100644 --- a/src/Lua/arrayfire/arrayfire.cpp +++ b/src/Lua/arrayfire/arrayfire.cpp @@ -1,3 +1,4 @@ +#include "export.h" #include "funcs.h" #include "graphics.h" #include "methods.h" @@ -17,7 +18,7 @@ void Register (lua_State * L, lua_CFunction func) } } -extern "C" __declspec(dllexport) int luaopen_arrayfire (lua_State * L) +__EXPORT__ int luaopen_arrayfire (lua_State * L) { lua_createtable(L, 0, 0); // af @@ -50,4 +51,4 @@ extern "C" __declspec(dllexport) int luaopen_arrayfire (lua_State * L) Register(L, &Window); return 1; -} \ No newline at end of file +} diff --git a/src/Lua/arrayfire/export.h b/src/Lua/arrayfire/export.h new file mode 100644 index 0000000..9676a9a --- /dev/null +++ b/src/Lua/arrayfire/export.h @@ -0,0 +1,5 @@ +#if defined(_WIN32) || defined(_MSC_VER) +#define __EXPORT__ extern "C" __declspec(dllimport) +#else +#define __EXPORT__ extern "C" __attribute__((visibility("default"))) +#endif diff --git a/src/Lua/arrayfire/funcs.h b/src/Lua/arrayfire/funcs.h index 4ffa84f..a89dc82 100644 --- a/src/Lua/arrayfire/funcs.h +++ b/src/Lua/arrayfire/funcs.h @@ -6,6 +6,8 @@ extern "C" { #include } +#include "lua_compat.h" + int AddEnums (lua_State * L); int CreateArrayFuncs (lua_State * L); int Backends (lua_State * L); @@ -20,4 +22,4 @@ int Statistics (lua_State * L); int Util (lua_State * L); int Vector (lua_State * L); -#endif // FUNCS_H \ No newline at end of file +#endif // FUNCS_H diff --git a/src/Lua/arrayfire/graphics.h b/src/Lua/arrayfire/graphics.h index bc7677a..1d4462e 100644 --- a/src/Lua/arrayfire/graphics.h +++ b/src/Lua/arrayfire/graphics.h @@ -6,7 +6,9 @@ extern "C" { #include } +#include "lua_compat.h" + int Draw (lua_State * L); int Window (lua_State * L); -#endif // GRAPHICS_H \ No newline at end of file +#endif // GRAPHICS_H diff --git a/src/Lua/arrayfire/lua_compat.h b/src/Lua/arrayfire/lua_compat.h new file mode 100644 index 0000000..1d48ced --- /dev/null +++ b/src/Lua/arrayfire/lua_compat.h @@ -0,0 +1,20 @@ +extern "C" { + #include + #include +} + +#if LUA_VERSION_NUM > 501 + +#define lua_objlen(L,i) lua_rawlen(L, (i)) + +#define luaL_register(L, n, l) do { \ + lua_getglobal(L, n); \ + if (lua_isnil(L, -1)) { \ + lua_pop(L, 1); \ + lua_newtable(L); \ + } \ + luaL_setfuncs(L, l, 0); \ + lua_setglobal(L, n); \ + }while(0) + +#endif diff --git a/src/Lua/arrayfire/methods.h b/src/Lua/arrayfire/methods.h index 9709070..852f649 100644 --- a/src/Lua/arrayfire/methods.h +++ b/src/Lua/arrayfire/methods.h @@ -6,6 +6,8 @@ extern "C" { #include } +#include "lua_compat.h" + int AssignIndex (lua_State * L); int Create (lua_State * L); int Constructor (lua_State * L); @@ -15,4 +17,4 @@ int Methods (lua_State * L); int Helper (lua_State * L); int MoveReorder (lua_State * L); -#endif // METHODS_H \ No newline at end of file +#endif // METHODS_H diff --git a/src/Lua/arrayfire/template/args.h b/src/Lua/arrayfire/template/args.h index d1bed56..86639c4 100644 --- a/src/Lua/arrayfire/template/args.h +++ b/src/Lua/arrayfire/template/args.h @@ -1,6 +1,11 @@ #ifndef ARGS_TEMPLATE_H #define ARGS_TEMPLATE_H +extern "C" { + #include + #include +} + #include template @@ -87,4 +92,4 @@ unsigned U (lua_State * L, int index); const char * S (lua_State * L, int index); void * UD (lua_State * L, int index); // N.B. Does not use Arg, since these are ambiguous with af_array / af_features -#endif \ No newline at end of file +#endif diff --git a/src/Lua/arrayfire/utils.cpp b/src/Lua/arrayfire/utils.cpp index 4526075..a859a86 100644 --- a/src/Lua/arrayfire/utils.cpp +++ b/src/Lua/arrayfire/utils.cpp @@ -1,5 +1,5 @@ #include "utils.h" -#include "template/args.h" +#include "lua_compat.h" af_dtype GetDataType (lua_State * L, int index) { @@ -201,7 +201,7 @@ LuaDims::LuaDims (lua_State * L, int first) { luaL_checktype(L, first + 1, LUA_TTABLE); - int n = luaL_checkint(L, first); + int n = (int)luaL_checkinteger(L, first); for (int i = 0; i < n; ++i) { @@ -345,4 +345,4 @@ LuaData::LuaData (lua_State * L, int index, int type_index, bool copy) : mDataPt } if (!mDataPtr) mDataPtr = &mData.front(); -} \ No newline at end of file +} diff --git a/src/Lua/arrayfire/utils.h b/src/Lua/arrayfire/utils.h index 640b9d6..609a7c5 100644 --- a/src/Lua/arrayfire/utils.h +++ b/src/Lua/arrayfire/utils.h @@ -1,6 +1,7 @@ #ifndef UTILS_H #define UTILS_H +#include "template/args.h" #include #include @@ -66,4 +67,4 @@ template } -#endif \ No newline at end of file +#endif