From 9cfa51a4831068c741c312956071f5ce2e5eb06c Mon Sep 17 00:00:00 2001 From: Alexander Mordvintsev Date: Mon, 12 Nov 2012 14:42:51 +0400 Subject: [PATCH 01/10] added CV_OUT to StereoVar output paramiter --- modules/contrib/include/opencv2/contrib/contrib.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/contrib/include/opencv2/contrib/contrib.hpp b/modules/contrib/include/opencv2/contrib/contrib.hpp index 1b13fd7f34..0085b0dfe6 100644 --- a/modules/contrib/include/opencv2/contrib/contrib.hpp +++ b/modules/contrib/include/opencv2/contrib/contrib.hpp @@ -583,7 +583,7 @@ namespace cv virtual ~StereoVar(); //! the stereo correspondence operator that computes disparity map for the specified rectified stereo pair - CV_WRAP_AS(compute) virtual void operator()(const Mat& left, const Mat& right, Mat& disp); + CV_WRAP_AS(compute) virtual void operator()(const Mat& left, const Mat& right, CV_OUT Mat& disp); CV_PROP_RW int levels; CV_PROP_RW double pyrScale; From 1e0bff3268af9c03addf60f8dee33064e7122194 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Thu, 15 Nov 2012 11:24:41 +0400 Subject: [PATCH 02/10] Issue #2541 make install does not work for Android build fixed. --- android/libinfo/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/android/libinfo/CMakeLists.txt b/android/libinfo/CMakeLists.txt index f8e8e15afe..028413ec6e 100644 --- a/android/libinfo/CMakeLists.txt +++ b/android/libinfo/CMakeLists.txt @@ -35,5 +35,5 @@ set_target_properties(${the_module} PROPERTIES INSTALL_NAME_DIR lib ) -get_filename_component(lib_name "opencv_info" NAME) -install(FILES "${LIBRARY_OUTPUT_PATH}/${lib_name}" DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main) \ No newline at end of file +get_filename_component(lib_name "libopencv_info.so" NAME) +install(FILES "${LIBRARY_OUTPUT_PATH}/${lib_name}" DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main) From 759863d95cc9ac0f45e5692e7a0a07258f9412d0 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Fri, 16 Nov 2012 17:01:25 +0400 Subject: [PATCH 03/10] Issue #2537 OpenCV Manager doesn't work on Android 4.2 fixed. --- android/scripts/cmake_android_service.sh | 2 +- android/service/engine/AndroidManifest.xml | 4 ++-- android/service/engine/jni/Android.mk | 5 ++--- android/service/engine/jni/Application.mk | 1 + android/service/engine/jni/Tests/Tests.mk | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/android/scripts/cmake_android_service.sh b/android/scripts/cmake_android_service.sh index 3503bb73d3..e0d1222cd0 100755 --- a/android/scripts/cmake_android_service.sh +++ b/android/scripts/cmake_android_service.sh @@ -4,5 +4,5 @@ cd `dirname $0`/.. mkdir -p build_service cd build_service -cmake -DCMAKE_TOOLCHAIN_FILE=../android.toolchain.cmake -DANDROID_STL=stlport_static -DANDROID_STL_FORCE_FEATURES=OFF -DBUILD_ANDROID_SERVICE=ON -DANDROID_SOURCE_TREE=~/Projects/AndroidSource/ServiceStub/ $@ ../.. +cmake -DCMAKE_TOOLCHAIN_FILE=../android.toolchain.cmake -DANDROID_TOOLCHAIN_NAME="arm-linux-androideabi-4.4.3" -DANDROID_STL=stlport_static -DANDROID_STL_FORCE_FEATURES=OFF -DBUILD_ANDROID_SERVICE=ON -DANDROID_SOURCE_TREE=~/Projects/AndroidSource/ServiceStub/ $@ ../.. diff --git a/android/service/engine/AndroidManifest.xml b/android/service/engine/AndroidManifest.xml index b1d6f691c3..1e0652494d 100644 --- a/android/service/engine/AndroidManifest.xml +++ b/android/service/engine/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="21" + android:versionName="2.1" > diff --git a/android/service/engine/jni/Android.mk b/android/service/engine/jni/Android.mk index a33466c5c5..9ab92a2089 100644 --- a/android/service/engine/jni/Android.mk +++ b/android/service/engine/jni/Android.mk @@ -35,7 +35,7 @@ LOCAL_MODULE := libOpenCVEngine LOCAL_LDLIBS += -lz -lbinder -llog -lutils -LOCAL_LDFLAGS += -Wl,-allow-shlib-undefine +LOCAL_LDFLAGS += -Wl,-allow-shlib-undefined include $(BUILD_SHARED_LIBRARY) @@ -74,7 +74,6 @@ LOCAL_CFLAGS += -D__SUPPORT_MIPS LOCAL_MODULE := libOpenCVEngine_jni LOCAL_LDLIBS += -lz -lbinder -llog -lutils -landroid_runtime - LOCAL_SHARED_LIBRARIES = libOpenCVEngine include $(BUILD_SHARED_LIBRARY) @@ -83,4 +82,4 @@ include $(BUILD_SHARED_LIBRARY) # Native test application #--------------------------------------------------------------------- -include $(LOCAL_PATH)/Tests/Tests.mk \ No newline at end of file +#include $(LOCAL_PATH)/Tests/Tests.mk \ No newline at end of file diff --git a/android/service/engine/jni/Application.mk b/android/service/engine/jni/Application.mk index 4230cd26e0..5647110fa2 100644 --- a/android/service/engine/jni/Application.mk +++ b/android/service/engine/jni/Application.mk @@ -2,4 +2,5 @@ APP_ABI := armeabi x86 mips APP_PLATFORM := android-8 APP_STL := stlport_static APP_CPPFLAGS := -fno-rtti -fno-exceptions +NDK_TOOLCHAIN_VERSION=4.4.3 #APP_OPTIM := debug \ No newline at end of file diff --git a/android/service/engine/jni/Tests/Tests.mk b/android/service/engine/jni/Tests/Tests.mk index a436bc2095..4cfe1c16a3 100644 --- a/android/service/engine/jni/Tests/Tests.mk +++ b/android/service/engine/jni/Tests/Tests.mk @@ -36,7 +36,7 @@ LOCAL_CFLAGS += -D__SUPPORT_TEGRA3 LOCAL_CFLAGS += -D__SUPPORT_MIPS #LOCAL_CFLAGS += -D__SUPPORT_ARMEABI_FEATURES -LOCAL_LDFLAGS = -Wl,-allow-shlib-undefined +#LOCAL_LDFLAGS = -Wl,-allow-shlib-undefined LOCAL_MODULE := OpenCVEngineTestApp From 9ca1162be822f4a62d9ff984bb546d0cb389ffd7 Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Mon, 19 Nov 2012 11:43:28 +0400 Subject: [PATCH 04/10] Update URL for TBB download. Update to TBB 4.1 update 1 --- 3rdparty/tbb/CMakeLists.txt | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/3rdparty/tbb/CMakeLists.txt b/3rdparty/tbb/CMakeLists.txt index bf91f4d8b8..1d4748d38c 100644 --- a/3rdparty/tbb/CMakeLists.txt +++ b/3rdparty/tbb/CMakeLists.txt @@ -5,40 +5,46 @@ endif() project(tbb) -# 4.1 - works fine -set(tbb_ver "tbb41_20120718oss") -set(tbb_url "http://threadingbuildingblocks.org/uploads/77/188/4.1/tbb41_20120718oss_src.tgz") -set(tbb_md5 "31b9ec300f3d09da2504d5d882788dd4") +# 4.1 update 1 - works fine +set(tbb_ver "tbb41_20121003oss") +set(tbb_url "http://threadingbuildingblocks.org/sites/default/files/software_releases/source/tbb41_20121003oss_src.tgz") +set(tbb_md5 "2a684fefb855d2d0318d1ef09afa75ff") set(tbb_version_file "version_string.ver") +# 4.1 - works fine +#set(tbb_ver "tbb41_20120718oss") +#set(tbb_url "http://threadingbuildingblocks.org/sites/default/files/software_releases/source/tbb41_20120718oss_src.tgz") +#set(tbb_md5 "31b9ec300f3d09da2504d5d882788dd4") +#set(tbb_version_file "version_string.ver") + # 4.0 update 5 - works fine #set(tbb_ver "tbb40_20120613oss") -#set(tbb_url "http://threadingbuildingblocks.org/uploads/77/187/4.0%20update%205/tbb40_20120613oss_src.tgz") +#set(tbb_url "http://threadingbuildingblocks.org/sites/default/files/software_releases/source/tbb40_20120613oss_src.tgz") #set(tbb_md5 "da01ed74944ec5950cfae3476901a172") #set(tbb_version_file "version_string.ver") # 4.0 update 4 - works fine #set(tbb_ver "tbb40_20120408oss") -#set(tbb_url "http://threadingbuildingblocks.org/uploads/77/185/4.0%20update%204/tbb40_20120408oss_src.tgz") +#set(tbb_url "http://threadingbuildingblocks.org/sites/default/files/software_releases/source/tbb40_20120408oss_src.tgz") #set(tbb_md5 "734b356da7fe0ed308741f3e6018251e") #set(tbb_version_file "version_string.ver") # 4.0 update 3 - build broken #set(tbb_ver "tbb40_20120201oss") -#set(tbb_url "http://threadingbuildingblocks.org/uploads/77/182/4.0%20update%203/tbb40_20120201oss_src.tgz") +#set(tbb_url "http://threadingbuildingblocks.org/sites/default/files/software_releases/source/tbb40_20120201oss_src.tgz") #set(tbb_md5 "4669e7d4adee018de7a7b8b972987218") #set(tbb_version_file "version_string.tmp") # 4.0 update 2 - works fine #set(tbb_ver "tbb40_20111130oss") -#set(tbb_url "http://threadingbuildingblocks.org/uploads/77/180/4.0%20update%202/tbb40_20111130oss_src.tgz") +#set(tbb_url "http://threadingbuildingblocks.org/sites/default/files/software_releases/source/tbb40_20111130oss_src.tgz") #set(tbb_md5 "1e6926b21e865e79772119cd44fc3ad8") #set(tbb_version_file "version_string.tmp") #set(tbb_need_GENERIC_DWORD_LOAD_STORE TRUE) # 4.0 update 1 - works fine #set(tbb_ver "tbb40_20111003oss") -#set(tbb_url "http://threadingbuildingblocks.org/uploads/77/177/4.0%20update%201/tbb40_20111003oss_src.tgz") +#set(tbb_url "http://threadingbuildingblocks.org/sites/default/files/software_releases/source/tbb40_20111003oss_src.tgz") #set(tbb_md5 "7b5d94eb35a563b29ef402e0fd8f15c9") #set(tbb_version_file "version_string.tmp") #set(tbb_need_GENERIC_DWORD_LOAD_STORE TRUE) From 1f1d43fc88e97f10449fd2cfcbe761aa9c174eb4 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Mon, 19 Nov 2012 12:58:17 +0400 Subject: [PATCH 05/10] Issue #2548 Missing static library libtbb.a for armeabi and mips build fixed. --- cmake/OpenCVGenAndroidMK.cmake | 6 ++++++ cmake/templates/OpenCV.mk.in | 18 ++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/cmake/OpenCVGenAndroidMK.cmake b/cmake/OpenCVGenAndroidMK.cmake index 04ebdb7592..5b11afc17b 100644 --- a/cmake/OpenCVGenAndroidMK.cmake +++ b/cmake/OpenCVGenAndroidMK.cmake @@ -71,6 +71,12 @@ if(ANDROID) endforeach() string(REPLACE "opencv_" "" OPENCV_MODULES_CONFIGMAKE "${OPENCV_MODULES_CONFIGMAKE}") + # prepare 3rd-party component list without TBB for armeabi and mips platforms. TBB is useless there. + set(OPENCV_3RDPARTY_COMPONENTS_CONFIGMAKE_NO_TBB ${OPENCV_3RDPARTY_COMPONENTS_CONFIGMAKE}) + foreach(mod ${OPENCV_3RDPARTY_COMPONENTS_CONFIGMAKE_NO_TBB}) + string(REPLACE "tbb" "" OPENCV_3RDPARTY_COMPONENTS_CONFIGMAKE_NO_TBB "${OPENCV_3RDPARTY_COMPONENTS_CONFIGMAKE_NO_TBB}") + endforeach() + if(BUILD_FAT_JAVA_LIB) set(OPENCV_LIBS_CONFIGMAKE java) else() diff --git a/cmake/templates/OpenCV.mk.in b/cmake/templates/OpenCV.mk.in index 32ab27fb62..d52f75b915 100644 --- a/cmake/templates/OpenCV.mk.in +++ b/cmake/templates/OpenCV.mk.in @@ -29,8 +29,22 @@ ifeq ($(OPENCV_LIB_TYPE),SHARED) OPENCV_3RDPARTY_COMPONENTS:= OPENCV_EXTRA_COMPONENTS:= else - OPENCV_3RDPARTY_COMPONENTS:=@OPENCV_3RDPARTY_COMPONENTS_CONFIGMAKE@ - OPENCV_EXTRA_COMPONENTS:=@OPENCV_EXTRA_COMPONENTS_CONFIGMAKE@ + ifeq ($(TARGET_ARCH_ABI),armeabi-v7a) + OPENCV_3RDPARTY_COMPONENTS:=@OPENCV_3RDPARTY_COMPONENTS_CONFIGMAKE@ + OPENCV_EXTRA_COMPONENTS:=@OPENCV_EXTRA_COMPONENTS_CONFIGMAKE@ + endif + ifeq ($(TARGET_ARCH_ABI),x86) + OPENCV_3RDPARTY_COMPONENTS:=@OPENCV_3RDPARTY_COMPONENTS_CONFIGMAKE@ + OPENCV_EXTRA_COMPONENTS:=@OPENCV_EXTRA_COMPONENTS_CONFIGMAKE@ + endif + ifeq ($(TARGET_ARCH_ABI),armeabi) + OPENCV_3RDPARTY_COMPONENTS:=@OPENCV_3RDPARTY_COMPONENTS_CONFIGMAKE_NO_TBB@ + OPENCV_EXTRA_COMPONENTS:=@OPENCV_EXTRA_COMPONENTS_CONFIGMAKE@ + endif + ifeq ($(TARGET_ARCH_ABI),mips) + OPENCV_3RDPARTY_COMPONENTS:=@OPENCV_3RDPARTY_COMPONENTS_CONFIGMAKE_NO_TBB@ + OPENCV_EXTRA_COMPONENTS:=@OPENCV_EXTRA_COMPONENTS_CONFIGMAKE@ + endif endif ifeq (${OPENCV_CAMERA_MODULES},on) From 66a1ea7604d0043343eba3feecfe9b2ccd027e13 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Tue, 20 Nov 2012 10:45:46 +0400 Subject: [PATCH 06/10] Test execution inside Eclipse fixed; OpenCV testing via OpenCV Manager implemented. --- .../src/org/opencv/test/OpenCVTestCase.java | 17 +++++- .../src/org/opencv/test/OpenCVTestRunner.java | 59 ++++++++++++++----- .../opencv/test/highgui/VideoCaptureTest.java | 31 ++++------ 3 files changed, 70 insertions(+), 37 deletions(-) diff --git a/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java b/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java index 102adf1958..b24d858ee3 100644 --- a/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java +++ b/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java @@ -23,15 +23,20 @@ import org.opencv.features2d.DMatch; import org.opencv.features2d.KeyPoint; import org.opencv.highgui.Highgui; -public class OpenCVTestCase extends TestCase { +import android.util.Log; +public class OpenCVTestCase extends TestCase { //change to 'true' to unblock fail on fail("Not yet implemented") public static final boolean passNYI = true; + protected static boolean isTestCaseEnabled = true; + protected static final int matSize = 10; protected static final double EPS = 0.001; protected static final double weakEPS = 0.5; + private static final String TAG = "OpenCVTestCase"; + protected Mat dst; protected Mat truth; @@ -173,6 +178,16 @@ public class OpenCVTestCase extends TestCase { super.tearDown(); } + @Override + protected void runTest() throws Throwable { + // Do nothing if the precondition does not hold. + if (isTestCaseEnabled) { + super.runTest(); + } else { + Log.e(TAG, "Test case \"" + this.getClass().getName() + "\" disabled!"); + } + } + protected Mat getMat(int type, double... vals) { return new Mat(matSize, matSize, type, new Scalar(vals)); diff --git a/modules/java/android_test/src/org/opencv/test/OpenCVTestRunner.java b/modules/java/android_test/src/org/opencv/test/OpenCVTestRunner.java index 3c416c5104..2dc4aead8d 100644 --- a/modules/java/android_test/src/org/opencv/test/OpenCVTestRunner.java +++ b/modules/java/android_test/src/org/opencv/test/OpenCVTestRunner.java @@ -2,11 +2,11 @@ package org.opencv.test; import java.io.File; import java.io.IOException; -import java.util.Iterator; - -import junit.framework.TestCase; import junit.framework.Assert; +import org.opencv.android.BaseLoaderCallback; +import org.opencv.android.LoaderCallbackInterface; +import org.opencv.android.OpenCVLoader; import org.opencv.android.Utils; import org.opencv.core.Mat; @@ -23,8 +23,7 @@ import android.util.Log; public class OpenCVTestRunner extends InstrumentationTestRunner { - static { System.loadLibrary("opencv_java"); } - + private static final long MANAGER_TIMEOUT = 3000; public static String LENA_PATH; public static String CHESS_PATH; public static String LBPCASCADE_FRONTALFACE_PATH; @@ -33,6 +32,26 @@ public class OpenCVTestRunner extends InstrumentationTestRunner { private AndroidTestRunner androidTestRunner; private static String TAG = "opencv_test_java"; + private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(getContext()) { + + @Override + public void onManagerConnected(int status) { + switch (status) { + case LoaderCallbackInterface.SUCCESS: + { + Log("OpenCV loaded successfully"); + synchronized (this) { + notify(); + } + } break; + default: + { + super.onManagerConnected(status); + } break; + } + } + }; + public static String getTempFileName(String extension) { File cache = context.getCacheDir(); @@ -59,6 +78,25 @@ public class OpenCVTestRunner extends InstrumentationTestRunner { @Override public void onStart() { + // try to load internal libs + if (!OpenCVLoader.initDebug()) { + // There is no internal OpenCV libs + // Using OpenCV Manager for initialization; + + Log("Internal OpenCV library not found. Using OpenCV Manager for initialization"); + OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, getContext(), mLoaderCallback); + + synchronized (this) { + try { + wait(MANAGER_TIMEOUT); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } else { + Log("OpenCV library found inside test package. Using it!"); + } + context = getContext(); Assert.assertTrue("Context can't be 'null'", context != null); LENA_PATH = Utils.exportResource(context, R.drawable.lena); @@ -72,17 +110,6 @@ public class OpenCVTestRunner extends InstrumentationTestRunner { //List testCases = androidTestRunner.getTestCases(); //Collections.shuffle(testCases); //shuffle the tests order - if(OpenCVTestCase.passNYI) { - // turn off problematic camera tests - Iterator it = androidTestRunner.getTestCases().iterator(); - while (it.hasNext()) { - String name = it.next().toString(); - if (name.contains("VideoCaptureTest")) - it.remove(); - } - } - - super.onStart(); } diff --git a/modules/java/android_test/src/org/opencv/test/highgui/VideoCaptureTest.java b/modules/java/android_test/src/org/opencv/test/highgui/VideoCaptureTest.java index c6901c5e4d..ec7211a294 100644 --- a/modules/java/android_test/src/org/opencv/test/highgui/VideoCaptureTest.java +++ b/modules/java/android_test/src/org/opencv/test/highgui/VideoCaptureTest.java @@ -19,13 +19,13 @@ public class VideoCaptureTest extends OpenCVTestCase { super.setUp(); capture = null; + isTestCaseEnabled = false; isSucceed = false; isOpened = false; } public void testGet() { - try - { + try { capture = new VideoCapture(Highgui.CV_CAP_ANDROID); double frameWidth = capture.get(Highgui.CV_CAP_PROP_FRAME_WIDTH); assertTrue(0 != frameWidth); @@ -35,8 +35,7 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testGetSupportedPreviewSizes() { - try - { + try { capture = new VideoCapture(Highgui.CV_CAP_ANDROID); List sizes = capture.getSupportedPreviewSizes(); assertNotNull(sizes); @@ -68,8 +67,7 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testIsOpenedRealCamera() { - try - { + try { capture = new VideoCapture(Highgui.CV_CAP_ANDROID); isOpened = capture.isOpened(); assertTrue(isOpened); @@ -79,8 +77,7 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testOpen() { - try - { + try { capture = new VideoCapture(); capture.open(Highgui.CV_CAP_ANDROID); isOpened = capture.isOpened(); @@ -91,8 +88,7 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testRead() { - try - { + try { capture = new VideoCapture(Highgui.CV_CAP_ANDROID); isSucceed = capture.read(dst); assertTrue(isSucceed); @@ -104,8 +100,7 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testRelease() { - try - { + try { capture = new VideoCapture(Highgui.CV_CAP_ANDROID); capture.release(); assertFalse(capture.isOpened()); @@ -116,8 +111,7 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testRetrieveMat() { - try - { + try { capture = new VideoCapture(Highgui.CV_CAP_ANDROID); capture.grab(); isSucceed = capture.retrieve(dst); @@ -130,8 +124,7 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testRetrieveMatInt() { - try - { + try { capture = new VideoCapture(Highgui.CV_CAP_ANDROID); capture.grab(); isSucceed = capture.retrieve(dst, Highgui.CV_CAP_ANDROID_GREY_FRAME); @@ -144,8 +137,7 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testSet() { - try - { + try { capture = new VideoCapture(Highgui.CV_CAP_ANDROID); capture.set(Highgui.CV_CAP_PROP_FRAME_WIDTH, 640); capture.set(Highgui.CV_CAP_PROP_FRAME_HEIGHT, 480); @@ -165,8 +157,7 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testVideoCaptureInt() { - try - { + try { capture = new VideoCapture(Highgui.CV_CAP_ANDROID); assertNotNull(capture); assertTrue(capture.isOpened()); From ab9311947ae788852bae893e5b38da4bb67b81a2 Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Thu, 15 Nov 2012 12:44:57 +0400 Subject: [PATCH 07/10] Update Android CMake toolchain for NDK r8c --- android/android.toolchain.cmake | 470 +++++++++++++++++++++----------- 1 file changed, 308 insertions(+), 162 deletions(-) diff --git a/android/android.toolchain.cmake b/android/android.toolchain.cmake index 7ab9668356..25cef0f98b 100644 --- a/android/android.toolchain.cmake +++ b/android/android.toolchain.cmake @@ -1,7 +1,37 @@ +# Copyright (c) 2010-2011, Ethan Rublee +# Copyright (c) 2011-2012, Andrey Kamaev +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. The name of the copyright holders may be used to endorse or promote +# products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + # ------------------------------------------------------------------------------ # Android CMake toolchain file, for use with the Android NDK r5-r8 # Requires cmake 2.6.3 or newer (2.8.5 or newer is recommended). -# See home page: http://code.google.com/p/android-cmake/ +# See home page: https://github.com/taka-no-me/android-cmake # # The file is mantained by the OpenCV project. The latest version can be get at # http://code.opencv.org/projects/opencv/repository/revisions/master/changes/android/android.toolchain.cmake @@ -64,6 +94,20 @@ # ANDROID_NATIVE_API_LEVEL=android-8 - level of Android API compile for. # Option is read-only when standalone toolchain is used. # +# ANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-4.6 - the name of compiler +# toolchain to be used. The list of possible values depends on the NDK +# version. For NDK r8c the possible values are: +# +# * arm-linux-androideabi-4.4.3 +# * arm-linux-androideabi-4.6 +# * arm-linux-androideabi-clang3.1 +# * mipsel-linux-android-4.4.3 +# * mipsel-linux-android-4.6 +# * mipsel-linux-android-clang3.1 +# * x86-4.4.3 +# * x86-4.6 +# * x86-clang3.1 +# # ANDROID_FORCE_ARM_BUILD=OFF - set ON to generate 32-bit ARM instructions # instead of Thumb. Is not available for "x86" (inapplicable) and # "armeabi-v6 with VFP" (is forced to be ON) ABIs. @@ -147,13 +191,9 @@ # under the ${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ANDROID_NDK_ABI_NAME} # (depending on the target ABI). This is convenient for Android packaging. # -# Authors: -# Ethan Rublee ethan.ruble@gmail.com -# Andrey Kamaev andrey.kamaev@itseez.com -# # Change Log: # - initial version December 2010 -# - modified April 2011 +# - April 2011 # [+] added possibility to build with NDK (without standalone toolchain) # [+] support cross-compilation on Windows (native, no cygwin support) # [+] added compiler option to force "char" type to be signed @@ -164,13 +204,13 @@ # [+] EXECUTABLE_OUTPUT_PATH is set by toolchain (required on Windows) # [~] Fixed bug with ANDROID_API_LEVEL variable # [~] turn off SWIG search if it is not found first time -# - modified May 2011 +# - May 2011 # [~] ANDROID_LEVEL is renamed to ANDROID_API_LEVEL # [+] ANDROID_API_LEVEL is detected by toolchain if not specified # [~] added guard to prevent changing of output directories on the first # cmake pass # [~] toolchain exits with error if ARM_TARGET is not recognized -# - modified June 2011 +# - June 2011 # [~] default NDK path is updated for version r5c # [+] variable CMAKE_SYSTEM_PROCESSOR is set based on ARM_TARGET # [~] toolchain install directory is added to linker paths @@ -178,13 +218,13 @@ # [+] added macro find_host_package, find_host_program to search # packages/programs on the host system # [~] fixed path to STL library -# - modified July 2011 +# - July 2011 # [~] fixed options caching # [~] search for all supported NDK versions # [~] allowed spaces in NDK path -# - modified September 2011 +# - September 2011 # [~] updated for NDK r6b -# - modified November 2011 +# - November 2011 # [*] rewritten for NDK r7 # [+] x86 toolchain support (experimental) # [+] added "armeabi-v6 with VFP" ABI for ARMv6 processors. @@ -197,37 +237,37 @@ # [~] ARM_TARGET is renamed to ANDROID_ABI # [~] ARMEABI_NDK_NAME is renamed to ANDROID_NDK_ABI_NAME # [~] ANDROID_API_LEVEL is renamed to ANDROID_NATIVE_API_LEVEL -# - modified January 2012 +# - January 2012 # [+] added stlport_static support (experimental) # [+] added special check for cygwin # [+] filtered out hidden files (starting with .) while globbing inside NDK # [+] automatically applied GLESv2 linkage fix for NDK revisions 5-6 # [+] added ANDROID_GET_ABI_RAWNAME to get NDK ABI names by CMake flags -# - modified February 2012 +# - February 2012 # [+] updated for NDK r7b # [~] fixed cmake try_compile() command # [~] Fix for missing install_name_tool on OS X -# - modified March 2012 +# - March 2012 # [~] fixed incorrect C compiler flags # [~] fixed CMAKE_SYSTEM_PROCESSOR change on ANDROID_ABI change # [+] improved toolchain loading speed # [+] added assembler language support (.S) # [+] allowed preset search paths and extra search suffixes -# - modified April 2012 +# - April 2012 # [+] updated for NDK r7c # [~] fixed most of problems with compiler/linker flags and caching # [+] added option ANDROID_FUNCTION_LEVEL_LINKING -# - modified May 2012 +# - May 2012 # [+] updated for NDK r8 # [+] added mips architecture support -# - modified August 2012 +# - August 2012 # [+] updated for NDK r8b # [~] all intermediate files generated by toolchain are moved to CMakeFiles # [~] libstdc++ and libsupc are removed from explicit link libraries # [+] added CCache support (via NDK_CCACHE environment or cmake variable) # [+] added gold linker support for NDK r8b # [~] fixed mips linker flags for NDK r8b -# - modified September 2012 +# - September 2012 # [+] added NDK release name detection (see ANDROID_NDK_RELEASE) # [+] added support for all C++ runtimes from NDK # (system, gabi++, stlport, gnustl) @@ -235,8 +275,11 @@ # [~] use gold linker as default if available (NDK r8b) # [~] globally turned off rpath # [~] compiler options are aligned with NDK r8b -# - modified October 2012 +# - October 2012 # [~] fixed C++ linking: explicitly link with math library (OpenCV #2426) +# - November 2012 +# [+] updated for NDK r8c +# [+] added support for clang compiler # ------------------------------------------------------------------------------ cmake_minimum_required( VERSION 2.6.3 ) @@ -259,7 +302,7 @@ set( CMAKE_SYSTEM_VERSION 1 ) # rpath makes low sence for Android set( CMAKE_SKIP_RPATH TRUE CACHE BOOL "If set, runtime paths are not added when using shared libraries." ) -set( ANDROID_SUPPORTED_NDK_VERSIONS ${ANDROID_EXTRA_NDK_VERSIONS} -r8b -r8 -r7c -r7b -r7 -r6b -r6 -r5c -r5b -r5 "" ) +set( ANDROID_SUPPORTED_NDK_VERSIONS ${ANDROID_EXTRA_NDK_VERSIONS} -r8c -r8b -r8 -r7c -r7b -r7 -r6b -r6 -r5c -r5b -r5 "" ) if(NOT DEFINED ANDROID_NDK_SEARCH_PATHS) if( CMAKE_HOST_WIN32 ) file( TO_CMAKE_PATH "$ENV{PROGRAMFILES}" ANDROID_NDK_SEARCH_PATHS ) @@ -367,8 +410,8 @@ endmacro() macro( __DETECT_TOOLCHAIN_MACHINE_NAME _var _root ) if( EXISTS "${_root}" ) - file( GLOB __gccExePath "${_root}/bin/*-gcc${TOOL_OS_SUFFIX}" ) - __LIST_FILTER( __gccExePath "bin/[.].*-gcc${TOOL_OS_SUFFIX}$" ) + file( GLOB __gccExePath RELATIVE "${_root}/bin/" "${_root}/bin/*-gcc${TOOL_OS_SUFFIX}" ) + __LIST_FILTER( __gccExePath "^[.].*" ) list( LENGTH __gccExePath __gccExePathsCount ) if( NOT __gccExePathsCount EQUAL 1 AND NOT _CMAKE_IN_TRY_COMPILE ) message( WARNING "Could not determine machine name for compiler from ${_root}" ) @@ -506,55 +549,73 @@ if( BUILD_WITH_STANDALONE_TOOLCHAIN ) elseif( __availableToolchainMachines MATCHES mipsel ) set( __availableToolchainArchs "mipsel" ) endif() - if( ANDROID_COMPILER_VERSION ) - # do not run gcc every time because it is relatevely expencive - set( __availableToolchainCompilerVersions "${ANDROID_COMPILER_VERSION}" ) - else() - execute_process( COMMAND "${ANDROID_STANDALONE_TOOLCHAIN}/bin/${__availableToolchainMachines}-gcc${TOOL_OS_SUFFIX}" --version - OUTPUT_VARIABLE __availableToolchainCompilerVersions OUTPUT_STRIP_TRAILING_WHITESPACE ) - string( REGEX MATCH "[0-9]+[.][0-9]+([.][0-9]+)?" __availableToolchainCompilerVersions "${__availableToolchainCompilerVersions}" ) + execute_process( COMMAND "${ANDROID_STANDALONE_TOOLCHAIN}/bin/${__availableToolchainMachines}-gcc${TOOL_OS_SUFFIX}" -dumpversion + OUTPUT_VARIABLE __availableToolchainCompilerVersions OUTPUT_STRIP_TRAILING_WHITESPACE ) + string( REGEX MATCH "[0-9]+[.][0-9]+([.][0-9]+)?" __availableToolchainCompilerVersions "${__availableToolchainCompilerVersions}" ) + if( EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/bin/clang${TOOL_OS_SUFFIX}" ) + list( APPEND __availableToolchains "standalone-clang" ) + list( APPEND __availableToolchainMachines ${__availableToolchainMachines} ) + list( APPEND __availableToolchainArchs ${__availableToolchainArchs} ) + list( APPEND __availableToolchainCompilerVersions ${__availableToolchainCompilerVersions} ) endif() endif() -# get all the details about NDK -if( BUILD_WITH_ANDROID_NDK ) - file( GLOB ANDROID_SUPPORTED_NATIVE_API_LEVELS RELATIVE "${ANDROID_NDK}/platforms" "${ANDROID_NDK}/platforms/android-*" ) - string( REPLACE "android-" "" ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_SUPPORTED_NATIVE_API_LEVELS}" ) - file( GLOB __availableToolchains RELATIVE "${ANDROID_NDK}/toolchains" "${ANDROID_NDK}/toolchains/*" ) - __LIST_FILTER( __availableToolchains "^[.]" ) - set( __availableToolchainMachines "" ) - set( __availableToolchainArchs "" ) - set( __availableToolchainCompilerVersions "" ) - foreach( __toolchain ${__availableToolchains} ) - __DETECT_TOOLCHAIN_MACHINE_NAME( __machine "${ANDROID_NDK}/toolchains/${__toolchain}/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}" ) +macro( __GLOB_NDK_TOOLCHAINS __availableToolchainsVar ) + foreach( __toolchain ${${__availableToolchainsVar}} ) + if( "${__toolchain}" MATCHES "-clang3[.][0-9]$" AND NOT EXISTS "${ANDROID_NDK}/toolchains/${__toolchain}/prebuilt/" ) + string( REGEX REPLACE "-clang3[.][0-9]$" "-4.6" __gcc_toolchain "${__toolchain}" ) + else() + set( __gcc_toolchain "${__toolchain}" ) + endif() + __DETECT_TOOLCHAIN_MACHINE_NAME( __machine "${ANDROID_NDK}/toolchains/${__gcc_toolchain}/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}" ) if( __machine ) - string( REGEX MATCH "[0-9]+[.][0-9]+([.][0-9]+)?$" __version "${__toolchain}" ) - string( REGEX MATCH "^[^-]+" __arch "${__toolchain}" ) + string( REGEX MATCH "[0-9]+[.][0-9]+([.][0-9]+)?$" __version "${__gcc_toolchain}" ) + string( REGEX MATCH "^[^-]+" __arch "${__gcc_toolchain}" ) list( APPEND __availableToolchainMachines "${__machine}" ) list( APPEND __availableToolchainArchs "${__arch}" ) list( APPEND __availableToolchainCompilerVersions "${__version}" ) else() - list( REMOVE_ITEM __availableToolchains "${__toolchain}" ) + list( REMOVE_ITEM ${__availableToolchainsVar} "${__toolchain}" ) endif() + unset( __gcc_toolchain ) endforeach() +endmacro() + +# get all the details about NDK +if( BUILD_WITH_ANDROID_NDK ) + file( GLOB ANDROID_SUPPORTED_NATIVE_API_LEVELS RELATIVE "${ANDROID_NDK}/platforms" "${ANDROID_NDK}/platforms/android-*" ) + string( REPLACE "android-" "" ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_SUPPORTED_NATIVE_API_LEVELS}" ) + set( __availableToolchains "" ) + set( __availableToolchainMachines "" ) + set( __availableToolchainArchs "" ) + set( __availableToolchainCompilerVersions "" ) + if( ANDROID_TOOLCHAIN_NAME AND EXISTS "${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN_NAME}/" ) + # do not go through all toolchains if we know the name + set( __availableToolchains "${ANDROID_TOOLCHAIN_NAME}" ) + __GLOB_NDK_TOOLCHAINS( __availableToolchains ) + endif() + if( NOT __availableToolchains ) + file( GLOB __availableToolchains RELATIVE "${ANDROID_NDK}/toolchains" "${ANDROID_NDK}/toolchains/*" ) + __LIST_FILTER( __availableToolchains "^[.]" ) + __LIST_FILTER( __availableToolchains "llvm" ) + __GLOB_NDK_TOOLCHAINS( __availableToolchains ) + endif() if( NOT __availableToolchains ) - message( FATAL_ERROR "Could not any working toolchain in the NDK. Probably your Android NDK is broken." ) + message( FATAL_ERROR "Could not find any working toolchain in the NDK. Probably your Android NDK is broken." ) endif() endif() # build list of available ABIs +set( ANDROID_SUPPORTED_ABIS "" ) +set( __uniqToolchainArchNames ${__availableToolchainArchs} ) +list( REMOVE_DUPLICATES __uniqToolchainArchNames ) +list( SORT __uniqToolchainArchNames ) +foreach( __arch ${__uniqToolchainArchNames} ) +list( APPEND ANDROID_SUPPORTED_ABIS ${ANDROID_SUPPORTED_ABIS_${__arch}} ) +endforeach() +unset( __uniqToolchainArchNames ) if( NOT ANDROID_SUPPORTED_ABIS ) - set( ANDROID_SUPPORTED_ABIS "" ) - set( __uniqToolchainArchNames ${__availableToolchainArchs} ) - list( REMOVE_DUPLICATES __uniqToolchainArchNames ) - list( SORT __uniqToolchainArchNames ) - foreach( __arch ${__uniqToolchainArchNames} ) - list( APPEND ANDROID_SUPPORTED_ABIS ${ANDROID_SUPPORTED_ABIS_${__arch}} ) - endforeach() - unset( __uniqToolchainArchNames ) - if( NOT ANDROID_SUPPORTED_ABIS ) - message( FATAL_ERROR "No one of known Android ABIs is supported by this cmake toolchain." ) - endif() +message( FATAL_ERROR "No one of known Android ABIs is supported by this cmake toolchain." ) endif() # choose target ABI @@ -569,33 +630,34 @@ if( __androidAbiIdx EQUAL -1 ) endif() unset( __androidAbiIdx ) -# remember target ABI -set( ANDROID_ABI "${ANDROID_ABI}" CACHE STRING "The target ABI for Android. If arm, then armeabi-v7a is recommended for hardware floating point." FORCE ) - # set target ABI options if( ANDROID_ABI STREQUAL "x86" ) set( X86 true ) set( ANDROID_NDK_ABI_NAME "x86" ) set( ANDROID_ARCH_NAME "x86" ) set( ANDROID_ARCH_FULLNAME "x86" ) + set( ANDROID_LLVM_TRIPLE "i686-none-linux-android" ) set( CMAKE_SYSTEM_PROCESSOR "i686" ) elseif( ANDROID_ABI STREQUAL "mips" ) set( MIPS true ) set( ANDROID_NDK_ABI_NAME "mips" ) set( ANDROID_ARCH_NAME "mips" ) set( ANDROID_ARCH_FULLNAME "mipsel" ) + set( ANDROID_LLVM_TRIPLE "mipsel-none-linux-android" ) set( CMAKE_SYSTEM_PROCESSOR "mips" ) elseif( ANDROID_ABI STREQUAL "armeabi" ) set( ARMEABI true ) set( ANDROID_NDK_ABI_NAME "armeabi" ) set( ANDROID_ARCH_NAME "arm" ) set( ANDROID_ARCH_FULLNAME "arm" ) + set( ANDROID_LLVM_TRIPLE "armv5te-none-linux-androideabi" ) set( CMAKE_SYSTEM_PROCESSOR "armv5te" ) elseif( ANDROID_ABI STREQUAL "armeabi-v6 with VFP" ) set( ARMEABI_V6 true ) set( ANDROID_NDK_ABI_NAME "armeabi" ) set( ANDROID_ARCH_NAME "arm" ) set( ANDROID_ARCH_FULLNAME "arm" ) + set( ANDROID_LLVM_TRIPLE "armv5te-none-linux-androideabi" ) set( CMAKE_SYSTEM_PROCESSOR "armv6" ) # need always fallback to older platform set( ARMEABI true ) @@ -604,12 +666,14 @@ elseif( ANDROID_ABI STREQUAL "armeabi-v7a") set( ANDROID_NDK_ABI_NAME "armeabi-v7a" ) set( ANDROID_ARCH_NAME "arm" ) set( ANDROID_ARCH_FULLNAME "arm" ) + set( ANDROID_LLVM_TRIPLE "armv7-none-linux-androideabi" ) set( CMAKE_SYSTEM_PROCESSOR "armv7-a" ) elseif( ANDROID_ABI STREQUAL "armeabi-v7a with VFPV3" ) set( ARMEABI_V7A true ) set( ANDROID_NDK_ABI_NAME "armeabi-v7a" ) set( ANDROID_ARCH_NAME "arm" ) set( ANDROID_ARCH_FULLNAME "arm" ) + set( ANDROID_LLVM_TRIPLE "armv7-none-linux-androideabi" ) set( CMAKE_SYSTEM_PROCESSOR "armv7-a" ) set( VFPV3 true ) elseif( ANDROID_ABI STREQUAL "armeabi-v7a with NEON" ) @@ -617,6 +681,7 @@ elseif( ANDROID_ABI STREQUAL "armeabi-v7a with NEON" ) set( ANDROID_NDK_ABI_NAME "armeabi-v7a" ) set( ANDROID_ARCH_NAME "arm" ) set( ANDROID_ARCH_FULLNAME "arm" ) + set( ANDROID_LLVM_TRIPLE "armv7-none-linux-androideabi" ) set( CMAKE_SYSTEM_PROCESSOR "armv7-a" ) set( VFPV3 true ) set( NEON true ) @@ -630,12 +695,6 @@ if( CMAKE_BINARY_DIR AND EXISTS "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMa file( APPEND "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeSystem.cmake" "SET(CMAKE_SYSTEM_PROCESSOR \"${CMAKE_SYSTEM_PROCESSOR}\")\n" ) endif() -set( ANDROID_SUPPORTED_ABIS ${ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_FULLNAME}} CACHE INTERNAL "ANDROID_ABI can be changed only to one of these ABIs. Changing to any other ABI requires to reset cmake cache." FORCE ) -if( CMAKE_VERSION VERSION_GREATER "2.8" ) - list( SORT ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_FULLNAME} ) - set_property( CACHE ANDROID_ABI PROPERTY STRINGS ${ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_FULLNAME}} ) -endif() - if( ANDROID_ARCH_NAME STREQUAL "arm" AND NOT ARMEABI_V6 ) __INIT_VARIABLE( ANDROID_FORCE_ARM_BUILD OBSOLETE_FORCE_ARM VALUES OFF ) set( ANDROID_FORCE_ARM_BUILD ${ANDROID_FORCE_ARM_BUILD} CACHE BOOL "Use 32-bit ARM instructions instead of Thumb-1" FORCE ) @@ -648,11 +707,15 @@ endif() if( ANDROID_TOOLCHAIN_NAME ) list( FIND __availableToolchains "${ANDROID_TOOLCHAIN_NAME}" __toolchainIdx ) if( __toolchainIdx EQUAL -1 ) - message( FATAL_ERROR "Previously selected toolchain \"${ANDROID_TOOLCHAIN_NAME}\" is missing. You need to remove CMakeCache.txt and rerun cmake manually to change the toolchain" ) + list( SORT __availableToolchains ) + string( REPLACE ";" "\n * " toolchains_list "${__availableToolchains}" ) + set( toolchains_list " * ${toolchains_list}") + message( FATAL_ERROR "Specified toolchain \"${ANDROID_TOOLCHAIN_NAME}\" is missing in your NDK or broken. Please verify that your NDK is working or select another compiler toolchain. +To configure the toolchain set CMake variable ANDROID_TOOLCHAIN_NAME to one of the following values:\n${toolchains_list}\n" ) endif() list( GET __availableToolchainArchs ${__toolchainIdx} __toolchainArch ) if( NOT __toolchainArch STREQUAL ANDROID_ARCH_FULLNAME ) - message( SEND_ERROR "Previously selected toolchain \"${ANDROID_TOOLCHAIN_NAME}\" is not able to compile binaries for the \"${ANDROID_ARCH_NAME}\" platform." ) + message( SEND_ERROR "Selected toolchain \"${ANDROID_TOOLCHAIN_NAME}\" is not able to compile binaries for the \"${ANDROID_ARCH_NAME}\" platform." ) endif() else() set( __toolchainIdx -1 ) @@ -681,8 +744,7 @@ endif() list( GET __availableToolchains ${__toolchainIdx} ANDROID_TOOLCHAIN_NAME ) list( GET __availableToolchainMachines ${__toolchainIdx} ANDROID_TOOLCHAIN_MACHINE_NAME ) list( GET __availableToolchainCompilerVersions ${__toolchainIdx} ANDROID_COMPILER_VERSION ) -set( ANDROID_TOOLCHAIN_NAME "${ANDROID_TOOLCHAIN_NAME}" CACHE INTERNAL "Name of toolchain used" FORCE ) -set( ANDROID_COMPILER_VERSION "${ANDROID_COMPILER_VERSION}" CACHE INTERNAL "compiler version from selected toolchain" FORCE ) + unset( __toolchainIdx ) unset( __availableToolchains ) unset( __availableToolchainMachines ) @@ -692,38 +754,36 @@ unset( __availableToolchainCompilerVersions ) # choose native API level __INIT_VARIABLE( ANDROID_NATIVE_API_LEVEL ENV_ANDROID_NATIVE_API_LEVEL ANDROID_API_LEVEL ENV_ANDROID_API_LEVEL ANDROID_STANDALONE_TOOLCHAIN_API_LEVEL ANDROID_DEFAULT_NDK_API_LEVEL_${ANDROID_ARCH_NAME} ANDROID_DEFAULT_NDK_API_LEVEL ) string( REGEX MATCH "[0-9]+" ANDROID_NATIVE_API_LEVEL "${ANDROID_NATIVE_API_LEVEL}" ) +# TODO: filter out unsupported levels # validate list( FIND ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_NATIVE_API_LEVEL}" __levelIdx ) if( __levelIdx EQUAL -1 ) message( SEND_ERROR "Specified Android native API level (${ANDROID_NATIVE_API_LEVEL}) is not supported by your NDK/toolchain." ) -endif() -unset( __levelIdx ) -if( BUILD_WITH_ANDROID_NDK ) - __DETECT_NATIVE_API_LEVEL( __realApiLevel "${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}/usr/include/android/api-level.h" ) - if( NOT __realApiLevel EQUAL ANDROID_NATIVE_API_LEVEL ) - message( SEND_ERROR "Specified Android API level (${ANDROID_NATIVE_API_LEVEL}) does not match to the level found (${__realApiLevel}). Probably your copy of NDK is broken." ) +else() + if( BUILD_WITH_ANDROID_NDK ) + __DETECT_NATIVE_API_LEVEL( __realApiLevel "${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}/usr/include/android/api-level.h" ) + if( NOT __realApiLevel EQUAL ANDROID_NATIVE_API_LEVEL ) + message( SEND_ERROR "Specified Android API level (${ANDROID_NATIVE_API_LEVEL}) does not match to the level found (${__realApiLevel}). Probably your copy of NDK is broken." ) + endif() + unset( __realApiLevel ) + endif() + set( ANDROID_NATIVE_API_LEVEL "${ANDROID_NATIVE_API_LEVEL}" CACHE STRING "Android API level for native code" FORCE ) + if( CMAKE_VERSION VERSION_GREATER "2.8" ) + list( SORT ANDROID_SUPPORTED_NATIVE_API_LEVELS ) + set_property( CACHE ANDROID_NATIVE_API_LEVEL PROPERTY STRINGS ${ANDROID_SUPPORTED_NATIVE_API_LEVELS} ) endif() - unset( __realApiLevel ) -endif() -set( ANDROID_NATIVE_API_LEVEL "${ANDROID_NATIVE_API_LEVEL}" CACHE STRING "Android API level for native code" FORCE ) -if( CMAKE_VERSION VERSION_GREATER "2.8" ) - list( SORT ANDROID_SUPPORTED_NATIVE_API_LEVELS ) - set_property( CACHE ANDROID_NATIVE_API_LEVEL PROPERTY STRINGS ${ANDROID_SUPPORTED_NATIVE_API_LEVELS} ) endif() +unset( __levelIdx ) -# setup output directories -set( LIBRARY_OUTPUT_PATH_ROOT ${CMAKE_SOURCE_DIR} CACHE PATH "root for library output, set this to change where android libs are installed to" ) -set( CMAKE_INSTALL_PREFIX "${ANDROID_TOOLCHAIN_ROOT}/user" CACHE STRING "path for installing" ) -if(NOT _CMAKE_IN_TRY_COMPILE) - if( EXISTS "${CMAKE_SOURCE_DIR}/jni/CMakeLists.txt" ) - set( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin/${ANDROID_NDK_ABI_NAME}" CACHE PATH "Output directory for applications" ) - else() - set( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin" CACHE PATH "Output directory for applications" ) - endif() - set( LIBRARY_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ANDROID_NDK_ABI_NAME}" CACHE PATH "path for android libs" ) +# remember target ABI +set( ANDROID_ABI "${ANDROID_ABI}" CACHE STRING "The target ABI for Android. If arm, then armeabi-v7a is recommended for hardware floating point." FORCE ) +if( CMAKE_VERSION VERSION_GREATER "2.8" ) + list( SORT ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_FULLNAME} ) + set_property( CACHE ANDROID_ABI PROPERTY STRINGS ${ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_FULLNAME}} ) endif() + # runtime choice (STL, rtti, exceptions) if( NOT ANDROID_STL ) # honor legacy ANDROID_USE_STLPORT @@ -800,9 +860,84 @@ See https://android.googlesource.com/platform/development.git f907f4f9d4e56ccc80 " ) endif() + +# setup paths and STL for standalone toolchain +if( BUILD_WITH_STANDALONE_TOOLCHAIN ) + set( ANDROID_TOOLCHAIN_ROOT "${ANDROID_STANDALONE_TOOLCHAIN}" ) + set( ANDROID_CLANG_TOOLCHAIN_ROOT "${ANDROID_STANDALONE_TOOLCHAIN}" ) + set( ANDROID_SYSROOT "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot" ) + + if( NOT ANDROID_STL STREQUAL "none" ) + set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}" ) + if( ARMEABI_V7A AND EXISTS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}/bits" ) + list( APPEND ANDROID_STL_INCLUDE_DIRS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}" ) + elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/thumb/bits" ) + list( APPEND ANDROID_STL_INCLUDE_DIRS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/thumb" ) + else() + list( APPEND ANDROID_STL_INCLUDE_DIRS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}" ) + endif() + # always search static GNU STL to get the location of libsupc++.a + if( ARMEABI_V7A AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb/libstdc++.a" ) + set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb" ) + elseif( ARMEABI_V7A AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libstdc++.a" ) + set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}" ) + elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libstdc++.a" ) + set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb" ) + elseif( EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libstdc++.a" ) + set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib" ) + endif() + if( __libstl ) + set( __libsupcxx "${__libstl}/libsupc++.a" ) + set( __libstl "${__libstl}/libstdc++.a" ) + endif() + if( NOT EXISTS "${__libsupcxx}" ) + message( FATAL_ERROR "The required libstdsupc++.a is missing in your standalone toolchain. + Usually it happens because of bug in make-standalone-toolchain.sh script from NDK r7, r7b and r7c. + You need to either upgrade to newer NDK or manually copy + $ANDROID_NDK/sources/cxx-stl/gnu-libstdc++/libs/${ANDROID_NDK_ABI_NAME}/libsupc++.a + to + ${__libsupcxx} + " ) + endif() + if( ANDROID_STL STREQUAL "gnustl_shared" ) + if( ARMEABI_V7A AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libgnustl_shared.so" ) + set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libgnustl_shared.so" ) + elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libgnustl_shared.so" ) + set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libgnustl_shared.so" ) + elseif( EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libgnustl_shared.so" ) + set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libgnustl_shared.so" ) + endif() + endif() + endif() +endif() + +# clang +if( "${ANDROID_TOOLCHAIN_NAME}" STREQUAL "standalone-clang" ) + set( ANDROID_COMPILER_IS_CLANG 1 ) + execute_process( COMMAND "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/clang${TOOL_OS_SUFFIX}" --version OUTPUT_VARIABLE ANDROID_CLANG_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE ) + string( REGEX MATCH "[0-9]+[.][0-9]+" ANDROID_CLANG_VERSION "${ANDROID_CLANG_VERSION}") +elseif( "${ANDROID_TOOLCHAIN_NAME}" MATCHES "-clang3[.][0-9]?$" ) + string( REGEX MATCH "3[.][0-9]$" ANDROID_CLANG_VERSION "${ANDROID_TOOLCHAIN_NAME}") + string( REGEX REPLACE "-clang${ANDROID_CLANG_VERSION}$" "-4.6" ANDROID_GCC_TOOLCHAIN_NAME "${ANDROID_TOOLCHAIN_NAME}" ) + if( NOT EXISTS "${ANDROID_NDK}/toolchains/llvm-${ANDROID_CLANG_VERSION}/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}/bin/clang${TOOL_OS_SUFFIX}" ) + message( FATAL_ERROR "Could not find the " ) + endif() + set( ANDROID_COMPILER_IS_CLANG 1 ) + set( ANDROID_CLANG_TOOLCHAIN_ROOT "${ANDROID_NDK}/toolchains/llvm-${ANDROID_CLANG_VERSION}/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}" ) +else() + set( ANDROID_GCC_TOOLCHAIN_NAME "${ANDROID_TOOLCHAIN_NAME}" ) + unset( ANDROID_COMPILER_IS_CLANG CACHE ) +endif() + +string( REPLACE "." "" _clang_name "clang${ANDROID_CLANG_VERSION}" ) +if( NOT EXISTS "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}${TOOL_OS_SUFFIX}" ) + set( _clang_name "clang" ) +endif() + + # setup paths and STL for NDK if( BUILD_WITH_ANDROID_NDK ) - set( ANDROID_TOOLCHAIN_ROOT "${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN_NAME}/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}" ) + set( ANDROID_TOOLCHAIN_ROOT "${ANDROID_NDK}/toolchains/${ANDROID_GCC_TOOLCHAIN_NAME}/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}" ) set( ANDROID_SYSROOT "${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}" ) if( ANDROID_STL STREQUAL "none" ) @@ -874,54 +1009,6 @@ if( BUILD_WITH_ANDROID_NDK ) endif() endif() -# setup paths and STL for standalone toolchain -if( BUILD_WITH_STANDALONE_TOOLCHAIN ) - set( ANDROID_TOOLCHAIN_ROOT "${ANDROID_STANDALONE_TOOLCHAIN}" ) - set( ANDROID_SYSROOT "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot" ) - - if( NOT ANDROID_STL STREQUAL "none" ) - set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}" ) - if( ARMEABI_V7A AND EXISTS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}/bits" ) - list( APPEND ANDROID_STL_INCLUDE_DIRS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}" ) - elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/thumb/bits" ) - list( APPEND ANDROID_STL_INCLUDE_DIRS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/thumb" ) - else() - list( APPEND ANDROID_STL_INCLUDE_DIRS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}" ) - endif() - # always search static GNU STL to get the location of libsupc++.a - if( ARMEABI_V7A AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb/libstdc++.a" ) - set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb" ) - elseif( ARMEABI_V7A AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libstdc++.a" ) - set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}" ) - elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libstdc++.a" ) - set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb" ) - elseif( EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libstdc++.a" ) - set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib" ) - endif() - if( __libstl ) - set( __libsupcxx "${__libstl}/libsupc++.a" ) - set( __libstl "${__libstl}/libstdc++.a" ) - endif() - if( NOT EXISTS "${__libsupcxx}" ) - message( FATAL_ERROR "The required libstdsupc++.a is missing in your standalone toolchain. - Usually it happens because of bug in make-standalone-toolchain.sh script from NDK r7, r7b and r7c. - You need to either upgrade to newer NDK or manually copy - $ANDROID_NDK/sources/cxx-stl/gnu-libstdc++/libs/${ANDROID_NDK_ABI_NAME}/libsupc++.a - to - ${__libsupcxx} - " ) - endif() - if( ANDROID_STL STREQUAL "gnustl_shared" ) - if( ARMEABI_V7A AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libgnustl_shared.so" ) - set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libgnustl_shared.so" ) - elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libgnustl_shared.so" ) - set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libgnustl_shared.so" ) - elseif( EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libgnustl_shared.so" ) - set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libgnustl_shared.so" ) - endif() - endif() - endif() -endif() # case of shared STL linkage if( ANDROID_STL MATCHES "shared" AND DEFINED __libstl ) @@ -937,6 +1024,7 @@ if( ANDROID_STL MATCHES "shared" AND DEFINED __libstl ) endif() endif() + # ccache support __INIT_VARIABLE( _ndk_ccache NDK_CCACHE ENV_NDK_CCACHE ) if( _ndk_ccache ) @@ -946,16 +1034,27 @@ else() endif() unset( _ndk_ccache ) + # setup the cross-compiler if( NOT CMAKE_C_COMPILER ) if( NDK_CCACHE ) set( CMAKE_C_COMPILER "${NDK_CCACHE}" CACHE PATH "ccache as C compiler" ) set( CMAKE_CXX_COMPILER "${NDK_CCACHE}" CACHE PATH "ccache as C++ compiler" ) - set( CMAKE_C_COMPILER_ARG1 "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "gcc") - set( CMAKE_CXX_COMPILER_ARG1 "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-g++${TOOL_OS_SUFFIX}" CACHE PATH "g++") + if( ANDROID_COMPILER_IS_CLANG ) + set( CMAKE_C_COMPILER_ARG1 "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}${TOOL_OS_SUFFIX}" CACHE PATH "C compiler") + set( CMAKE_CXX_COMPILER_ARG1 "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}++${TOOL_OS_SUFFIX}" CACHE PATH "C++ compiler") + else() + set( CMAKE_C_COMPILER_ARG1 "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "C compiler") + set( CMAKE_CXX_COMPILER_ARG1 "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-g++${TOOL_OS_SUFFIX}" CACHE PATH "C++ compiler") + endif() else() - set( CMAKE_C_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "gcc" ) - set( CMAKE_CXX_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-g++${TOOL_OS_SUFFIX}" CACHE PATH "g++" ) + if( ANDROID_COMPILER_IS_CLANG ) + set( CMAKE_C_COMPILER "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}${TOOL_OS_SUFFIX}" CACHE PATH "C compiler") + set( CMAKE_CXX_COMPILER "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}++${TOOL_OS_SUFFIX}" CACHE PATH "C++ compiler") + else() + set( CMAKE_C_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "C compiler" ) + set( CMAKE_CXX_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-g++${TOOL_OS_SUFFIX}" CACHE PATH "C++ compiler" ) + endif() endif() set( CMAKE_ASM_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "assembler" ) set( CMAKE_STRIP "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-strip${TOOL_OS_SUFFIX}" CACHE PATH "strip" ) @@ -982,15 +1081,22 @@ endif() # Force set compilers because standard identification works badly for us include( CMakeForceCompiler ) CMAKE_FORCE_C_COMPILER( "${CMAKE_C_COMPILER}" GNU ) +if( ANDROID_COMPILER_IS_CLANG ) + set( CMAKE_C_COMPILER_ID Clang) +endif() set( CMAKE_C_PLATFORM_ID Linux ) set( CMAKE_C_SIZEOF_DATA_PTR 4 ) set( CMAKE_C_HAS_ISYSROOT 1 ) set( CMAKE_C_COMPILER_ABI ELF ) CMAKE_FORCE_CXX_COMPILER( "${CMAKE_CXX_COMPILER}" GNU ) +if( ANDROID_COMPILER_IS_CLANG ) + set( CMAKE_CXX_COMPILER_ID Clang) +endif() set( CMAKE_CXX_PLATFORM_ID Linux ) set( CMAKE_CXX_SIZEOF_DATA_PTR 4 ) set( CMAKE_CXX_HAS_ISYSROOT 1 ) set( CMAKE_CXX_COMPILER_ABI ELF ) +set( CMAKE_CXX_SOURCE_FILE_EXTENSIONS cc cp cxx cpp CPP c++ C ) # force ASM compiler (required for CMake < 2.8.5) set( CMAKE_ASM_COMPILER_ID_RUN TRUE ) set( CMAKE_ASM_COMPILER_ID GNU ) @@ -1056,10 +1162,10 @@ if( ARMEABI_V7A ) elseif( VFPV3 ) set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=vfpv3" ) else() - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=vfp" ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=vfpv3-d16" ) endif() elseif( ARMEABI_V6 ) - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv6 -mfloat-abi=softfp -mfpu=vfp" ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv6 -mfloat-abi=softfp -mfpu=vfp" ) # vfp == vfpv2 elseif( ARMEABI ) set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv5te -mtune=xscale -msoft-float" ) endif() @@ -1148,17 +1254,25 @@ if( ANDROID_FUNCTION_LEVEL_LINKING ) set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,--gc-sections" ) endif() -if( ANDROID_GOLD_LINKER AND CMAKE_HOST_UNIX AND (ARMEABI OR ARMEABI_V7A OR X86) AND ANDROID_COMPILER_VERSION VERSION_EQUAL "4.6" ) - set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -fuse-ld=gold" ) -elseif( ANDROID_NDK_RELEASE STREQUAL "r8b" AND ARMEABI AND ANDROID_COMPILER_VERSION VERSION_EQUAL "4.6" AND NOT _CMAKE_IN_TRY_COMPILE ) - message( WARNING "The default bfd linker from arm GCC 4.6 toolchain can fail with 'unresolvable R_ARM_THM_CALL relocation' error message. See https://code.google.com/p/android/issues/detail?id=35342 +if( ANDROID_COMPILER_VERSION VERSION_EQUAL "4.6" ) + if( ANDROID_GOLD_LINKER AND (CMAKE_HOST_UNIX OR ANDROID_NDK_RELEASE STRGREATER "r8b") AND (ARMEABI OR ARMEABI_V7A OR X86) ) + set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -fuse-ld=gold" ) + elseif( ANDROID_NDK_RELEASE STREQUAL "r8c") + set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -fuse-ld=bfd" ) + elseif( ANDROID_NDK_RELEASE STREQUAL "r8b" AND ARMEABI AND NOT _CMAKE_IN_TRY_COMPILE ) + message( WARNING "The default bfd linker from arm GCC 4.6 toolchain can fail with 'unresolvable R_ARM_THM_CALL relocation' error message. See https://code.google.com/p/android/issues/detail?id=35342 On Linux and OS X host platform you can workaround this problem using gold linker (default). - Rerun cmake with -DANDROID_GOLD_LINKER=ON option. + Rerun cmake with -DANDROID_GOLD_LINKER=ON option in case of problems. " ) -endif() + endif() +endif() # version 4.6 if( ANDROID_NOEXECSTACK ) - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -Wa,--noexecstack" ) + if( ANDROID_COMPILER_IS_CLANG ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -Xclang -mnoexecstack" ) + else() + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -Wa,--noexecstack" ) + endif() set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,-z,noexecstack" ) endif() @@ -1166,6 +1280,22 @@ if( ANDROID_RELRO ) set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,-z,relro -Wl,-z,now" ) endif() +if( ANDROID_COMPILER_IS_CLANG ) + set( ANDROID_CXX_FLAGS "-Qunused-arguments ${ANDROID_CXX_FLAGS}" ) + if( ARMEABI_V7A AND NOT ANDROID_FORCE_ARM_BUILD ) + set( ANDROID_CXX_FLAGS_RELEASE "-target thumbv7-none-linux-androideabi ${ANDROID_CXX_FLAGS_RELEASE}" ) + set( ANDROID_CXX_FLAGS_DEBUG "-target ${ANDROID_LLVM_TRIPLE} ${ANDROID_CXX_FLAGS_DEBUG}" ) + else() + set( ANDROID_CXX_FLAGS "-target ${ANDROID_LLVM_TRIPLE} ${ANDROID_CXX_FLAGS}" ) + endif() + if( BUILD_WITH_ANDROID_NDK ) + if(ANDROID_ARCH_NAME STREQUAL "arm" ) + set( ANDROID_CXX_FLAGS "-isystem ${ANDROID_CLANG_TOOLCHAIN_ROOT}/lib/clang/${ANDROID_CLANG_VERSION}/include ${ANDROID_CXX_FLAGS}" ) + endif() + set( ANDROID_CXX_FLAGS "-gcc-toolchain ${ANDROID_TOOLCHAIN_ROOT} ${ANDROID_CXX_FLAGS}" ) + endif() +endif() + # cache flags set( CMAKE_CXX_FLAGS "" CACHE STRING "c++ flags" ) set( CMAKE_C_FLAGS "" CACHE STRING "c flags" ) @@ -1189,9 +1319,9 @@ set( CMAKE_MODULE_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_MODULE_LINKER_FL set( CMAKE_EXE_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}" ) if( MIPS AND BUILD_WITH_ANDROID_NDK AND ANDROID_NDK_RELEASE STREQUAL "r8" ) - set( CMAKE_SHARED_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN_NAME}/mipself.xsc ${CMAKE_SHARED_LINKER_FLAGS}" ) - set( CMAKE_MODULE_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN_NAME}/mipself.xsc ${CMAKE_MODULE_LINKER_FLAGS}" ) - set( CMAKE_EXE_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN_NAME}/mipself.x ${CMAKE_EXE_LINKER_FLAGS}" ) + set( CMAKE_SHARED_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK}/toolchains/${ANDROID_GCC_TOOLCHAIN_NAME}/mipself.xsc ${CMAKE_SHARED_LINKER_FLAGS}" ) + set( CMAKE_MODULE_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK}/toolchains/${ANDROID_GCC_TOOLCHAIN_NAME}/mipself.xsc ${CMAKE_MODULE_LINKER_FLAGS}" ) + set( CMAKE_EXE_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK}/toolchains/${ANDROID_GCC_TOOLCHAIN_NAME}/mipself.x ${CMAKE_EXE_LINKER_FLAGS}" ) endif() # configure rtti @@ -1218,6 +1348,19 @@ endif() include_directories( SYSTEM "${ANDROID_SYSROOT}/usr/include" ${ANDROID_STL_INCLUDE_DIRS} ) link_directories( "${CMAKE_INSTALL_PREFIX}/libs/${ANDROID_NDK_ABI_NAME}" ) +# setup output directories +set( LIBRARY_OUTPUT_PATH_ROOT ${CMAKE_SOURCE_DIR} CACHE PATH "root for library output, set this to change where android libs are installed to" ) +set( CMAKE_INSTALL_PREFIX "${ANDROID_TOOLCHAIN_ROOT}/user" CACHE STRING "path for installing" ) + +if(NOT _CMAKE_IN_TRY_COMPILE) + if( EXISTS "${CMAKE_SOURCE_DIR}/jni/CMakeLists.txt" ) + set( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin/${ANDROID_NDK_ABI_NAME}" CACHE PATH "Output directory for applications" ) + else() + set( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin" CACHE PATH "Output directory for applications" ) + endif() + set( LIBRARY_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ANDROID_NDK_ABI_NAME}" CACHE PATH "path for android libs" ) +endif() + # set these global flags for cmake client scripts to change behavior set( ANDROID True ) set( BUILD_ANDROID True ) @@ -1335,7 +1478,7 @@ endif() # Variables controlling behavior or set by cmake toolchain: # ANDROID_ABI : "armeabi-v7a" (default), "armeabi", "armeabi-v7a with NEON", "armeabi-v7a with VFPV3", "armeabi-v6 with VFP", "x86", "mips" # ANDROID_NATIVE_API_LEVEL : 3,4,5,8,9,14 (depends on NDK version) -# ANDROID_SET_OBSOLETE_VARIABLES : ON/OFF +# ANDROID_STL : gnustl_static/gnustl_shared/stlport_static/stlport_shared/gabi++_static/gabi++_shared/system_re/system/none # ANDROID_FORBID_SYGWIN : ON/OFF # ANDROID_NO_UNDEFINED : ON/OFF # ANDROID_SO_UNDEFINED : OFF/ON (default depends on NDK version) @@ -1343,16 +1486,15 @@ endif() # ANDROID_GOLD_LINKER : ON/OFF # ANDROID_NOEXECSTACK : ON/OFF # ANDROID_RELRO : ON/OFF -# Variables that takes effect only at first run: # ANDROID_FORCE_ARM_BUILD : ON/OFF -# ANDROID_STL : gnustl_static/gnustl_shared/stlport_static/stlport_shared/gabi++_static/gabi++_shared/system_re/system/none # ANDROID_STL_FORCE_FEATURES : ON/OFF -# LIBRARY_OUTPUT_PATH_ROOT : -# NDK_CCACHE : +# ANDROID_SET_OBSOLETE_VARIABLES : ON/OFF # Can be set only at the first run: # ANDROID_NDK # ANDROID_STANDALONE_TOOLCHAIN -# ANDROID_TOOLCHAIN_NAME : "arm-linux-androideabi-4.4.3" or "arm-linux-androideabi-4.6" or "mipsel-linux-android-4.4.3" or "mipsel-linux-android-4.6" or "x86-4.4.3" or "x86-4.6" +# ANDROID_TOOLCHAIN_NAME : the NDK name of compiler toolchain +# LIBRARY_OUTPUT_PATH_ROOT : +# NDK_CCACHE : # Obsolete: # ANDROID_API_LEVEL : superseded by ANDROID_NATIVE_API_LEVEL # ARM_TARGET : superseded by ANDROID_ABI @@ -1375,10 +1517,11 @@ endif() # BUILD_WITH_STANDALONE_TOOLCHAIN : TRUE if standalone toolchain is used # ANDROID_NDK_HOST_SYSTEM_NAME : "windows", "linux-x86" or "darwin-x86" depending on host platform # ANDROID_NDK_ABI_NAME : "armeabi", "armeabi-v7a", "x86" or "mips" depending on ANDROID_ABI -# ANDROID_NDK_RELEASE : one of r5, r5b, r5c, r6, r6b, r7, r7b, r7c, r8, r8b; set only for NDK +# ANDROID_NDK_RELEASE : one of r5, r5b, r5c, r6, r6b, r7, r7b, r7c, r8, r8b, r8c; set only for NDK # ANDROID_ARCH_NAME : "arm" or "x86" or "mips" depending on ANDROID_ABI # ANDROID_SYSROOT : path to the compiler sysroot # TOOL_OS_SUFFIX : "" or ".exe" depending on host platform +# ANDROID_COMPILER_IS_CLANG : TRUE if clang compiler is used # Obsolete: # ARMEABI_NDK_NAME : superseded by ANDROID_NDK_ABI_NAME # @@ -1388,10 +1531,13 @@ endif() # ANDROID_SUPPORTED_ABIS : list of currently allowed values for ANDROID_ABI # ANDROID_TOOLCHAIN_MACHINE_NAME : "arm-linux-androideabi", "arm-eabi" or "i686-android-linux" # ANDROID_TOOLCHAIN_ROOT : path to the top level of toolchain (standalone or placed inside NDK) +# ANDROID_CLANG_TOOLCHAIN_ROOT : path to clang tools # ANDROID_SUPPORTED_NATIVE_API_LEVELS : list of native API levels found inside NDK # ANDROID_STL_INCLUDE_DIRS : stl include paths # ANDROID_RTTI : if rtti is enabled by the runtime # ANDROID_EXCEPTIONS : if exceptions are enabled by the runtime +# ANDROID_GCC_TOOLCHAIN_NAME : read-only, differs from ANDROID_TOOLCHAIN_NAME only if clang is used +# ANDROID_CLANG_VERSION : version of clang compiler if clang is used # # Defaults: # ANDROID_DEFAULT_NDK_API_LEVEL From 04481d9ef487df5e8c80d38dbf1fdeb4a4f81cb0 Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Mon, 19 Nov 2012 15:16:13 +0400 Subject: [PATCH 08/10] Fix Android build with clang compiler --- 3rdparty/libjasper/CMakeLists.txt | 1 + 3rdparty/libjpeg/CMakeLists.txt | 1 + 3rdparty/libtiff/CMakeLists.txt | 1 + 3rdparty/tbb/CMakeLists.txt | 5 +++++ cmake/OpenCVDetectCXXCompiler.cmake | 2 +- modules/contrib/src/detection_based_tracker.cpp | 2 ++ modules/core/include/opencv2/core/core.hpp | 4 ++-- modules/core/include/opencv2/core/operations.hpp | 2 +- samples/android/tutorial-3-native/jni/jni_part.cpp | 2 ++ samples/android/tutorial-4-mixed/jni/jni_part.cpp | 2 ++ 10 files changed, 18 insertions(+), 4 deletions(-) diff --git a/3rdparty/libjasper/CMakeLists.txt b/3rdparty/libjasper/CMakeLists.txt index a6fb71ec57..42855e2a6d 100644 --- a/3rdparty/libjasper/CMakeLists.txt +++ b/3rdparty/libjasper/CMakeLists.txt @@ -24,6 +24,7 @@ if(WIN32 AND NOT MINGW) endif(WIN32 AND NOT MINGW) ocv_warnings_disable(CMAKE_C_FLAGS -Wno-implicit-function-declaration -Wno-uninitialized -Wmissing-prototypes -Wmissing-declarations -Wunused -Wshadow -Wsign-compare) +ocv_warnings_disable(CMAKE_C_FLAGS -Wunused-parameter) # clang ocv_warnings_disable(CMAKE_C_FLAGS /wd4013 /wd4018 /wd4101 /wd4244 /wd4267 /wd4715) # vs2005 if(UNIX) diff --git a/3rdparty/libjpeg/CMakeLists.txt b/3rdparty/libjpeg/CMakeLists.txt index 708e63e25b..b4000a40aa 100644 --- a/3rdparty/libjpeg/CMakeLists.txt +++ b/3rdparty/libjpeg/CMakeLists.txt @@ -26,6 +26,7 @@ if(CMAKE_COMPILER_IS_GNUCXX) endif() ocv_warnings_disable(CMAKE_C_FLAGS -Wcast-align -Wshadow -Wunused) +ocv_warnings_disable(CMAKE_C_FLAGS -Wunused-parameter) # clang set_target_properties(${JPEG_LIBRARY} PROPERTIES OUTPUT_NAME ${JPEG_LIBRARY} diff --git a/3rdparty/libtiff/CMakeLists.txt b/3rdparty/libtiff/CMakeLists.txt index 25ff0d94ed..46fef61c7d 100644 --- a/3rdparty/libtiff/CMakeLists.txt +++ b/3rdparty/libtiff/CMakeLists.txt @@ -89,6 +89,7 @@ endif(WIN32) ocv_warnings_disable(CMAKE_C_FLAGS -Wno-unused-but-set-variable -Wmissing-prototypes -Wmissing-declarations -Wundef -Wunused -Wsign-compare -Wcast-align -Wshadow -Wno-maybe-uninitialized -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast) +ocv_warnings_disable(CMAKE_C_FLAGS -Wunused-parameter) # clang ocv_warnings_disable(CMAKE_CXX_FLAGS -Wmissing-declarations -Wunused-parameter) ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4018 /wd4100 /wd4127 /wd4311 /wd4701 /wd4706) # vs2005 ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4244) # vs2008 diff --git a/3rdparty/tbb/CMakeLists.txt b/3rdparty/tbb/CMakeLists.txt index bf91f4d8b8..2f13949992 100644 --- a/3rdparty/tbb/CMakeLists.txt +++ b/3rdparty/tbb/CMakeLists.txt @@ -123,6 +123,11 @@ add_definitions(-D__TBB_DYNAMIC_LOAD_ENABLED=0 #required -DDO_ITT_NOTIFY=0 #it seems that we don't need these notifications ) +if(ANDROID_COMPILER_IS_CLANG) + add_definitions(-D__TBB_GCC_BUILTIN_ATOMICS_PRESENT=1) + ocv_warnings_disable(CMAKE_CXX_FLAGS -Wmissing-prototypes) +endif() + if(tbb_need_GENERIC_DWORD_LOAD_STORE) #needed by TBB 4.0 update 1,2; fixed in TBB 4.0 update 3 but it has 2 new problems add_definitions(-D__TBB_USE_GENERIC_DWORD_LOAD_STORE=1) diff --git a/cmake/OpenCVDetectCXXCompiler.cmake b/cmake/OpenCVDetectCXXCompiler.cmake index 65edf72ede..d8c00cfdd3 100644 --- a/cmake/OpenCVDetectCXXCompiler.cmake +++ b/cmake/OpenCVDetectCXXCompiler.cmake @@ -54,7 +54,7 @@ endif() # Detect GNU version: # ---------------------------------------------------------------------------- if(CMAKE_COMPILER_IS_GNUCXX) - execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} --version + execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} -dumpversion OUTPUT_VARIABLE CMAKE_OPENCV_GCC_VERSION_FULL OUTPUT_STRIP_TRAILING_WHITESPACE) diff --git a/modules/contrib/src/detection_based_tracker.cpp b/modules/contrib/src/detection_based_tracker.cpp index 5deb3b4186..a1e5dea4de 100644 --- a/modules/contrib/src/detection_based_tracker.cpp +++ b/modules/contrib/src/detection_based_tracker.cpp @@ -1,6 +1,8 @@ #if defined(__linux__) || defined(LINUX) || defined(__APPLE__) || defined(ANDROID) #include "opencv2/contrib/detection_based_tracker.hpp" +#include + #define DEBUGLOGS 1 #ifdef ANDROID diff --git a/modules/core/include/opencv2/core/core.hpp b/modules/core/include/opencv2/core/core.hpp index 561d26b3a4..0454cf4e96 100644 --- a/modules/core/include/opencv2/core/core.hpp +++ b/modules/core/include/opencv2/core/core.hpp @@ -204,11 +204,11 @@ CV_EXPORTS ErrorCallback redirectError( ErrorCallback errCallback, #ifdef __GNUC__ #define CV_Error( code, msg ) cv::error( cv::Exception(code, msg, __func__, __FILE__, __LINE__) ) #define CV_Error_( code, args ) cv::error( cv::Exception(code, cv::format args, __func__, __FILE__, __LINE__) ) -#define CV_Assert( expr ) if((expr)) ; else cv::error( cv::Exception(CV_StsAssert, #expr, __func__, __FILE__, __LINE__) ) +#define CV_Assert( expr ) if(!!(expr)) ; else cv::error( cv::Exception(CV_StsAssert, #expr, __func__, __FILE__, __LINE__) ) #else #define CV_Error( code, msg ) cv::error( cv::Exception(code, msg, "", __FILE__, __LINE__) ) #define CV_Error_( code, args ) cv::error( cv::Exception(code, cv::format args, "", __FILE__, __LINE__) ) -#define CV_Assert( expr ) if((expr)) ; else cv::error( cv::Exception(CV_StsAssert, #expr, "", __FILE__, __LINE__) ) +#define CV_Assert( expr ) if(!!(expr)) ; else cv::error( cv::Exception(CV_StsAssert, #expr, "", __FILE__, __LINE__) ) #endif #ifdef _DEBUG diff --git a/modules/core/include/opencv2/core/operations.hpp b/modules/core/include/opencv2/core/operations.hpp index 847daf8c2d..e3ebe6e675 100644 --- a/modules/core/include/opencv2/core/operations.hpp +++ b/modules/core/include/opencv2/core/operations.hpp @@ -56,7 +56,7 @@ #define CV_XADD(addr,delta) _InterlockedExchangeAdd(const_cast(reinterpret_cast(addr)), delta) #elif defined __GNUC__ - #if defined __clang__ && __clang_major__ >= 3 + #if defined __clang__ && __clang_major__ >= 3 && !defined __ANDROID__ #ifdef __ATOMIC_SEQ_CST #define CV_XADD(addr, delta) __c11_atomic_fetch_add((_Atomic(int)*)(addr), (delta), __ATOMIC_SEQ_CST) #else diff --git a/samples/android/tutorial-3-native/jni/jni_part.cpp b/samples/android/tutorial-3-native/jni/jni_part.cpp index 2448948d1a..fa3c857ab0 100644 --- a/samples/android/tutorial-3-native/jni/jni_part.cpp +++ b/samples/android/tutorial-3-native/jni/jni_part.cpp @@ -8,6 +8,8 @@ using namespace std; using namespace cv; extern "C" { +JNIEXPORT void JNICALL Java_org_opencv_samples_tutorial3_Sample3Native_FindFeatures(JNIEnv*, jobject, jlong addrGray, jlong addrRgba); + JNIEXPORT void JNICALL Java_org_opencv_samples_tutorial3_Sample3Native_FindFeatures(JNIEnv*, jobject, jlong addrGray, jlong addrRgba) { Mat* pMatGr=(Mat*)addrGray; diff --git a/samples/android/tutorial-4-mixed/jni/jni_part.cpp b/samples/android/tutorial-4-mixed/jni/jni_part.cpp index 6b0b48ee86..0c395d629d 100644 --- a/samples/android/tutorial-4-mixed/jni/jni_part.cpp +++ b/samples/android/tutorial-4-mixed/jni/jni_part.cpp @@ -8,6 +8,8 @@ using namespace std; using namespace cv; extern "C" { +JNIEXPORT void JNICALL Java_org_opencv_samples_tutorial4_Sample4Mixed_FindFeatures(JNIEnv*, jobject, jlong addrGray, jlong addrRgba); + JNIEXPORT void JNICALL Java_org_opencv_samples_tutorial4_Sample4Mixed_FindFeatures(JNIEnv*, jobject, jlong addrGray, jlong addrRgba) { Mat* pMatGr=(Mat*)addrGray; From 5b148083fea54d0f5c9b4f06ddb5c77652e72750 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Tue, 20 Nov 2012 17:17:22 +0400 Subject: [PATCH 09/10] Libinfo build fix; Libinfo revision formating fix; HW dependent VersionCode for Manager implemented. --- CMakeLists.txt | 2 +- android/libinfo/info.c | 2 +- android/service/engine/AndroidManifest.xml | 4 ++-- android/service/engine/CMakeLists.txt | 18 ++++++++++++++++++ 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0502fb8995..8707e0155d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -467,7 +467,7 @@ if(BUILD_ANDROID_PACKAGE) add_subdirectory(android/package) endif() -if (ANDROID AND NOT BUILD_ANDROID_SERVICE AND NOT BUILD_ANDROID_PACKAGE AND NOT BUILD_CAMERA_WRAPER) +if (ANDROID) add_subdirectory(android/libinfo) endif() diff --git a/android/libinfo/info.c b/android/libinfo/info.c index f1e5bf01ed..f0c2dd6a28 100644 --- a/android/libinfo/info.c +++ b/android/libinfo/info.c @@ -7,7 +7,7 @@ const char* GetLibraryList(void); JNIEXPORT jstring JNICALL Java_org_opencv_android_StaticHelper_getLibraryList(JNIEnv *, jclass); #define PACKAGE_NAME "org.opencv.lib_v" CVAUX_STR(CV_MAJOR_VERSION) CVAUX_STR(CV_MINOR_VERSION) "_" ANDROID_PACKAGE_PLATFORM -#define PACKAGE_REVISION CVAUX_STR(CV_SUBMINOR_VERSION) CVAUX_STR(ANDROID_PACKAGE_RELEASE) +#define PACKAGE_REVISION CVAUX_STR(CV_SUBMINOR_VERSION) "." CVAUX_STR(ANDROID_PACKAGE_RELEASE) const char* GetPackageName(void) { diff --git a/android/service/engine/AndroidManifest.xml b/android/service/engine/AndroidManifest.xml index 1e0652494d..fdf6303d9a 100644 --- a/android/service/engine/AndroidManifest.xml +++ b/android/service/engine/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="22@ANDROID_PLATFORM_VERSION_CODE@" + android:versionName="2.2" > diff --git a/android/service/engine/CMakeLists.txt b/android/service/engine/CMakeLists.txt index 529aef9bd5..b0d8425ca4 100644 --- a/android/service/engine/CMakeLists.txt +++ b/android/service/engine/CMakeLists.txt @@ -4,6 +4,24 @@ set(JNI_LIB_NAME ${engine} ${engine}_jni) unset(__android_project_chain CACHE) add_android_project(opencv_engine "${CMAKE_CURRENT_SOURCE_DIR}" SDK_TARGET 8 ${ANDROID_SDK_TARGET} IGNORE_JAVA ON) +set(ANDROID_PLATFORM_VERSION_CODE "0") + +if(ARMEABI_V7A) + set(ANDROID_PLATFORM_VERSION_CODE "2") + elseif(ARMEABI_V6) + set(ANDROID_PLATFORM_VERSION_CODE "1") + elseif(ARMEABI) + set(ANDROID_PLATFORM_VERSION_CODE "1") + elseif(X86) + set(ANDROID_PLATFORM_VERSION_CODE "3") + elseif(MIPS) + set(ANDROID_PLATFORM_VERSION_CODE "4") + else() + message(WARNING "Can not automatically determine the value for ANDROID_PLATFORM_VERSION_CODE") + endif() + +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/${ANDROID_MANIFEST_FILE}" "${OpenCV_BINARY_DIR}/android/service/engine/.build/${ANDROID_MANIFEST_FILE}" @ONLY) + link_directories("${ANDROID_SOURCE_TREE}/out/target/product/generic/system/lib" "${ANDROID_SOURCE_TREE}/out/target/product/${ANDROID_PRODUCT}/system/lib" "${ANDROID_SOURCE_TREE}/bin/${ANDROID_ARCH_NAME}") # -D__SUPPORT_ARMEABI_FEATURES key is also available From cfd634ca3e43bd9144dca74c88c828f8d2c96b4d Mon Sep 17 00:00:00 2001 From: Andrey Pavlenko Date: Tue, 20 Nov 2012 18:27:03 +0400 Subject: [PATCH 10/10] Improving compatibility with the latest Android SDK (r21) and NDK (r8c). - Adding Android SDK/ADT r21 compatibility; - fixing stl headers path for new ndk; - fixing native API level for Android projects --- .../java/android_lib/.settings/org.eclipse.jdt.core.prefs | 5 ----- .../android_test/.settings/org.eclipse.jdt.core.prefs | 7 +++---- samples/android/15-puzzle/.project | 2 +- .../15-puzzle/.settings/org.eclipse.jdt.core.prefs | 6 +++--- .../.settings/org.eclipse.jdt.core.prefs | 7 +++---- samples/android/face-detection/.cproject | 8 ++++---- .../face-detection/.settings/org.eclipse.jdt.core.prefs | 7 +++---- samples/android/face-detection/jni/Application.mk | 1 + .../.settings/org.eclipse.jdt.core.prefs | 7 +++---- .../.settings/org.eclipse.jdt.core.prefs | 7 +++---- .../.settings/org.eclipse.jdt.core.prefs | 7 +++---- .../.settings/org.eclipse.jdt.core.prefs | 7 +++---- samples/android/tutorial-3-native/.cproject | 8 ++++---- .../.settings/org.eclipse.jdt.core.prefs | 7 +++---- samples/android/tutorial-3-native/jni/Application.mk | 1 + samples/android/tutorial-4-mixed/.cproject | 8 ++++---- .../tutorial-4-mixed/.settings/org.eclipse.jdt.core.prefs | 7 +++---- samples/android/tutorial-4-mixed/jni/Application.mk | 1 + 18 files changed, 46 insertions(+), 57 deletions(-) delete mode 100644 modules/java/android_lib/.settings/org.eclipse.jdt.core.prefs diff --git a/modules/java/android_lib/.settings/org.eclipse.jdt.core.prefs b/modules/java/android_lib/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 53e0495157..0000000000 --- a/modules/java/android_lib/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,5 +0,0 @@ -#Wed Jun 29 04:36:40 MSD 2011 -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.compliance=1.5 -org.eclipse.jdt.core.compiler.source=1.5 diff --git a/modules/java/android_test/.settings/org.eclipse.jdt.core.prefs b/modules/java/android_test/.settings/org.eclipse.jdt.core.prefs index 53e0495157..b080d2ddc8 100644 --- a/modules/java/android_test/.settings/org.eclipse.jdt.core.prefs +++ b/modules/java/android_test/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,4 @@ -#Wed Jun 29 04:36:40 MSD 2011 eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.compliance=1.5 -org.eclipse.jdt.core.compiler.source=1.5 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/samples/android/15-puzzle/.project b/samples/android/15-puzzle/.project index d9387703f4..e7ad660402 100644 --- a/samples/android/15-puzzle/.project +++ b/samples/android/15-puzzle/.project @@ -1,6 +1,6 @@ - 15-puzzle + OpenCV Sample - 15 puzzle diff --git a/samples/android/15-puzzle/.settings/org.eclipse.jdt.core.prefs b/samples/android/15-puzzle/.settings/org.eclipse.jdt.core.prefs index f77b31c2d2..b080d2ddc8 100644 --- a/samples/android/15-puzzle/.settings/org.eclipse.jdt.core.prefs +++ b/samples/android/15-puzzle/.settings/org.eclipse.jdt.core.prefs @@ -1,4 +1,4 @@ eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.compliance=1.5 -org.eclipse.jdt.core.compiler.source=1.5 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/samples/android/color-blob-detection/.settings/org.eclipse.jdt.core.prefs b/samples/android/color-blob-detection/.settings/org.eclipse.jdt.core.prefs index 53e0495157..b080d2ddc8 100644 --- a/samples/android/color-blob-detection/.settings/org.eclipse.jdt.core.prefs +++ b/samples/android/color-blob-detection/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,4 @@ -#Wed Jun 29 04:36:40 MSD 2011 eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.compliance=1.5 -org.eclipse.jdt.core.compiler.source=1.5 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/samples/android/face-detection/.cproject b/samples/android/face-detection/.cproject index 4b8f95d190..f57ae9006c 100644 --- a/samples/android/face-detection/.cproject +++ b/samples/android/face-detection/.cproject @@ -28,8 +28,8 @@