Skip to content

Commit

Permalink
integrate cmake into gradle
Browse files Browse the repository at this point in the history
  • Loading branch information
wgtdkp committed May 12, 2024
1 parent 79d1ddc commit 8cfbc4a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
35 changes: 35 additions & 0 deletions android/openthread_commissioner/service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,32 @@ android {

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"

externalNativeBuild {
cmake {
arguments "-DOT_COMM_ANDROID=ON",
"-DOT_COMM_JAVA_BINDING=ON",
"-DBUILD_SHARED_LIBS=OFF",
"-DCMAKE_CXX_STANDARD=11",
"-DCMAKE_CXX_STANDARD_REQUIRED=ON",
"-DCMAKE_BUILD_TYPE=Release",
"-DOT_COMM_APP=OFF",
"-DOT_COMM_TEST=OFF",
"-DOT_COMM_CCM=OFF",
"-DOT_COMM_JAR_DIR=libs"

targets "commissioner-java", "commissioner-java-lib"
}
}
}

externalNativeBuild {

// Encapsulates your CMake build configurations.
cmake {
// Provides a relative path to your CMake build script.
path "../../../CMakeLists.txt"
}
}

buildTypes {
Expand All @@ -52,6 +78,15 @@ android {
targetCompatibility JavaVersion.VERSION_1_8
}
namespace 'io.openthread.commissioner.service'
sourceSets.main.java.srcDirs += 'src/genlibs/java'
}

project.afterEvaluate {
// Not sure how much of a hack this is - but it allows CMake/SWIG to run before Android Studio
// complains about missing generated files
// TODO: Probably need a release hook too?
compileDebugJavaWithJavac.dependsOn externalNativeBuildDebug
javaPreCompileRelease.dependsOn externalNativeBuildRelease
}

// This is for the local tests (src/test) to find the native libraries.
Expand Down
11 changes: 9 additions & 2 deletions src/java/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#

set(JAVA_PACKAGE_NAME io.openthread.commissioner)
set(JAVA_OUTFILE_DIR ${CMAKE_CURRENT_BINARY_DIR}/io/openthread/commissioner)

find_package(SWIG 4.0 REQUIRED)
find_package(Java REQUIRED)
Expand Down Expand Up @@ -74,6 +73,14 @@ install(TARGETS commissioner-java
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)

get_property(GENERATED_JAVA_SRCS TARGET commissioner-java PROPERTY SWIG_SUPPORT_FILES)

add_jar(commissioner-java-lib
${GENERATED_JAVA_SRCS}
)

add_dependencies(commissioner-java-lib commissioner-java)

## It is useful that the output directory can be configured when
## OT commissioner is integrated with an existing Android application.
if (OT_COMM_JAVA_BINDING_OUTDIR)
Expand All @@ -82,5 +89,5 @@ if (OT_COMM_JAVA_BINDING_OUTDIR)
COMMAND cp io/openthread/commissioner/*.java ${OT_COMM_JAVA_BINDING_OUTDIR}/io/openthread/commissioner
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "packing generated Java source files..."
)
)
endif()

0 comments on commit 8cfbc4a

Please sign in to comment.