-
Notifications
You must be signed in to change notification settings - Fork 20
/
Dockerfile
109 lines (96 loc) · 3.92 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
ARG ARCH=armv7hf
ARG REPO=axisecp
ARG SDK=acap-sdk
ARG UBUNTU_VERSION=20.04
ARG VERSION=3.5
FROM ${REPO}/${SDK}:${VERSION}-${ARCH}-ubuntu${UBUNTU_VERSION}
# Set general arguments
ARG ARCH
ARG SDK_LIB_PATH_BASE=/opt/axis/acapsdk/sysroots/${ARCH}/usr
ARG BUILD_DIR=/opt/build
#-------------------------------------------------------------------------------
# Prepare build environment
#-------------------------------------------------------------------------------
# Install build dependencies for cross compiling OpenCV
RUN DEBIAN_FRONTEND=noninteractive \
apt-get update && apt-get install -y -f --no-install-recommends \
cmake && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
#-------------------------------------------------------------------------------
# Build OpenCV libraries
#-------------------------------------------------------------------------------
ARG OPENCV_VERSION=4.5.1
ARG OPENCV_DIR=${BUILD_DIR}/opencv
ARG OPENCV_SRC_DIR=${OPENCV_DIR}/opencv-${OPENCV_VERSION}
ARG OPENCV_BUILD_DIR=${OPENCV_DIR}/build
WORKDIR ${OPENCV_DIR}
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN curl -fsSL https://github.com/opencv/opencv/archive/$OPENCV_VERSION.tar.gz | tar -xz
WORKDIR ${OPENCV_BUILD_DIR}
ENV COMMON_CMAKE_FLAGS="-S $OPENCV_SRC_DIR \
-B $OPENCV_BUILD_DIR \
-D CMAKE_INSTALL_PREFIX=$SDK_LIB_PATH_BASE \
-D CMAKE_BUILD_TYPE=RELEASE \
-D WITH_OPENEXR=OFF \
-D WITH_GTK=OFF \
-D WITH_V4L=OFF \
-D WITH_FFMPEG=OFF \
-D WITH_GSTREAMER=OFF \
-D WITH_GSTREAMER_0_10=OFF \
-D BUILD_LIST=core,imgproc,video \
-D BUILD_EXAMPLES=OFF \
-D BUILD_OPENCV_APPS=OFF \
-D BUILD_DOCS=OFF \
-D BUILD_JPEG=ON \
-D BUILD_PNG=OFF \
-D WITH_JASPER=OFF \
-D BUILD_PROTOBUF=OFF \
-D OPENCV_GENERATE_PKGCONFIG=ON "
# hadolint ignore=SC2086
RUN if [ "$ARCH" = armv7hf ]; then \
# Source SDK environment to get cross compilation tools
. /opt/axis/acapsdk/environment-setup* && \
# Configure build with CMake
cmake \
-D CMAKE_CXX_COMPILER=${CXX%-g++*}-g++ \
-D CMAKE_CXX_FLAGS="${CXX#*-g++}" \
-D CMAKE_C_COMPILER=${CC%-gcc*}-gcc \
-D CMAKE_C_FLAGS="${CC#*-gcc}" \
-D CMAKE_TOOLCHAIN_FILE=${OPENCV_SRC_DIR}/platforms/linux/arm-gnueabi.toolchain.cmake \
-D CPU_BASELINE=NEON,VFPV3 \
-D ENABLE_NEON=ON \
-D ENABLE_VFPV3=ON \
$COMMON_CMAKE_FLAGS && \
# Build and install OpenCV
make -j "$(nproc)" install ; \
elif [ "$ARCH" = aarch64 ]; then \
# Source SDK environment to get cross compilation tools
. /opt/axis/acapsdk/environment-setup* && \
# Configure build with CMake
# No need to set NEON and VFP for aarch64 since they are implicitly
# present in an any standard armv8-a implementation.
cmake \
-D CMAKE_CXX_COMPILER=${CXX%-g++*}-g++ \
-D CMAKE_CXX_FLAGS="${CXX#*-g++}" \
-D CMAKE_C_COMPILER=${CC%-gcc*}-gcc \
-D CMAKE_C_FLAGS="${CC#*-gcc}" \
-D CMAKE_TOOLCHAIN_FILE=${OPENCV_SRC_DIR}/platforms/linux/aarch64-gnu.toolchain.cmake \
$COMMON_CMAKE_FLAGS && \
# Build and install OpenCV
make -j "$(nproc)" install ; \
else \
printf "Error: '%s' is not a valid value for the ARCH variable\n", "$ARCH"; \
exit 1; \
fi
#-------------------------------------------------------------------------------
# Copy the built library files to application directory
#-------------------------------------------------------------------------------
WORKDIR /opt/app
COPY ./app .
RUN mkdir lib && \
cp -P ${OPENCV_BUILD_DIR}/lib/lib*.so* ./lib/
#-------------------------------------------------------------------------------
# Finally build the ACAP application
#-------------------------------------------------------------------------------
RUN . /opt/axis/acapsdk/environment-setup* && acap-build .