Skip to content

Building

gershnik-smartsheet edited this page May 23, 2016 · 4 revisions

Smjni originated on Android so it comes with Android.mk and build.gradle for ndk-build and experimental Gradle plugin respectively. In addition it provides portable CMake script that should work everywhere. Instructions for users of other build systems are provided at the end of this section

Android

Smjni requires to be built with RTTI and exceptions enabled. It should work with GNU STL or LLVM libc++. It might or might not work with STLPort. As on every othr platfrom C++14 mode is required.

Using ndk-build

Clone this repository somewhere

In your Android.mk you should have the following settings in addition to other flags

LOCAL_CPP_FEATURES := rtti exceptions
LOCAL_CPPFLAGS :=  -std=gnu++14

Specify dependency on smjni as follows

LOCAL_STATIC_LIBRARIES += smjni

and at the end add

include /path/to/smjni/Android.mk

Using experimental gradle plugin

Clone this repository somewhere

In your settings.gradle specify

include ...all the other projects you have..., ':smjni'
project(':smjni').projectDir = new File('/path/to/smjni')

In your JNI module build.gradle specify the following in addition to other JNI settings you already have

model {
    android {
        ndk {
            cppFlags.add("-std=gnu++14")
            cppFlags.add("-fvisibility=hidden")
            cppFlags.add("-frtti")
            cppFlags.add("-fexceptions")
        }
        sources {
            main {
                jni {
                    dependencies {
                        project ":smjni" linkage "static"
                    }
                }
            }
        }
}

CMake

Clone this repository somewhere

Add the following to your CMakeLists.txt

add_subdirectory("/path/to/smjni" ${CMAKE_CURRENT_BINARY_DIR}/smjni)

#set relevant C++14 flag for your compiler here
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")

target_link_libraries(your_target_name smjni ${JAVA_JVM_LIBRARY})

Other build systems

You will need to

  • Build all *.cpp files under src directory and link them with your code
  • Add inc directory to your include path

Build requires C++14 and a modern standard library.

Clone this wiki locally