mirror of
https://github.com/opencv/opencv.git
synced 2024-12-04 00:39:11 +08:00
Merge pull request #26009 from alexlyulkov:al/unify-build-gradle
Unified build.gradle files into one template #26009 Issue #24686 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
parent
a087a9c47a
commit
8715229e49
@ -15,6 +15,59 @@ file(MAKE_DIRECTORY "${java_src_dir}")
|
|||||||
|
|
||||||
ocv_copyfiles_append_dir(JAVA_SRC_COPY "${OPENCV_JAVA_BINDINGS_DIR}/gen/java" "${java_src_dir}")
|
ocv_copyfiles_append_dir(JAVA_SRC_COPY "${OPENCV_JAVA_BINDINGS_DIR}/gen/java" "${java_src_dir}")
|
||||||
|
|
||||||
|
set(SOURSE_SETS_JNI_LIBS_SRC_DIRS "'native/libs'")
|
||||||
|
set(SOURSE_SETS_JAVA_SRC_DIRS "'java/src'")
|
||||||
|
set(SOURSE_SETS_RES_SRC_DIRS "'java/res'")
|
||||||
|
set(SOURSE_SETS_MANIFEST_SRC_FILE "'java/AndroidManifest.xml'")
|
||||||
|
set(BUILD_GRADLE_COMPILE_OPTIONS "
|
||||||
|
compileOptions {
|
||||||
|
sourceCompatibility JavaVersion.VERSION_${ANDROID_GRADLE_JAVA_VERSION_INIT}
|
||||||
|
targetCompatibility JavaVersion.VERSION_${ANDROID_GRADLE_JAVA_VERSION_INIT}
|
||||||
|
}
|
||||||
|
")
|
||||||
|
set(MAVEN_PUBLISH_PLUGIN_DECLARATION "apply plugin: 'maven-publish'")
|
||||||
|
set(BUILD_GRADLE_ANDROID_PUBLISHING_CONFIG "
|
||||||
|
buildFeatures {
|
||||||
|
prefabPublishing true
|
||||||
|
buildConfig true
|
||||||
|
}
|
||||||
|
|
||||||
|
prefab {
|
||||||
|
opencv_jni_shared {
|
||||||
|
headers 'native/jni/include'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
publishing {
|
||||||
|
singleVariant('release') {
|
||||||
|
withSourcesJar()
|
||||||
|
withJavadocJar()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
")
|
||||||
|
|
||||||
|
set(BUILD_GRADLE_PUBLISHING_CONFIG "
|
||||||
|
publishing {
|
||||||
|
publications {
|
||||||
|
release(MavenPublication) {
|
||||||
|
groupId = 'org.opencv'
|
||||||
|
artifactId = 'opencv'
|
||||||
|
version = '${OPENCV_VERSION_PLAIN}'
|
||||||
|
|
||||||
|
afterEvaluate {
|
||||||
|
from components.release
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
repositories {
|
||||||
|
maven {
|
||||||
|
name = 'myrepo'
|
||||||
|
url = \"\${project.buildDir}/repo\"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
")
|
||||||
|
|
||||||
if(ANDROID_EXECUTABLE)
|
if(ANDROID_EXECUTABLE)
|
||||||
|
|
||||||
ocv_assert(ANDROID_TOOLS_Pkg_Revision GREATER 13)
|
ocv_assert(ANDROID_TOOLS_Pkg_Revision GREATER 13)
|
||||||
@ -108,6 +161,7 @@ if(ANDROID_NATIVE_API_LEVEL GREATER 21)
|
|||||||
else()
|
else()
|
||||||
ocv_update(ANDROID_TARGET_SDK_VERSION "21")
|
ocv_update(ANDROID_TARGET_SDK_VERSION "21")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/build.gradle.in" "${CMAKE_CURRENT_BINARY_DIR}/build.gradle" @ONLY)
|
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/build.gradle.in" "${CMAKE_CURRENT_BINARY_DIR}/build.gradle" @ONLY)
|
||||||
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/build.gradle" DESTINATION ${JAVA_INSTALL_ROOT}/.. COMPONENT java)
|
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/build.gradle" DESTINATION ${JAVA_INSTALL_ROOT}/.. COMPONENT java)
|
||||||
|
|
||||||
@ -117,12 +171,23 @@ else() # gradle build
|
|||||||
# Android Gradle-based project
|
# Android Gradle-based project
|
||||||
#
|
#
|
||||||
|
|
||||||
|
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/build.gradle.in" "${ANDROID_TMP_INSTALL_BASE_DIR}/opencv/build.gradle" @ONLY)
|
||||||
|
|
||||||
#TODO: INSTALL ONLY
|
#TODO: INSTALL ONLY
|
||||||
ocv_copyfiles_append_dir(JAVA_SRC_COPY "${OPENCV_JAVA_BINDINGS_DIR}/gen/android/java" "${java_src_dir}")
|
ocv_copyfiles_append_dir(JAVA_SRC_COPY "${OPENCV_JAVA_BINDINGS_DIR}/gen/android/java" "${java_src_dir}")
|
||||||
ocv_copyfiles_append_dir(JAVA_SRC_COPY "${OPENCV_JAVA_BINDINGS_DIR}/gen/android-21/java" "${java_src_dir}")
|
ocv_copyfiles_append_dir(JAVA_SRC_COPY "${OPENCV_JAVA_BINDINGS_DIR}/gen/android-21/java" "${java_src_dir}")
|
||||||
ocv_copyfiles_append_dir(JAVA_SRC_COPY "${OPENCV_JAVA_BINDINGS_DIR}/gen/android-24/java" "${java_src_dir}")
|
ocv_copyfiles_append_dir(JAVA_SRC_COPY "${OPENCV_JAVA_BINDINGS_DIR}/gen/android-24/java" "${java_src_dir}")
|
||||||
|
|
||||||
# copy boilerplate
|
# copy boilerplate
|
||||||
|
set(SOURSE_SETS_JNI_LIBS_SRC_DIRS "'../../jni'")
|
||||||
|
set(SOURSE_SETS_JAVA_SRC_DIRS "'src'")
|
||||||
|
set(SOURSE_SETS_RES_SRC_DIRS "'${OpenCV_SOURCE_DIR}/modules/java/android_sdk/android_gradle_lib/res'")
|
||||||
|
set(SOURSE_SETS_MANIFEST_SRC_FILE "'AndroidManifest.xml'")
|
||||||
|
set(BUILD_GRADLE_COMPILE_OPTIONS "")
|
||||||
|
set(MAVEN_PUBLISH_PLUGIN_DECLARATION "")
|
||||||
|
set(BUILD_GRADLE_ANDROID_PUBLISHING_CONFIG "")
|
||||||
|
set(BUILD_GRADLE_PUBLISHING_CONFIG "")
|
||||||
|
|
||||||
set(__base_dir "${CMAKE_CURRENT_SOURCE_DIR}/android_gradle_lib/")
|
set(__base_dir "${CMAKE_CURRENT_SOURCE_DIR}/android_gradle_lib/")
|
||||||
file(GLOB_RECURSE seed_project_files_rel RELATIVE "${__base_dir}/" "${__base_dir}/*")
|
file(GLOB_RECURSE seed_project_files_rel RELATIVE "${__base_dir}/" "${__base_dir}/*")
|
||||||
list(REMOVE_ITEM seed_project_files_rel "${ANDROID_MANIFEST_FILE}")
|
list(REMOVE_ITEM seed_project_files_rel "${ANDROID_MANIFEST_FILE}")
|
||||||
@ -134,6 +199,7 @@ foreach(file ${seed_project_files_rel})
|
|||||||
install(FILES "${OPENCV_JAVA_DIR}/${file}" DESTINATION "${JAVA_INSTALL_ROOT}/${install_subdir}" COMPONENT java)
|
install(FILES "${OPENCV_JAVA_DIR}/${file}" DESTINATION "${JAVA_INSTALL_ROOT}/${install_subdir}" COMPONENT java)
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/build.gradle.in" "${OPENCV_JAVA_DIR}/build.gradle" @ONLY)
|
||||||
|
|
||||||
# copy libcxx_helper
|
# copy libcxx_helper
|
||||||
set(__base_dir "${CMAKE_CURRENT_SOURCE_DIR}/")
|
set(__base_dir "${CMAKE_CURRENT_SOURCE_DIR}/")
|
||||||
@ -165,7 +231,6 @@ file(REMOVE "${OPENCV_DEPHELPER}/${the_module}_android") # force rebuild after
|
|||||||
|
|
||||||
add_custom_target(${the_module}_android ALL DEPENDS "${OPENCV_DEPHELPER}/${the_module}_android" SOURCES "${__base_dir}/${ANDROID_MANIFEST_FILE}")
|
add_custom_target(${the_module}_android ALL DEPENDS "${OPENCV_DEPHELPER}/${the_module}_android" SOURCES "${__base_dir}/${ANDROID_MANIFEST_FILE}")
|
||||||
|
|
||||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/build.gradle.in" "${ANDROID_TMP_INSTALL_BASE_DIR}/opencv/build.gradle" @ONLY)
|
|
||||||
install(FILES "${ANDROID_TMP_INSTALL_BASE_DIR}/opencv/build.gradle" DESTINATION ${JAVA_INSTALL_ROOT}/.. COMPONENT java)
|
install(FILES "${ANDROID_TMP_INSTALL_BASE_DIR}/opencv/build.gradle" DESTINATION ${JAVA_INSTALL_ROOT}/.. COMPONENT java)
|
||||||
|
|
||||||
install(DIRECTORY "${java_src_dir}" DESTINATION "${JAVA_INSTALL_ROOT}" COMPONENT java)
|
install(DIRECTORY "${java_src_dir}" DESTINATION "${JAVA_INSTALL_ROOT}" COMPONENT java)
|
||||||
|
@ -1,58 +0,0 @@
|
|||||||
apply plugin: 'com.android.library'
|
|
||||||
@KOTLIN_PLUGIN_DECLARATION@
|
|
||||||
|
|
||||||
def openCVersionName = "@OPENCV_VERSION@"
|
|
||||||
def openCVersionCode = ((@OPENCV_VERSION_MAJOR@ * 100 + @OPENCV_VERSION_MINOR@) * 100 + @OPENCV_VERSION_PATCH@) * 10 + 0
|
|
||||||
|
|
||||||
android {
|
|
||||||
@OPENCV_ANDROID_NAMESPACE_DECLARATION@
|
|
||||||
compileSdkVersion @ANDROID_COMPILE_SDK_VERSION@
|
|
||||||
|
|
||||||
defaultConfig {
|
|
||||||
minSdkVersion @ANDROID_MIN_SDK_VERSION@
|
|
||||||
targetSdkVersion @ANDROID_TARGET_SDK_VERSION@
|
|
||||||
|
|
||||||
versionCode openCVersionCode
|
|
||||||
versionName openCVersionName
|
|
||||||
|
|
||||||
externalNativeBuild {
|
|
||||||
cmake {
|
|
||||||
arguments "-DANDROID_STL=@ANDROID_STL@"
|
|
||||||
targets "opencv_jni_shared"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
buildTypes {
|
|
||||||
debug {
|
|
||||||
packagingOptions {
|
|
||||||
doNotStrip '**/*.so' // controlled by OpenCV CMake scripts
|
|
||||||
}
|
|
||||||
}
|
|
||||||
release {
|
|
||||||
packagingOptions {
|
|
||||||
doNotStrip '**/*.so' // controlled by OpenCV CMake scripts
|
|
||||||
}
|
|
||||||
minifyEnabled false
|
|
||||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sourceSets {
|
|
||||||
main {
|
|
||||||
jniLibs.srcDirs = ['../../jni']
|
|
||||||
java.srcDirs = ['src'] // TODO Use original files instead of copied into build directory
|
|
||||||
res.srcDirs = ['@OpenCV_SOURCE_DIR@/modules/java/android_sdk/android_gradle_lib/res']
|
|
||||||
manifest.srcFile 'AndroidManifest.xml'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
externalNativeBuild {
|
|
||||||
cmake {
|
|
||||||
path (project.projectDir.toString() + '/libcxx_helper/CMakeLists.txt')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
}
|
|
@ -89,7 +89,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
apply plugin: 'com.android.library'
|
apply plugin: 'com.android.library'
|
||||||
apply plugin: 'maven-publish'
|
@MAVEN_PUBLISH_PLUGIN_DECLARATION@
|
||||||
try {
|
try {
|
||||||
@KOTLIN_PLUGIN_DECLARATION@
|
@KOTLIN_PLUGIN_DECLARATION@
|
||||||
println "Configure OpenCV with Kotlin"
|
println "Configure OpenCV with Kotlin"
|
||||||
@ -120,12 +120,7 @@ android {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@BUILD_GRADLE_COMPILE_OPTIONS@
|
||||||
compileOptions {
|
|
||||||
sourceCompatibility JavaVersion.VERSION_@ANDROID_GRADLE_JAVA_VERSION_INIT@
|
|
||||||
targetCompatibility JavaVersion.VERSION_@ANDROID_GRADLE_JAVA_VERSION_INIT@
|
|
||||||
}
|
|
||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
debug {
|
debug {
|
||||||
packagingOptions {
|
packagingOptions {
|
||||||
@ -141,29 +136,12 @@ android {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buildFeatures {
|
|
||||||
prefabPublishing true
|
|
||||||
buildConfig true
|
|
||||||
}
|
|
||||||
prefab {
|
|
||||||
opencv_jni_shared {
|
|
||||||
headers "native/jni/include"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
main {
|
main {
|
||||||
jniLibs.srcDirs = ['native/libs']
|
jniLibs.srcDirs = [@SOURSE_SETS_JNI_LIBS_SRC_DIRS@]
|
||||||
java.srcDirs = ['java/src']
|
java.srcDirs = [@SOURSE_SETS_JAVA_SRC_DIRS@]
|
||||||
res.srcDirs = ['java/res']
|
res.srcDirs = [@SOURSE_SETS_RES_SRC_DIRS@]
|
||||||
manifest.srcFile 'java/AndroidManifest.xml'
|
manifest.srcFile @SOURSE_SETS_MANIFEST_SRC_FILE@
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
publishing {
|
|
||||||
singleVariant('release') {
|
|
||||||
withSourcesJar()
|
|
||||||
withJavadocJar()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,27 +150,8 @@ android {
|
|||||||
path (project.projectDir.toString() + '/libcxx_helper/CMakeLists.txt')
|
path (project.projectDir.toString() + '/libcxx_helper/CMakeLists.txt')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@BUILD_GRADLE_ANDROID_PUBLISHING_CONFIG@
|
||||||
}
|
}
|
||||||
|
@BUILD_GRADLE_PUBLISHING_CONFIG@
|
||||||
publishing {
|
|
||||||
publications {
|
|
||||||
release(MavenPublication) {
|
|
||||||
groupId = 'org.opencv'
|
|
||||||
artifactId = 'opencv'
|
|
||||||
version = '@OPENCV_VERSION_PLAIN@'
|
|
||||||
|
|
||||||
afterEvaluate {
|
|
||||||
from components.release
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
repositories {
|
|
||||||
maven {
|
|
||||||
name = 'myrepo'
|
|
||||||
url = "${project.buildDir}/repo"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user