Skip to content

Commit

Permalink
added LightGBM SWIG wrappers for macOS and updated docs (#2002)
Browse files Browse the repository at this point in the history
* added LightGBM SWIG wrappers for macOS and updated docs

* updated installation instructions based on comments

* updated based on comments
  • Loading branch information
imatiach-msft authored and guolinke committed Feb 20, 2019
1 parent 7ebf80f commit 414bb60
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
9 changes: 9 additions & 0 deletions CMakeLists.txt
Expand Up @@ -55,6 +55,9 @@ if(USE_SWIG)
if(WIN32)
FILE(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/com/microsoft/ml/lightgbm/windows/x86_64")
include_directories($ENV{JAVA_HOME}/include/win32)
elseif(APPLE)
FILE(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/com/microsoft/ml/lightgbm/osx/x86_64")
include_directories($ENV{JAVA_HOME}/include/darwin)
else()
FILE(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/com/microsoft/ml/lightgbm/linux/x86_64")
include_directories($ENV{JAVA_HOME}/include/linux)
Expand Down Expand Up @@ -196,6 +199,12 @@ if(USE_SWIG)
COMMAND cp "${PROJECT_SOURCE_DIR}/Release/*.dll" com/microsoft/ml/lightgbm/windows/x86_64
COMMAND "${Java_JAR_EXECUTABLE}" -cf lightgbmlib.jar com)
endif()
elseif(APPLE)
add_custom_command(TARGET _lightgbm_swig POST_BUILD
COMMAND "${Java_JAVAC_EXECUTABLE}" -d . java/*.java
COMMAND cp "${PROJECT_SOURCE_DIR}/*.dylib" com/microsoft/ml/lightgbm/osx/x86_64
COMMAND cp "${PROJECT_SOURCE_DIR}/lib_lightgbm_swig.jnilib" com/microsoft/ml/lightgbm/osx/x86_64/lib_lightgbm_swig.dylib
COMMAND "${Java_JAR_EXECUTABLE}" -cf lightgbmlib.jar com)
else()
add_custom_command(TARGET _lightgbm_swig POST_BUILD
COMMAND "${Java_JAVAC_EXECUTABLE}" -d . java/*.java
Expand Down
76 changes: 76 additions & 0 deletions docs/Installation-Guide.rst
Expand Up @@ -670,6 +670,82 @@ On Linux Java wrapper of LightGBM can be built using **Java**, **SWIG**, **CMake
cmake -DUSE_SWIG=ON ..
make -j4
macOS
^^^^^

On macOS Java wrapper of LightGBM can be built using **Java**, **SWIG**, **CMake** and **Apple Clang** or **gcc**.

First, install `SWIG`_ and **Java** (also make sure that ``JAVA_HOME`` is set properly).
Then, either follow the **Apple Clang** or **gcc** installation instructions below.

Apple Clang
***********

Only **Apple Clang** version 8.1 or higher is supported.

1. Install `CMake`_ (3.12 or higher):

.. code::
brew install cmake
2. Install **OpenMP**:

.. code::
brew install libomp
3. Run the following commands:

.. code::
git clone --recursive https://github.com/Microsoft/LightGBM ; cd LightGBM
mkdir build ; cd build
# For Mojave (10.14)
cmake \
-DUSE_SWIG=ON \
-DAPPLE_OUTPUT_DYLIB=ON \
-DOpenMP_C_FLAGS="-Xpreprocessor -fopenmp -I$(brew --prefix libomp)/include" \
-DOpenMP_C_LIB_NAMES="omp" \
-DOpenMP_CXX_FLAGS="-Xpreprocessor -fopenmp -I$(brew --prefix libomp)/include" \
-DOpenMP_CXX_LIB_NAMES="omp" \
-DOpenMP_omp_LIBRARY=$(brew --prefix libomp)/lib/libomp.dylib \
..
# For High Sierra or earlier (<= 10.13)
cmake -DUSE_SWIG=ON -DAPPLE_OUTPUT_DYLIB=ON ..
make -j4
gcc
***

1. Install `CMake`_ (3.2 or higher):

.. code::
brew install cmake
2. Install **gcc**:

.. code::
brew install gcc
3. Run the following commands:

.. code::
git clone --recursive https://github.com/Microsoft/LightGBM ; cd LightGBM
export CXX=g++-7 CC=gcc-7 # replace "7" with version of gcc installed on your machine
mkdir build ; cd build
cmake -DUSE_SWIG=ON -DAPPLE_OUTPUT_DYLIB=ON ..
make -j4
Also, you may want to read `gcc Tips <./gcc-Tips.rst>`__.


.. |download artifacts| image:: ./_static/images/artifacts-not-available.svg
:target: https://lightgbm.readthedocs.io/en/latest/Installation-Guide.html

Expand Down

0 comments on commit 414bb60

Please sign in to comment.