Merge pull request #6827 from jtkb:cmake-maven-release
This commit is contained in:
commit
0015a09987
64
platforms/maven/README.md
Normal file
64
platforms/maven/README.md
Normal file
@ -0,0 +1,64 @@
|
||||
# Using Maven to build OpenCV
|
||||
|
||||
This page describes the how to build OpenCV using [Apache Maven](http://maven.apache.org/index.html). The Maven build is simply a wrapper around the existing CMake process but has the additional aims of creating Java OSGi-compatible bundles with included native support and also allow the build to be carried out on RaspberryPi (ARM) architecture. There is nothing preventing using the POM on x86 Linux however.
|
||||
|
||||
The following assumes building on Debian-based Linux platform.
|
||||
|
||||
## Overview
|
||||
The Maven build process aims to:
|
||||
1. Provide a simpler route to build OpenCV and Java bundles.
|
||||
2. Automatically check the required native dependencies.
|
||||
3. Make the Java libraries OSGi compatible.
|
||||
4. Include the native OpenCV native library inside the Java bundle.
|
||||
5. Allow the build to function on x86, x86_64 or amd architectures, Debian-based Linux platform.
|
||||
|
||||
### Starting the build
|
||||
#### Environment variables
|
||||
**Applicability:** All processors.
|
||||
|
||||
The following environment variables must be set otherwise the build will fail and halt:
|
||||
|
||||
* `$JAVA_HOME` (the absolute path to the JDK root directory)
|
||||
* `$ANT_HOME` (the absolute path to the Ant root directory)
|
||||
|
||||
It is recommended that advantage is taken of multiple processor cores to reduce build time. This can be done by setting a MAKEFLAGS environment variable specifying the number of parallel builds e.g.:
|
||||
|
||||
* `$MAKEFLAGS="-j8"`
|
||||
|
||||
However if this flag is not set the build will NOT fail. On a RaspberryPi 2 typical build times are 5 hours with `-j1` (which is the default if `$MAKEFLAGS` is not specified) and a little over 2 hours with `-j4`.
|
||||
|
||||
All of the above environment variables can be set on an ad-hoc basis using 'export'.
|
||||
#### Build Directory
|
||||
**Applicability:** All processors
|
||||
|
||||
By default the following build directories are created.
|
||||
|
||||
`<OpenCV_root_dir>/build`
|
||||
|
||||
`<OpenCV_root_dir>/build/target`
|
||||
|
||||
Under `build` are the standard OpenCV artifacts. Under `build/target` can be found the OSGi compatible Java bundle. When deploying the bundle into an OSGi framework e.g. [Apache Karaf](http://karaf.apache.org/), loading of the native library is automatically taken care of. The standard Java library as created by the CMake process is also available as specified in the existing OpenCV documentation.
|
||||
|
||||
The Maven build is initiated from the directory contain the `pom.xml` file.
|
||||
#### x86 or x86_64 Architecture:
|
||||
Generally all that is required is the standard Maven command:
|
||||
|
||||
`mvn clean install`
|
||||
|
||||
One of the first things the build will do is check the required native dependencies. The Maven build indicates the status of the required dependencies and will fail at this point if any are missing. Install using the package manager e.g. aptitude or apt-get, and restart the build with the above command.
|
||||
|
||||
Once the build succesfully completes the OSGi compatible artifacts are available as described above in 'Build Directory'.
|
||||
|
||||
#### ARM 32-bit Architecture - Raspbian Distribution
|
||||
Similar to the x86 architecture the native dependencies are first checked so install any that are missing, however at the time of writing there are no official `libtbb2` and `libtbb-dev` packages in Raspbian. Version 4.4.3 of Intel's Thread Building Blocks library are available [here](http://www.javatechnics.com/thread-building-blocks-tbb-4-4-3-for-raspbian) as a Raspbian-compatible Debian packages.
|
||||
|
||||
**PLEASE NOTE THESE ARE NOT OFFICIAL RASPBIAN PACKAGES. INSTALL AT YOUR OWN RISK.**
|
||||
|
||||
OpenCV is built using CMake and the Maven build process uses the the [cmake-maven plugin](https://github.com/cmake-maven-project/cmake-maven-project). The cmake-maven plugin by default downloads CMake at build time but unfortunately there is no binary for ARM architecture currently available. As a work around it is possible to use the native CMake (which is checked for availability in the above dependency checks). Assuming all native dependencies are available the build can be started with the following command:
|
||||
|
||||
`mvn clean install -Duse.native.cmake=true`
|
||||
|
||||
Upon a successful build the libraries will be available as described above in 'Build Directory'.
|
||||
|
||||
#### cmake-mave-plugin 3.4.1-b2-SNAPSHOT
|
||||
Should this plugin not be available in Maven central, the source can be found at my GitHub page [here](https://github.com/jtkb/cmake-maven-project), checkout the `raspberrypi` branch and install. On x86 it is a standard Maven build and install command. If building on Raspbian you also need to supply the `-Duse.native.cmake=true` command-line option.
|
263
platforms/maven/pom.xml
Normal file
263
platforms/maven/pom.xml
Normal file
@ -0,0 +1,263 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>opencv.org</groupId>
|
||||
<artifactId>opencv</artifactId>
|
||||
<packaging>bundle</packaging>
|
||||
<version>3.1.0</version>
|
||||
<name>OpenCV</name>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>License Agreement For Open Source Computer Vision Library (3-clause BSD License)</name>
|
||||
<url></url>
|
||||
</license>
|
||||
</licenses>
|
||||
<url>http://opencv.org/</url>
|
||||
<scm>
|
||||
<connection>scm:git:https://github.com/Itseez/opencv.git</connection>
|
||||
<url>https://github.com/Itseez/opencv</url>
|
||||
</scm>
|
||||
<contributors>
|
||||
<contributor>
|
||||
<name>Kerry Billingham</name>
|
||||
<email>contact (at) AvionicEngineers (d0t) c(0)m</email>
|
||||
<organization>Java Technics</organization>
|
||||
<url>www.javatechnics.com</url>
|
||||
</contributor>
|
||||
</contributors>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<build.directory>../../build</build.directory>
|
||||
<nativelibrary.name>libopencv_java${lib.version.string}.so</nativelibrary.name>
|
||||
</properties>
|
||||
<distributionManagement>
|
||||
<snapshotRepository>
|
||||
<id>${repo.name}</id>
|
||||
<url>${repo.url}</url>
|
||||
</snapshotRepository>
|
||||
</distributionManagement>
|
||||
<build>
|
||||
<directory>../../build/target</directory>
|
||||
<outputDirectory>../../build/src</outputDirectory>
|
||||
<sourceDirectory>../../build/src</sourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<configuration>
|
||||
<filesets>
|
||||
<fileset>
|
||||
<directory>${build.directory}</directory>
|
||||
</fileset>
|
||||
</filesets>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.github.maven-nar</groupId>
|
||||
<artifactId>nar-maven-plugin</artifactId>
|
||||
<version>3.3.0</version>
|
||||
<extensions>true</extensions>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>nar-initiliase</id>
|
||||
<phase>validate</phase>
|
||||
<goals>
|
||||
<goal>nar-validate</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.4.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>get-opencv-version</id>
|
||||
<phase>generate-resources</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<executable>bash</executable>
|
||||
<workingDirectory>${project.basedir}/scripts</workingDirectory>
|
||||
<arguments>
|
||||
<argument>properties</argument>
|
||||
<argument>../../../modules/core/include/opencv2/core/version.hpp</argument>
|
||||
<argument>${build.directory}</argument>
|
||||
<argument>build.properties</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>setup-environment</id>
|
||||
<phase>validate</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<executable>bash</executable>
|
||||
<workingDirectory>${project.basedir}/scripts</workingDirectory>
|
||||
<arguments>
|
||||
<argument>deb_package_check</argument>
|
||||
<argument>build-essential</argument>
|
||||
<argument>cmake</argument>
|
||||
<argument>git</argument>
|
||||
<argument>libgtk2.0-dev</argument>
|
||||
<argument>pkg-config</argument>
|
||||
<argument>libavcodec-dev</argument>
|
||||
<argument>libavformat-dev</argument>
|
||||
<argument>libswscale-dev</argument>
|
||||
<argument>python-dev</argument>
|
||||
<argument>python-numpy</argument>
|
||||
<argument>libtbb2</argument>
|
||||
<argument>libtbb-dev</argument>
|
||||
<argument>libjpeg-dev</argument>
|
||||
<argument>libpng12-dev</argument>
|
||||
<argument>libtiff5-dev</argument>
|
||||
<argument>libjasper-dev</argument>
|
||||
<argument>libdc1394-22-dev</argument>
|
||||
<argument>ant</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>properties-maven-plugin</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>set-arch-properties</id>
|
||||
<phase>process-resources</phase>
|
||||
<goals>
|
||||
<goal>read-project-properties</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<files>
|
||||
<file>${build.directory}/build.properties</file>
|
||||
</files>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-enforcer-plugin</artifactId>
|
||||
<version>1.4.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>validate</phase>
|
||||
<id>enforce-os</id>
|
||||
<goals>
|
||||
<goal>enforce</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<rules>
|
||||
<requireOS>
|
||||
<family>unix</family>
|
||||
<message>This POM is written to function on UNIX family of OS.
|
||||
More specifically it should be a Debian flavour of Linux.</message>
|
||||
</requireOS>
|
||||
</rules>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>enforce-environment</id>
|
||||
<goals>
|
||||
<goal>enforce</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<rules>
|
||||
<requireEnvironmentVariable>
|
||||
<variableName>ANT_HOME</variableName>
|
||||
<message>$ANT_HOME is not set. Build may fail.</message>
|
||||
</requireEnvironmentVariable>
|
||||
<requireEnvironmentVariable>
|
||||
<variableName>JAVA_HOME</variableName>
|
||||
<message>$JAVA_HOME is not set. Build WILL fail.</message>
|
||||
</requireEnvironmentVariable>
|
||||
<requireEnvironmentVariable>
|
||||
<level>WARN</level>
|
||||
<variableName>MAKEFLAGS</variableName>
|
||||
<message>No MAKEFLAGS environment variable. Build may be slow.
|
||||
To speed up the build you can try exporting MAKEFLAGS=-jX where X equals the number of parallel builds.</message>
|
||||
</requireEnvironmentVariable>
|
||||
</rules>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<phase>process-resources</phase>
|
||||
<id>check-versions-match</id>
|
||||
<goals>
|
||||
<goal>enforce</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<rules>
|
||||
<requireProperty>
|
||||
<property>project.version</property>
|
||||
<regex>${opencv.version}</regex>
|
||||
<regexMessage>The Maven POM version ${project.version} does not match the extracted OpenCV version ${opencv.version}.</regexMessage>
|
||||
</requireProperty>
|
||||
</rules>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<version>2.3.7</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Export-Package>*</Export-Package>
|
||||
<Bundle-NativeCode>${nativelibrary.name};osname=linux;processor=${osgi.processor}</Bundle-NativeCode>
|
||||
<Include-Resource>${build.directory}/lib/${nativelibrary.name}</Include-Resource>
|
||||
</instructions>
|
||||
<manifestLocation>${build.directory}/manifest</manifestLocation>
|
||||
<niceManifest>true</niceManifest>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.googlecode.cmake-maven-project</groupId>
|
||||
<artifactId>cmake-maven-plugin</artifactId>
|
||||
<version>3.4.1-b2-SNAPSHOT</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>cmake-generate</id>
|
||||
<goals>
|
||||
<goal>generate</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sourcePath>../..</sourcePath>
|
||||
<targetPath>../../build</targetPath>
|
||||
<generator>Unix Makefiles</generator>
|
||||
<options>
|
||||
<option>-DBUILD_SHARED_LIBS:BOOL=OFF</option>
|
||||
</options>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>cmake-compile</id>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<projectDirectory>../../build</projectDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
42
platforms/maven/scripts/deb_package_check
Executable file
42
platforms/maven/scripts/deb_package_check
Executable file
@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
###########################################################################################
|
||||
#
|
||||
# This script checks for the required Debian packages are installed
|
||||
# to build OpenCV.
|
||||
# Commandline parameters:
|
||||
# $@ - These are the names of the packages to check with 'dpkg'
|
||||
#
|
||||
# Returns:
|
||||
# 0 - All packages installed (success)
|
||||
# 1 - One or more packages missing (failure)
|
||||
#
|
||||
# Kerry Billingham <contact (at) avionicengineers (d0t) com>
|
||||
# 20 April 2016
|
||||
#
|
||||
###########################################################################################
|
||||
red=$'\e[1;31m'
|
||||
green=$'\e[1;32m'
|
||||
end=$'\e[0m'
|
||||
check_message="Checking for 'dpkg'"
|
||||
dpkg -? &>/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
printf "%-80s%s\n" "${check_message}" "${red} MISSING.${end}"
|
||||
exit 1
|
||||
else
|
||||
printf "%-80s%s\n" "${check_message}" "${green} INSTALLED.${end}"
|
||||
fi
|
||||
|
||||
declare -i packageMissing=0
|
||||
packageArray=( "$@" )
|
||||
for package in ${packageArray[@]}; do
|
||||
check_message="Checking for package ${package}"
|
||||
dpkg -s ${package} &>/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
printf "%-80s%s\n" "${check_message}" "${red} MISSING.${end}"
|
||||
packageMissing=1
|
||||
else
|
||||
printf "%-80s%s\n" "${check_message}" "${green} INSTALLED.${end}"
|
||||
fi
|
||||
done
|
||||
|
||||
exit $packageMissing
|
90
platforms/maven/scripts/properties
Executable file
90
platforms/maven/scripts/properties
Executable file
@ -0,0 +1,90 @@
|
||||
#!/bin/bash
|
||||
#####################################################################
|
||||
# This script extracts several properties and then writes them to a
|
||||
# to a file, 'build.properties'. These properties include:
|
||||
#
|
||||
# 1. OpenCV version.
|
||||
# 2. OpenVC version as a string for use by Maven.
|
||||
# 3. The CPU binary word size.
|
||||
# 4. Architecture string.
|
||||
# 4. OSGi compatible CPU architecture string.
|
||||
#
|
||||
# There is no need to execute this script directly as it will be
|
||||
# called during the Maven build process.
|
||||
#
|
||||
# Command-line parameters:
|
||||
# $1 - Absolute path to the file containing Open CV version
|
||||
# $2 - The build directory and where the output file will be written
|
||||
# $3 - The name of the output file to write to.
|
||||
#
|
||||
# Returns:
|
||||
# 0 - Successfully written the properties file.
|
||||
# 1 - Error occured such as build directory does not exist
|
||||
# or OpenCV version could not be determined or an
|
||||
# unexpected error.
|
||||
#
|
||||
# Kerry Billingham <contact (at) avionicengineers (d0t) com>
|
||||
# 20 April 2016
|
||||
#
|
||||
#####################################################################
|
||||
|
||||
majorHashDefine="#define CV_VERSION_MAJOR"
|
||||
minorHashDefine="#define CV_VERSION_MINOR"
|
||||
revisionHashDefine="#define CV_VERSION_REVISION"
|
||||
statusHashDefine="#define CV_VERSION_STATUS"
|
||||
|
||||
#Test build directory exists
|
||||
if [ ! -n "$2" ] || [ ! -d $2 ];then
|
||||
echo "Build directory not specified or does not exist!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -n "$1" ] && [ -e $1 ];then
|
||||
minorVersion=$(grep "${minorHashDefine}" $1 | grep -o ".$")
|
||||
majorVersion=$(grep "${majorHashDefine}" $1 | grep -o ".$")
|
||||
revision=$(grep "${revisionHashDefine}" $1 | grep -o ".$")
|
||||
|
||||
bits=$(getconf LONG_BIT)
|
||||
architecture=$(arch)
|
||||
osgiProcessor="Not Set"
|
||||
|
||||
case ${architecture} in
|
||||
x86*)
|
||||
echo "This is x86 (32 | 64) bit"
|
||||
case ${bits} in
|
||||
32)
|
||||
osgiProcessor="x86"
|
||||
;;
|
||||
64)
|
||||
osgiProcessor="x86_64"
|
||||
;;
|
||||
*)
|
||||
osgiProcessor="Unknown"
|
||||
esac
|
||||
;;
|
||||
arm*)
|
||||
echo "This is ARM"
|
||||
byteOrder=$(lscpu | grep -i "byte order")
|
||||
shopt -s nocasematch
|
||||
if [[ "${byteOrder}" == *little* ]]; then
|
||||
osgiProcessor="arm_le"
|
||||
elif [[ "${byteOrder}}" == *big* ]]; then
|
||||
osgiProcessor="arm_be"
|
||||
fi
|
||||
shopt -u nocasematch
|
||||
;;
|
||||
*)
|
||||
echo "This is unknown architecture"
|
||||
esac
|
||||
|
||||
echo "The version number will be ${majorVersion}.${minorVersion}.${revision}"
|
||||
echo "opencv.version=${majorVersion}.${minorVersion}.${revision}" > ${2}/${3}
|
||||
echo "lib.version.string=${majorVersion}${minorVersion}${revision}" >> ${2}/${3}
|
||||
echo "bits=${bits}" >> ${2}/${3}
|
||||
echo "architecture=$(arch)" >> ${2}/${3}
|
||||
echo "osgi.processor=${osgiProcessor}" >> ${2}/${3}
|
||||
exit 0
|
||||
else
|
||||
echo "Could not locate file $1 to determine versioning."
|
||||
exit 1
|
||||
fi
|
Loading…
Reference in New Issue
Block a user