Skip to content

Commit 8528309

Browse files
author
pradeep
committed
Changes to use cmake build framework
1 parent 21d7fef commit 8528309

7 files changed

Lines changed: 96 additions & 116 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
*.suo
44
x64/*
55
tmp
6+
build

CMakeLists.txt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
2+
PROJECT(ArrayFire-Java)
3+
4+
SET(AF_JAR ArrayFire)
5+
SET(AF_LIB af_java)
6+
7+
OPTION(BUILD_EXAMPLES "Option for building examples" ON)
8+
# Set a default build type if none was specified
9+
IF(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
10+
SET(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
11+
# Set the possible values of build type for cmake-gui
12+
SET_PROPERTY(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
13+
"MinSizeRel" "RelWithDebInfo")
14+
ENDIF()
15+
16+
FIND_PACKAGE(Java COMPONENTS Development)
17+
INCLUDE(UseJava)
18+
19+
IF(NOT Java_FOUND)
20+
MESSAGE(FATAL_ERROR "Java SDK not found, if java is installed to non standard location, please
21+
make sure to set JAVA_HOME environmental variable")
22+
ENDIF()
23+
24+
ADD_SUBDIRECTORY(src)
25+
26+
FILE(GLOB af_java_src "com/arrayfire/*.java")
27+
28+
ADD_JAR(${AF_JAR} ${af_java_src} MANIFEST "${CMAKE_CURRENT_SOURCE_DIR}/Manifest.txt")
29+
30+
ADD_DEPENDENCIES(${AF_JAR} ${AF_LIB})
31+
32+
INSTALL_JAR(${AF_JAR} ".")
33+
34+
IF(BUILD_EXAMPLES)
35+
ADD_SUBDIRECTORY(examples)
36+
ENDIF()

Makefile

Lines changed: 0 additions & 53 deletions
This file was deleted.

Makefile.Windows

Lines changed: 0 additions & 61 deletions
This file was deleted.

examples/CMakeLists.txt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
2+
PROJECT(AFJava-Examples)
3+
4+
FIND_PACKAGE(Java COMPONENTS Runtime)
5+
INCLUDE(UseJava)
6+
7+
IF(NOT Java_FOUND)
8+
MESSAGE(FATAL_ERROR "Java SDK not found, if java is installed to non standard location, please
9+
make sure to set JAVA_HOME environmental variable")
10+
ENDIF()
11+
12+
FILE(GLOB af_examples_src "*.java")
13+
14+
MACRO(BUILD_EXAMPLE src)
15+
# get arrayfire jar file
16+
GET_TARGET_PROPERTY(_afJar ${AF_JAR} JAR_FILE)
17+
# extract file name from source file
18+
GET_FILENAME_COMPONENT(EXAMPLE ${src} NAME_WE)
19+
# add jar file for given source file
20+
ADD_JAR(${EXAMPLE} SOURCES ${src} INCLUDE_JARS ${_afJar})
21+
# udpate the jar file with program entry point
22+
GET_TARGET_PROPERTY(_jarFile ${EXAMPLE} JAR_FILE)
23+
ADD_CUSTOM_COMMAND(TARGET ${EXAMPLE} COMMAND ${Java_JAR_EXECUTABLE} ufe ${_jarFile} ${EXAMPLE})
24+
# install examples jar
25+
INSTALL_JAR(${EXAMPLE} examples)
26+
# add target for running examples
27+
ADD_CUSTOM_TARGET(ex${EXAMPLE} ${Java_JAVA_EXECUTABLE} -cp .:${_afJar}:${_jarFile} ${EXAMPLE})
28+
ENDMACRO()
29+
30+
FOREACH(FILE ${af_examples_src})
31+
BUILD_EXAMPLE(${FILE})
32+
ENDFOREACH()

examples/HelloWorld.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ public static void main(String[] args) {
2929
}
3030

3131
try {
32-
Array A = new Array(), B = new Array(), C = new Array();
33-
3432
// Get info about arrayfire information
3533
Util.info();
3634

35+
Array A = new Array(), B = new Array(), C = new Array();
36+
3737
// Send data to ArrayFire
3838
Data.createArray(A, dims, left);
3939
Data.createArray(B, dims, right);

src/CMakeLists.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
ENABLE_LANGUAGE(CXX)
2+
3+
FIND_PACKAGE(JNI REQUIRED)
4+
FIND_PACKAGE(ArrayFire QUIET)
5+
6+
IF(NOT ArrayFire_FOUND)
7+
MESSAGE(FATAL_ERROR "Please point environment variable ArrayFire_DIR to ArrayFire installation
8+
directory")
9+
ENDIF()
10+
11+
FILE(GLOB af_jni_headers "*.h")
12+
FILE(GLOB af_jni_sources "*.cpp")
13+
14+
INCLUDE_DIRECTORIES(${JNI_INCLUDE_DIRS} ${ArrayFire_INCLUDE_DIRS})
15+
ADD_LIBRARY(${AF_LIB} SHARED ${af_jni_headers} ${af_jni_sources})
16+
TARGET_LINK_LIBRARIES(${AF_LIB} ${JNI_LIBRARIES} ${ArrayFire_LIBRARIES})
17+
18+
IF(${UNIX})
19+
SET(CMAKE_CXX_FLAGS "-fPIC")
20+
SET_TARGET_PROPERTIES(${AF_LIB} PROPERTIES CMAKE_SHARED_LINKER_FLAGS "-fPIC")
21+
ELSEIF(${WINDOWS})
22+
SET(CMAKE_CXX_FLAGS "/MP /EHsc")
23+
ENDIF(${UNIX})
24+
25+
INSTALL(TARGETS ${AF_LIB} DESTINATION lib)

0 commit comments

Comments
 (0)