Added cmake file to compile Android native camera wrapper if Android source tree...
authorAndrey Kamaev <no@email>
Fri, 17 Jun 2011 13:52:55 +0000 (13:52 +0000)
committerAndrey Kamaev <no@email>
Fri, 17 Jun 2011 13:52:55 +0000 (13:52 +0000)
CMakeLists.txt
modules/androidcamera/CMakeLists.txt
modules/androidcamera/camera_wrapper/CMakeLists.txt [new file with mode: 0644]
modules/androidcamera/camera_wrapper/camera_wrapper.cpp

index 06bb404..0b328b0 100644 (file)
@@ -863,6 +863,21 @@ if(WIN32)
 endif()
 
 
+############## Android source tree for native camera ###############
+if(ANDROID)
+    SET (ANDROID_SOURCE_TREE "ANDROID_SOURCE_TREE-NOTFOUND" CACHE PATH 
+"Path to Android source tree.
+Set this variable to path to your Android sources to compile
+libnative_camera_rx.x.x.so for your Android")
+    SET(BUILD_ANDROID_CAMERA_WRAPPER OFF)
+    if (ANDROID_SOURCE_TREE)
+        FILE(STRINGS "${ANDROID_SOURCE_TREE}/development/sdk/platform_source.properties" ANDROID_VERSION REGEX "Platform\\.Version=[0-9]+\\.[0-9]+\\.[0-9]+" )
+        string(REGEX REPLACE "Platform\\.Version=([0-9]+\\.[0-9]+\\.[0-9]+)" "\\1" ANDROID_VERSION "${ANDROID_VERSION}")
+        if(NOT "${ANDROID_VERSION}" STREQUAL "")
+            SET(BUILD_ANDROID_CAMERA_WRAPPER ON)
+        endif()
+    endif()
+endif()
 
 ################## Reference Manual ##################
 set(BUILD_DOCS ON CACHE BOOL "Build OpenCV Reference Manual")
@@ -1460,7 +1475,11 @@ message(STATUS "    V4L/V4L2:                   ${HAVE_CAMV4L}/${HAVE_CAMV4L2}")
 endif()
 message(STATUS "    Xine:                       ${HAVE_XINE}")
 if(ANDROID)
-message(STATUS "    AndroidNativeCamera:        build")
+if(BUILD_ANDROID_CAMERA_WRAPPER)
+message(STATUS "    AndroidNativeCamera:        build for Android ${ANDROID_VERSION}")
+else()
+message(STATUS "    AndroidNativeCamera:        use prebuilt libraries")
+endif(BUILD_ANDROID_CAMERA_WRAPPER)
 endif()
 endif() #if(UNIX AND NOT APPLE)
 
index ed0d4d0..ecc4597 100644 (file)
@@ -16,7 +16,7 @@ SET( the_target opencv_androidcamera )
 ADD_LIBRARY( ${the_target} STATIC src/camera_activity.cpp )
 
 if (BUILD_SHARED_LIBS)
-  add_definitions(-DCVAPI_EXPORTS)             
+  add_definitions(-DCVAPI_EXPORTS) 
 endif()
 
 TARGET_LINK_LIBRARIES( ${the_target} ${LIBRARY_DEPS} )
@@ -37,16 +37,18 @@ IF (NOT BUILD_SHARED_LIBS)
     )
 ENDIF()
 
-file(GLOB camera_wrappers "${CMAKE_CURRENT_SOURCE_DIR}/../../3rdparty/lib/libnative_camera_r*.so")
-
-foreach(wrapper ${camera_wrappers})
-  ADD_CUSTOM_COMMAND(
-      TARGET ${the_target}
-      POST_BUILD
-      COMMAND ${CMAKE_COMMAND} -E copy "${wrapper}" "${LIBRARY_OUTPUT_PATH}"
-  )
-  get_filename_component(wrapper_name "${wrapper}" NAME)
-  install(FILES "${LIBRARY_OUTPUT_PATH}/${wrapper_name}"
-        DESTINATION lib
-        COMPONENT main)
-endforeach()
\ No newline at end of file
+if (NOT BUILD_ANDROID_CAMERA_WRAPPER)
+  file(GLOB camera_wrappers "${CMAKE_CURRENT_SOURCE_DIR}/../../3rdparty/lib/libnative_camera_r*.so")
+
+  foreach(wrapper ${camera_wrappers})
+    ADD_CUSTOM_COMMAND(
+        TARGET ${the_target}
+        POST_BUILD
+        COMMAND ${CMAKE_COMMAND} -E copy "${wrapper}" "${LIBRARY_OUTPUT_PATH}"
+    )
+    get_filename_component(wrapper_name "${wrapper}" NAME)
+    install(FILES "${LIBRARY_OUTPUT_PATH}/${wrapper_name}"
+          DESTINATION lib
+          COMPONENT main)
+  endforeach()
+endif()
\ No newline at end of file
diff --git a/modules/androidcamera/camera_wrapper/CMakeLists.txt b/modules/androidcamera/camera_wrapper/CMakeLists.txt
new file mode 100644 (file)
index 0000000..1453f68
--- /dev/null
@@ -0,0 +1,40 @@
+SET (the_target native_camera_r${ANDROID_VERSION})
+
+project(${the_target})
+
+link_directories("${ANDROID_SOURCE_TREE}/out/target/product/generic/system/lib")
+
+INCLUDE_DIRECTORIES(
+       ${ANDROID_SOURCE_TREE}
+       ${ANDROID_SOURCE_TREE}/frameworks/base/include/ui
+       ${ANDROID_SOURCE_TREE}/frameworks/base/include/surfaceflinger
+       ${ANDROID_SOURCE_TREE}/frameworks/base/include/camera
+       ${ANDROID_SOURCE_TREE}/frameworks/base/include/media
+       ${ANDROID_SOURCE_TREE}/frameworks/base/include/camera
+       ${ANDROID_SOURCE_TREE}/frameworks/base/include
+       ${ANDROID_SOURCE_TREE}/system/core/include
+       ${ANDROID_SOURCE_TREE}/hardware/libhardware/include
+       ${ANDROID_SOURCE_TREE}/frameworks/base/native/include
+       )
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-rtti -fno-exceptions" )
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions")
+
+ADD_LIBRARY(${the_target} MODULE camera_wrapper.h camera_wrapper.cpp)
+
+string(REGEX REPLACE "[.]" "_" LIBRARY_DEF ${ANDROID_VERSION})
+add_definitions(-DANDROID_r${LIBRARY_DEF})
+
+target_link_libraries(${the_target} dl m stdc++ utils camera_client ui media binder cutils surfaceflinger_client supc++ log )
+
+SET_TARGET_PROPERTIES(${the_target} PROPERTIES
+                      OUTPUT_NAME "${the_target}"
+                      ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}
+                      RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
+                      )
+
+install(TARGETS ${the_target}
+  RUNTIME DESTINATION bin COMPONENT main
+  ARCHIVE DESTINATION lib COMPONENT main
+  LIBRARY DESTINATION lib COMPONENT main
+  )
\ No newline at end of file
index 2071d6e..0bf10ac 100644 (file)
@@ -6,7 +6,7 @@
 
 #include <camera/CameraHardwareInterface.h>
 #include "camera_wrapper.h"
-#include "../camera_wrapper_connector/camera_properties.h"
+#include "../include/camera_properties.h"
 #include <string>
 
 using namespace android;