[jvm-packages] Minor improvements to the CMake build (#2379)

* [jvm-packages] Fixed JNI_OnLoad overload

It does not compile on Windows without proper export flags.

* [jvm-packages] Use JNI types directly where appropriate

* Removed lib hack from CMake build

Prior to this commit the CMake build use hardcoded lib prefix for
libxgboost and libxgboost4j. Unfortunatelly this did not play well with
Windows, which does not use the lib- prefix.
This commit is contained in:
Sergei Lebedev 2017-06-09 17:25:09 +02:00 committed by Nan Zhu
parent 37c27ab8e8
commit 3820ab6a0b
2 changed files with 9 additions and 14 deletions

View File

@ -94,8 +94,6 @@ if(MSVC)
else()
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR})
#Prevent shared library being called liblibxgboost.so on Linux
set(CMAKE_SHARED_LIBRARY_PREFIX "")
endif()
set(LINK_LIBRARIES dmlccore rabit)
@ -124,11 +122,12 @@ endif()
add_library(objxgboost OBJECT ${SOURCES})
set_target_properties(${objxgboost} PROPERTIES POSITION_INDEPENDENT_CODE 1)
add_library(libxgboost SHARED $<TARGET_OBJECTS:objxgboost> ${CUDA_OBJS})
add_executable(xgboost $<TARGET_OBJECTS:objxgboost> ${CUDA_OBJS})
add_executable(runxgboost $<TARGET_OBJECTS:objxgboost> ${CUDA_OBJS})
set_target_properties(runxgboost PROPERTIES OUTPUT_NAME xgboost)
target_link_libraries(runxgboost ${LINK_LIBRARIES})
add_library(xgboost SHARED $<TARGET_OBJECTS:objxgboost> ${CUDA_OBJS})
target_link_libraries(xgboost ${LINK_LIBRARIES})
target_link_libraries(libxgboost ${LINK_LIBRARIES})
option(JVM_BINDINGS "Build JVM bindings" OFF)
@ -137,11 +136,11 @@ if(JVM_BINDINGS)
include_directories(${JNI_INCLUDE_DIRS} jvm-packages/xgboost4j/src/native)
add_library(libxgboost4j SHARED
add_library(xgboost4j SHARED
$<TARGET_OBJECTS:objxgboost>
${CUDA_OBJS}
jvm-packages/xgboost4j/src/native/xgboost4j.cpp)
target_link_libraries(libxgboost4j
target_link_libraries(xgboost4j
${LINK_LIBRARIES}
${JNI_LIBRARIES})
endif()

View File

@ -24,11 +24,7 @@
// helper functions
// set handle
void setHandle(JNIEnv *jenv, jlongArray jhandle, void* handle) {
#ifdef __APPLE__
jlong out = (long) handle;
#else
int64_t out = (int64_t) handle;
#endif
jlong out = (jlong) handle;
jenv->SetLongArrayRegion(jhandle, 0, 1, &out);
}
@ -36,7 +32,7 @@ void setHandle(JNIEnv *jenv, jlongArray jhandle, void* handle) {
static JavaVM* global_jvm = nullptr;
// overrides JNI on load
jint JNI_OnLoad(JavaVM *vm, void *reserved) {
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
global_jvm = vm;
return JNI_VERSION_1_6;
}
@ -76,7 +72,7 @@ XGB_EXTERN_C int XGBoost4jCallbackDataIterNext(
batch, jenv->GetFieldID(batchClass, "featureValue", "[F"));
XGBoostBatchCSR cbatch;
cbatch.size = jenv->GetArrayLength(joffset) - 1;
cbatch.offset = reinterpret_cast<long *>(
cbatch.offset = reinterpret_cast<jlong *>(
jenv->GetLongArrayElements(joffset, 0));
if (jlabel != nullptr) {
cbatch.label = jenv->GetFloatArrayElements(jlabel, 0);