Skip to content

Commit

Permalink
First attempt at building the arrayfire package on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
pavanky committed Dec 23, 2015
1 parent b0d9c80 commit b309d27
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 10 deletions.
64 changes: 64 additions & 0 deletions src/Lua/arrayfire/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 "")
5 changes: 3 additions & 2 deletions src/Lua/arrayfire/arrayfire.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "export.h"
#include "funcs.h"
#include "graphics.h"
#include "methods.h"
Expand All @@ -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

Expand Down Expand Up @@ -50,4 +51,4 @@ extern "C" __declspec(dllexport) int luaopen_arrayfire (lua_State * L)
Register(L, &Window);

return 1;
}
}
5 changes: 5 additions & 0 deletions src/Lua/arrayfire/export.h
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion src/Lua/arrayfire/funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ extern "C" {
#include <lauxlib.h>
}

#include "lua_compat.h"

int AddEnums (lua_State * L);
int CreateArrayFuncs (lua_State * L);
int Backends (lua_State * L);
Expand All @@ -20,4 +22,4 @@ int Statistics (lua_State * L);
int Util (lua_State * L);
int Vector (lua_State * L);

#endif // FUNCS_H
#endif // FUNCS_H
4 changes: 3 additions & 1 deletion src/Lua/arrayfire/graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ extern "C" {
#include <lauxlib.h>
}

#include "lua_compat.h"

int Draw (lua_State * L);
int Window (lua_State * L);

#endif // GRAPHICS_H
#endif // GRAPHICS_H
20 changes: 20 additions & 0 deletions src/Lua/arrayfire/lua_compat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
extern "C" {
#include <lua.h>
#include <lauxlib.h>
}

#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
4 changes: 3 additions & 1 deletion src/Lua/arrayfire/methods.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ extern "C" {
#include <lauxlib.h>
}

#include "lua_compat.h"

int AssignIndex (lua_State * L);
int Create (lua_State * L);
int Constructor (lua_State * L);
Expand All @@ -15,4 +17,4 @@ int Methods (lua_State * L);
int Helper (lua_State * L);
int MoveReorder (lua_State * L);

#endif // METHODS_H
#endif // METHODS_H
7 changes: 6 additions & 1 deletion src/Lua/arrayfire/template/args.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#ifndef ARGS_TEMPLATE_H
#define ARGS_TEMPLATE_H

extern "C" {
#include <lua.h>
#include <lauxlib.h>
}

#include <arrayfire.h>

template<class T>
Expand Down Expand Up @@ -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<void *>, since these are ambiguous with af_array / af_features

#endif
#endif
6 changes: 3 additions & 3 deletions src/Lua/arrayfire/utils.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "utils.h"
#include "template/args.h"
#include "lua_compat.h"

af_dtype GetDataType (lua_State * L, int index)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -345,4 +345,4 @@ LuaData::LuaData (lua_State * L, int index, int type_index, bool copy) : mDataPt
}

if (!mDataPtr) mDataPtr = &mData.front();
}
}
3 changes: 2 additions & 1 deletion src/Lua/arrayfire/utils.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef UTILS_H
#define UTILS_H

#include "template/args.h"
#include <arrayfire.h>
#include <vector>

Expand Down Expand Up @@ -66,4 +67,4 @@ template<af_err (*func)(af_array *, const unsigned, const dim_t *, const af_dtyp

#define DIMS_AND_TYPE(name) { "af_"#name, DimsAndType<&af_##name> }

#endif
#endif

0 comments on commit b309d27

Please sign in to comment.