diff --git a/CMakeLists.txt b/CMakeLists.txt index 787133e97..f14dfe43b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,18 +11,33 @@ set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) -# Add these standard paths to the search paths for FIND_LIBRARY -# to find libraries from these locations first -if(UNIX) - set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} /lib /usr/lib) -endif() +# Following block can broke build in case of cross-compilng +# but CMAKE_CROSSCOMPILING variable will be set only on project(OpenCV) command +# so we will try to detect crosscompiling by presense of CMAKE_TOOLCHAIN_FILE +if(NOT CMAKE_TOOLCHAIN_FILE) + # Add these standard paths to the search paths for FIND_LIBRARY + # to find libraries from these locations first + if(UNIX) + set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} /lib /usr/lib) + endif() -# it _must_ go before PROJECT(OpenCV) in order to work -if(WIN32) - set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Installation Directory") -else() - set(CMAKE_INSTALL_PREFIX "/usr/local" CACHE PATH "Installation Directory") -endif() + # it _must_ go before PROJECT(OpenCV) in order to work + if(WIN32) + set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Installation Directory") + else() + set(CMAKE_INSTALL_PREFIX "/usr/local" CACHE PATH "Installation Directory") + endif() + + if(MSVC) + set(CMAKE_USE_RELATIVE_PATHS ON CACHE INTERNAL "" FORCE) + endif() +endif(NOT CMAKE_TOOLCHAIN_FILE) + +# -------------------------------------------------------------- +# Top level OpenCV project +# -------------------------------------------------------------- +cmake_minimum_required(VERSION 2.4) +project(OpenCV) set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "Configs" FORCE) if(DEFINED CMAKE_BUILD_TYPE) @@ -44,13 +59,6 @@ if(CMAKE_VERBOSE) set(CMAKE_VERBOSE_MAKEFILE 1) endif() -if(MSVC) - set(CMAKE_USE_RELATIVE_PATHS ON CACHE INTERNAL "" FORCE) -endif() - -cmake_minimum_required(VERSION 2.4) -project(OpenCV) - # -------------------------------------------------------------- # Indicate CMake 2.7 and above that we don't want to mix relative # and absolute paths in linker lib lists. @@ -607,15 +615,15 @@ execute_process(COMMAND ${PYTHON_EXECUTABLE} --version OUTPUT_STRIP_TRAILING_WHITESPACE) string(REGEX MATCH "[0-9]+.[0-9]+" PYTHON_VERSION_MAJOR_MINOR "${PYTHON_VERSION_FULL}") -if(UNIX) +if(CMAKE_HOST_UNIX) set(PYTHON_PLUGIN_INSTALL_PATH lib/python${PYTHON_VERSION_MAJOR_MINOR}/site-packages/opencv) - if(APPLE) + if(CMAKE_HOST_APPLE) set(PYTHON_PACKAGES_PATH lib/python${PYTHON_VERSION_MAJOR_MINOR}/site-packages CACHE PATH "Where to install the python packages.") else() #debian based assumed, install to the dist-packages. set(PYTHON_PACKAGES_PATH lib/python${PYTHON_VERSION_MAJOR_MINOR}/dist-packages CACHE PATH "Where to install the python packages.") endif() endif() -if(WIN32) +if(CMAKE_HOST_WIN32) get_filename_component(PYTHON_PATH "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${PYTHON_VERSION_MAJOR_MINOR}\\InstallPath]" ABSOLUTE CACHE) set(PYTHON_PLUGIN_INSTALL_PATH "${PYTHON_PATH}/Lib/site-packages/opencv") set(PYTHON_PACKAGES_PATH "${PYTHON_PATH}/Lib/site-packages") @@ -657,9 +665,7 @@ endif() # Java support # =================================================== if (PYTHON_EXECUTABLE AND ANDROID) - SET(BUILD_JAVA_SUPPORT ON CACHE BOOL "Build with Java support") -else() - SET(BUILD_JAVA_SUPPORT OFF CACHE BOOL "Build with Java support" FORCE) + option(BUILD_JAVA_SUPPORT "Build with Java support" TRUE) endif() if (BUILD_JAVA_SUPPORT AND (BUILD_EXAMPLES OR BUILD_TESTS)) @@ -1464,14 +1470,14 @@ macro(status text) string(LENGTH "${text}" status_text_length) if (status_text_length LESS status_placeholder_length) string(SUBSTRING "${text}${status_placeholder}" 0 ${status_placeholder_length} status_text) - elseif (status_then OR status_else) + elseif (DEFINED status_then OR DEFINED status_else) message(STATUS "${text}") SET(status_text "${status_placeholder}") else() SET(status_text "${text}") endif() - if (status_then OR status_else) + if (DEFINED status_then OR DEFINED status_else) if(${status_cond}) string(REPLACE ";" " " status_then "${status_then}") message(STATUS "${status_text}" "${status_then}") @@ -1535,7 +1541,7 @@ status(" JPEG:" NOT WITH_JPEG OR JPEG_FOUND THEN ${JPEG_FOUND} status(" PNG:" NOT WITH_PNG OR PNG_FOUND THEN ${PNG_FOUND} ELSE build) status(" TIFF:" NOT WITH_TIFF OR TIFF_FOUND THEN ${TIFF_FOUND} ELSE build) status(" JPEG 2000:" NOT WITH_JASPER OR JASPER_FOUND THEN ${JASPER_FOUND} ELSE build) -status(" OpenEXR:" NOT WITH_OPENEXRR OR OPENEXR_FOUND THEN YES ELSE NO) +status(" OpenEXR:" WITH_OPENEXR OR OPENEXR_FOUND THEN YES ELSE NO) status(" OpenNI:" NOT HAVE_OPENNI OR HAVE_OPENNI_PRIME_SENSOR_MODULE THEN NO @@ -1572,22 +1578,9 @@ elseif(WIN32) status(" Video I/O:" HAVE_VIDEOINPUT THEN DirectShow ELSE NO) endif() -# interfaces to other languages -status("") -status(" Interfaces:") -status(" Python:" BUILD_NEW_PYTHON_SUPPORT THEN YES ELSE NO) -status(" Python interpreter:" PYTHON_EXECUTABLE THEN "${PYTHON_EXECUTABLE}" ELSE NO) -status(" Python numpy:" PYTHON_USE_NUMPY THEN YES ELSE "NO (Python interface will not cover OpenCV 2.x API)") -status(" Java:" BUILD_JAVA_SUPPORT THEN YES ELSE NO) - -if(ANDROID) - status(" android tool:" ANDROID_EXECUTABLE THEN "${ANDROID_EXECUTABLE}" ELSE NO) - status(" ant:" ANT_EXECUTABLE THEN "${ANT_EXECUTABLE} (ver ${ANT_VERSION})" ELSE NO) -endif() - # Other third-party libraries status("") -status(" Other third-party dependencies:") +status(" Other third-party libraries:") if(WITH_IPP AND IPP_FOUND) status(" Use IPP:" "${IPP_LATEST_VERSION_STR} [${IPP_LATEST_VERSION_MAJOR}.${IPP_LATEST_VERSION_MINOR}.${IPP_LATEST_VERSION_BUILD}]") @@ -1605,6 +1598,19 @@ endif() status(" Use Cuda:" HAVE_CUDA THEN YES ELSE NO) status(" Use Eigen:" HAVE_EIGEN THEN YES ELSE NO) +# interfaces to other languages +status("") +status(" Interfaces:") +status(" Python:" BUILD_NEW_PYTHON_SUPPORT THEN YES ELSE NO) +status(" Python interpreter:" PYTHON_EXECUTABLE THEN "${PYTHON_EXECUTABLE} (ver ${PYTHON_VERSION_MAJOR_MINOR})" ELSE NO) +status(" Python numpy:" PYTHON_USE_NUMPY THEN YES ELSE "NO (Python interface will not cover OpenCV 2.x API)") +status(" Java:" BUILD_JAVA_SUPPORT THEN YES ELSE NO) + +if(ANDROID) + status(" android tool:" ANDROID_EXECUTABLE THEN "${ANDROID_EXECUTABLE}" ELSE NO) + status(" ant:" ANT_EXECUTABLE THEN "${ANT_EXECUTABLE} (ver ${ANT_VERSION})" ELSE NO) +endif() + # documentation status("") status(" Documentation:") @@ -1634,5 +1640,4 @@ status("") # warn in the case of in-source build if("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}") message(WARNING "The source directory is the same as binary directory. \"make clean\" may damage the source tree") -endif() - +endif() \ No newline at end of file diff --git a/android/android.toolchain.cmake b/android/android.toolchain.cmake index ac6a13620..f48849d24 100644 --- a/android/android.toolchain.cmake +++ b/android/android.toolchain.cmake @@ -97,6 +97,8 @@ # [~] fixed path to STL library # ---------------------------------------------------------------------------- + + # this one is important set( CMAKE_SYSTEM_NAME Linux ) #this one not so much @@ -134,7 +136,7 @@ if( NOT EXISTS ${ANDROID_NDK} ) if( EXISTS ${ANDROID_NDK_DEFAULT_SEARCH_PATH} ) set ( ANDROID_NDK ${ANDROID_NDK_DEFAULT_SEARCH_PATH} ) message( STATUS "Using default path for android NDK ${ANDROID_NDK}" ) - message( STATUS "If you prefer to use a different location, please define the environment variable: ANDROID_NDK" ) + message( STATUS "If you prefer to use a different location, please define the variable: ANDROID_NDK" ) endif() endif() @@ -163,7 +165,7 @@ if( EXISTS ${ANDROID_NDK} ) if( NOT ANDROID_API_LEVEL GREATER 2 ) set( ANDROID_API_LEVEL 8) message( STATUS "Using default android API level android-${ANDROID_API_LEVEL}" ) - message( STATUS "If you prefer to use a different API level, please define the environment variable: ANDROID_API_LEVEL" ) + message( STATUS "If you prefer to use a different API level, please define the variable: ANDROID_API_LEVEL" ) endif() set( ANDROID_NDK_TOOLCHAIN_ROOT "${ANDROID_NDK}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/${NDKSYSTEM}" ) @@ -182,7 +184,7 @@ else() if( NOT EXISTS ${ANDROID_NDK_TOOLCHAIN_ROOT} ) set( ANDROID_NDK_TOOLCHAIN_ROOT ${ANDROID_NDK_TOOLCHAIN_DEFAULT_SEARCH_PATH} ) message( STATUS "Using default path for toolchain ${ANDROID_NDK_TOOLCHAIN_ROOT}" ) - message( STATUS "If you prefer to use a different location, please define the environment variable: ANDROID_NDK_TOOLCHAIN_ROOT" ) + message( STATUS "If you prefer to use a different location, please define the variable: ANDROID_NDK_TOOLCHAIN_ROOT" ) endif() set( ANDROID_NDK_TOOLCHAIN_ROOT ${ANDROID_NDK_TOOLCHAIN_ROOT} CACHE PATH "root of the Android NDK standalone toolchain" FORCE ) @@ -255,12 +257,12 @@ set( LIBRARY_OUTPUT_PATH_ROOT ${CMAKE_SOURCE_DIR} CACHE PATH "root for library o SET( DO_NOT_CHANGE_OUTPUT_PATHS_ON_FIRST_PASS OFF CACHE BOOL "") if( DO_NOT_CHANGE_OUTPUT_PATHS_ON_FIRST_PASS ) if( EXISTS ${CMAKE_SOURCE_DIR}/jni/CMakeLists.txt ) - set( EXECUTABLE_OUTPUT_PATH ${LIBRARY_OUTPUT_PATH_ROOT}/bin/${ARMEABI_NDK_NAME} CACHE PATH "Output directory for applications" FORCE) + set( EXECUTABLE_OUTPUT_PATH ${LIBRARY_OUTPUT_PATH_ROOT}/bin/${ARMEABI_NDK_NAME} CACHE PATH "Output directory for applications") else() - set( EXECUTABLE_OUTPUT_PATH ${LIBRARY_OUTPUT_PATH_ROOT}/bin CACHE PATH "Output directory for applications" FORCE) + 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/${ARMEABI_NDK_NAME} CACHE PATH "path for android libs" FORCE ) - set( CMAKE_INSTALL_PREFIX ${ANDROID_NDK_TOOLCHAIN_ROOT}/user CACHE STRING "path for installing" FORCE ) + set( LIBRARY_OUTPUT_PATH ${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ARMEABI_NDK_NAME} CACHE PATH "path for android libs") + set( CMAKE_INSTALL_PREFIX ${ANDROID_NDK_TOOLCHAIN_ROOT}/user CACHE STRING "path for installing" ) endif() SET( DO_NOT_CHANGE_OUTPUT_PATHS_ON_FIRST_PASS ON CACHE INTERNAL "" FORCE) @@ -352,7 +354,17 @@ macro(find_host_package) set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER ) set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER ) set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER ) - find_package(${ARGN}) + if( CMAKE_HOST_WIN32 ) + SET( WIN32 1 ) + SET( UNIX ) + elseif( CMAKE_HOST_APPLE ) + SET( APPLE 1 ) + SET( UNIX ) + endif() + find_package( ${ARGN} ) + SET( WIN32 ) + SET( APPLE ) + SET( UNIX 1) set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY ) set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) @@ -362,7 +374,17 @@ macro(find_host_program) set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER ) set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER ) set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER ) - find_program(${ARGN}) + if( CMAKE_HOST_WIN32 ) + SET( WIN32 1 ) + SET( UNIX ) + elseif( CMAKE_HOST_APPLE ) + SET( APPLE 1 ) + SET( UNIX ) + endif() + find_program( ${ARGN} ) + SET( WIN32 ) + SET( APPLE ) + SET( UNIX 1) set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY ) set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) diff --git a/android/scripts/build.cmd b/android/scripts/build.cmd index be62d0568..4fd32e26c 100644 --- a/android/scripts/build.cmd +++ b/android/scripts/build.cmd @@ -57,10 +57,10 @@ ECHO ARM_TARGET=%ARM_TARGET% ECHO. IF NOT %BUILD_OPENCV%==1 GOTO other-cmake :opencv-cmake -("%CMAKE_EXE%" -G"MinGW Makefiles" -DARM_TARGET="%ARM_TARGET%" -C "%SOURCE_DIR%\CMakeCache.android.initial.cmake" -DCMAKE_TOOLCHAIN_FILE="%SOURCE_DIR%"\android.toolchain.cmake -DCMAKE_MAKE_PROGRAM="%MAKE_EXE%" "%SOURCE_DIR%\..") && GOTO cmakefin +("%CMAKE_EXE%" -G"MinGW Makefiles" -DARM_TARGET="%ARM_TARGET%" -C "%SOURCE_DIR%\CMakeCache.android.initial.cmake" -DCMAKE_TOOLCHAIN_FILE="%SOURCE_DIR%"\android.toolchain.cmake -DCMAKE_MAKE_PROGRAM="%MAKE_EXE%" %* "%SOURCE_DIR%\..") && GOTO cmakefin ECHO. & ECHO cmake failed & GOTO end :other-cmake -("%CMAKE_EXE%" -G"MinGW Makefiles" -DARM_TARGET="%ARM_TARGET%" -DOpenCV_DIR="%OPENCV_BUILD_DIR%" -DAndroidOpenCV_DIR="%ANDROID_OPENCV_BUILD_DIR%" -DCMAKE_PROGRAM_PATH="%SWIG_DIR%" -DCMAKE_TOOLCHAIN_FILE="%OPENCV_BUILD_DIR%\..\android.toolchain.cmake" -DCMAKE_MAKE_PROGRAM="%MAKE_EXE%" "%SOURCE_DIR%") && GOTO cmakefin +("%CMAKE_EXE%" -G"MinGW Makefiles" -DARM_TARGET="%ARM_TARGET%" -DOpenCV_DIR="%OPENCV_BUILD_DIR%" -DAndroidOpenCV_DIR="%ANDROID_OPENCV_BUILD_DIR%" -DCMAKE_PROGRAM_PATH="%SWIG_DIR%" -DCMAKE_TOOLCHAIN_FILE="%OPENCV_BUILD_DIR%\..\android.toolchain.cmake" -DCMAKE_MAKE_PROGRAM="%MAKE_EXE%" %* "%SOURCE_DIR%") && GOTO cmakefin ECHO. & ECHO cmake failed & GOTO end :cmakefin diff --git a/android/scripts/cmake_android_neon.sh b/android/scripts/cmake_android_neon.sh index 7b29b9f1f..421221049 100644 --- a/android/scripts/cmake_android_neon.sh +++ b/android/scripts/cmake_android_neon.sh @@ -4,5 +4,5 @@ cd `dirname $0`/.. mkdir -p build_neon cd build_neon -cmake -C ../CMakeCache.android.initial.cmake -DARM_TARGET="armeabi-v7a with NEON" -DCMAKE_TOOLCHAIN_FILE=../android.toolchain.cmake ../.. +cmake -C ../CMakeCache.android.initial.cmake -DARM_TARGET="armeabi-v7a with NEON" -DCMAKE_TOOLCHAIN_FILE=../android.toolchain.cmake $@ ../.. diff --git a/modules/androidcamera/src/camera_activity.cpp b/modules/androidcamera/src/camera_activity.cpp index ca612b354..34d8501b6 100644 --- a/modules/androidcamera/src/camera_activity.cpp +++ b/modules/androidcamera/src/camera_activity.cpp @@ -238,7 +238,7 @@ void CameraWrapperConnector::fillListWrapperLibs(const string& folderPath, vecto dp = opendir (folderPath.c_str()); if (dp != NULL) { - while (ep = readdir (dp)) { + while ((ep = readdir (dp))) { const char* cur_name=ep->d_name; if (strstr(cur_name, PREFIX_CAMERA_WRAPPER_LIB)) { listLibs.push_back(cur_name); @@ -261,7 +261,7 @@ std::string CameraWrapperConnector::getPathLibFolder() LOGD("Library base address: %p", dl_info.dli_fbase); char addrBuf[18]; - sprintf(addrBuf, "%x-", dl_info.dli_fbase); + sprintf(addrBuf, "%p-", dl_info.dli_fbase); int addrLength = strlen(addrBuf); char lineBuf[2048];