Skip to content

Commit b309d27

Browse files
committed
First attempt at building the arrayfire package on linux
1 parent b0d9c80 commit b309d27

File tree

10 files changed

+112
-10
lines changed

10 files changed

+112
-10
lines changed

src/Lua/arrayfire/CMakeLists.txt

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
cmake_minimum_required(VERSION 2.8)
2+
SET(AF_LUA_VERSION_MAJOR 0)
3+
SET(AF_LUA_VERSION 0)
4+
5+
SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON)
6+
FIND_PACKAGE(ArrayFire REQUIRED)
7+
FIND_PACKAGE(Lua REQUIRED)
8+
9+
FILE(GLOB src
10+
"*.hpp"
11+
"*.h"
12+
"*.cpp"
13+
)
14+
15+
FILE(GLOB funcs_src
16+
"funcs/*.cpp"
17+
)
18+
19+
SOURCE_GROUP(funcs FILES ${funcs_src})
20+
21+
FILE(GLOB graphics_src
22+
"graphics/*.cpp"
23+
)
24+
25+
SOURCE_GROUP(graphics FILES ${graphics_src})
26+
27+
FILE(GLOB methods_src
28+
"methods/*.cpp"
29+
)
30+
31+
SOURCE_GROUP(methods FILES ${methods_src})
32+
33+
FILE(GLOB template_src
34+
"template/*.cpp")
35+
36+
SOURCE_GROUP(template FILES ${template_src})
37+
38+
# OS Definitions
39+
IF(UNIX)
40+
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -pthread -Wno-comment")
41+
ADD_DEFINITIONS(-Wall -std=c++11 -fvisibility=hidden)
42+
ELSE(${UNIX}) #Windows
43+
ADD_DEFINITIONS(-DAFDLL)
44+
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
45+
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /bigobj")
46+
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /bigobj")
47+
ENDIF()
48+
49+
INCLUDE_DIRECTORIES(${ArrayFire_INCLUDE_DIRS})
50+
INCLUDE_DIRECTORIES(${LUA_INCLUDE_DIR})
51+
52+
ADD_LIBRARY(arrayfire SHARED
53+
${src}
54+
${funcs_src}
55+
${graphics_src}
56+
${methods_src})
57+
58+
TARGET_LINK_LIBRARIES(arrayfire
59+
${ArrayFire_Unified_LIBRARIES}
60+
${LUA_LIBRARIES}
61+
)
62+
63+
SET_TARGET_PROPERTIES(arrayfire PROPERTIES
64+
PREFIX "")

src/Lua/arrayfire/arrayfire.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "export.h"
12
#include "funcs.h"
23
#include "graphics.h"
34
#include "methods.h"
@@ -17,7 +18,7 @@ void Register (lua_State * L, lua_CFunction func)
1718
}
1819
}
1920

20-
extern "C" __declspec(dllexport) int luaopen_arrayfire (lua_State * L)
21+
__EXPORT__ int luaopen_arrayfire (lua_State * L)
2122
{
2223
lua_createtable(L, 0, 0); // af
2324

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

5253
return 1;
53-
}
54+
}

src/Lua/arrayfire/export.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#if defined(_WIN32) || defined(_MSC_VER)
2+
#define __EXPORT__ extern "C" __declspec(dllimport)
3+
#else
4+
#define __EXPORT__ extern "C" __attribute__((visibility("default")))
5+
#endif

src/Lua/arrayfire/funcs.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ extern "C" {
66
#include <lauxlib.h>
77
}
88

9+
#include "lua_compat.h"
10+
911
int AddEnums (lua_State * L);
1012
int CreateArrayFuncs (lua_State * L);
1113
int Backends (lua_State * L);
@@ -20,4 +22,4 @@ int Statistics (lua_State * L);
2022
int Util (lua_State * L);
2123
int Vector (lua_State * L);
2224

23-
#endif // FUNCS_H
25+
#endif // FUNCS_H

src/Lua/arrayfire/graphics.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ extern "C" {
66
#include <lauxlib.h>
77
}
88

9+
#include "lua_compat.h"
10+
911
int Draw (lua_State * L);
1012
int Window (lua_State * L);
1113

12-
#endif // GRAPHICS_H
14+
#endif // GRAPHICS_H

src/Lua/arrayfire/lua_compat.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
extern "C" {
2+
#include <lua.h>
3+
#include <lauxlib.h>
4+
}
5+
6+
#if LUA_VERSION_NUM > 501
7+
8+
#define lua_objlen(L,i) lua_rawlen(L, (i))
9+
10+
#define luaL_register(L, n, l) do { \
11+
lua_getglobal(L, n); \
12+
if (lua_isnil(L, -1)) { \
13+
lua_pop(L, 1); \
14+
lua_newtable(L); \
15+
} \
16+
luaL_setfuncs(L, l, 0); \
17+
lua_setglobal(L, n); \
18+
}while(0)
19+
20+
#endif

src/Lua/arrayfire/methods.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ extern "C" {
66
#include <lauxlib.h>
77
}
88

9+
#include "lua_compat.h"
10+
911
int AssignIndex (lua_State * L);
1012
int Create (lua_State * L);
1113
int Constructor (lua_State * L);
@@ -15,4 +17,4 @@ int Methods (lua_State * L);
1517
int Helper (lua_State * L);
1618
int MoveReorder (lua_State * L);
1719

18-
#endif // METHODS_H
20+
#endif // METHODS_H

src/Lua/arrayfire/template/args.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#ifndef ARGS_TEMPLATE_H
22
#define ARGS_TEMPLATE_H
33

4+
extern "C" {
5+
#include <lua.h>
6+
#include <lauxlib.h>
7+
}
8+
49
#include <arrayfire.h>
510

611
template<class T>
@@ -87,4 +92,4 @@ unsigned U (lua_State * L, int index);
8792
const char * S (lua_State * L, int index);
8893
void * UD (lua_State * L, int index); // N.B. Does not use Arg<void *>, since these are ambiguous with af_array / af_features
8994

90-
#endif
95+
#endif

src/Lua/arrayfire/utils.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "utils.h"
2-
#include "template/args.h"
2+
#include "lua_compat.h"
33

44
af_dtype GetDataType (lua_State * L, int index)
55
{
@@ -201,7 +201,7 @@ LuaDims::LuaDims (lua_State * L, int first)
201201
{
202202
luaL_checktype(L, first + 1, LUA_TTABLE);
203203

204-
int n = luaL_checkint(L, first);
204+
int n = (int)luaL_checkinteger(L, first);
205205

206206
for (int i = 0; i < n; ++i)
207207
{
@@ -345,4 +345,4 @@ LuaData::LuaData (lua_State * L, int index, int type_index, bool copy) : mDataPt
345345
}
346346

347347
if (!mDataPtr) mDataPtr = &mData.front();
348-
}
348+
}

src/Lua/arrayfire/utils.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef UTILS_H
22
#define UTILS_H
33

4+
#include "template/args.h"
45
#include <arrayfire.h>
56
#include <vector>
67

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

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

69-
#endif
70+
#endif

0 commit comments

Comments
 (0)