Skip to content

Commit

Permalink
Improve OpenCV build and use pkg-config (#45)
Browse files Browse the repository at this point in the history
This patchset improves the build of OpenCV and also lets the Makefile
use pkg-config for it.

Signed-off-by: Joakim Roubert <joakimr@axis.com>
  • Loading branch information
joakimr-axis authored Jan 21, 2025
1 parent 1e01f8c commit f9a8ba9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
15 changes: 6 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ RUN case "$ARCH" in \
armv7hf) \
# Source SDK environment to get cross compilation tools
. /opt/axis/acapsdk/environment-setup* && \
# Configure build with CMake
# Configure build
cmake \
-D CMAKE_CXX_COMPILER=${TARGET_PREFIX}g++ \
-D CMAKE_CXX_FLAGS="${CXX#*-g++}" \
Expand All @@ -68,14 +68,12 @@ RUN case "$ARCH" in \
-D ENABLE_NEON=ON \
-D ENABLE_VFPV3=ON \
-D CMAKE_INSTALL_PREFIX="$SDKTARGETSYSROOT"/usr \
$COMMON_CMAKE_FLAGS && \
# Build and install OpenCV
make -j "$(nproc)" install ; \
$COMMON_CMAKE_FLAGS \
;; \
aarch64) \
# Source SDK environment to get cross compilation tools
. /opt/axis/acapsdk/environment-setup* && \
# Configure build with CMake
# Configure build
# No need to set NEON and VFP for aarch64 since they are implicitly
# present in an any standard armv8-a implementation.
cmake \
Expand All @@ -85,15 +83,14 @@ RUN case "$ARCH" in \
-D CMAKE_C_FLAGS="${CC#*-gcc}" \
-D CMAKE_TOOLCHAIN_FILE="$OPENCV_SRC_DIR"/platforms/linux/aarch64-gnu.toolchain.cmake \
-D CMAKE_INSTALL_PREFIX="$SDKTARGETSYSROOT"/usr \
$COMMON_CMAKE_FLAGS && \
# Build and install OpenCV
make -j "$(nproc)" install ; \
$COMMON_CMAKE_FLAGS \
;; \
*) \
printf "Error: '%s' is not a valid value for the ARCH variable\n", "$ARCH"; \
exit 1; \
;; \
esac
RUN cmake --build . -j "$(nproc)" --target install/strip

# open62541
ARG OPEN62541_DIR="$BUILD_DIR"/open62541
Expand All @@ -112,7 +109,7 @@ RUN . /opt/axis/acapsdk/environment-setup* && \
-DBUILD_SHARED_LIBS=ON \
-DUA_ENABLE_NODEMANAGEMENT=ON \
"$OPEN62541_SRC_DIR"
RUN make -j "$(nproc)" install
RUN cmake --build . -j "$(nproc)" --target install/strip

# Copy the built library files to application directory
WORKDIR "$ACAP_BUILD_DIR"/lib
Expand Down
16 changes: 9 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@ TARGET = opcuagaugereader
OBJECTS = $(wildcard $(CURDIR)/src/*.cpp)
RM ?= rm -f

PKGS = gio-2.0 gio-unix-2.0 vdostream open62541 libcurl axparameter
SDK_PKGS = gio-2.0 gio-unix-2.0 vdostream libcurl axparameter
OWN_PKGS = opencv4 open62541

CXXFLAGS += -Os -pipe -std=c++11 -Wall -Werror -Wextra
CXXFLAGS += $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) pkg-config --cflags-only-I $(PKGS))
LDLIBS += $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) pkg-config --libs $(PKGS))
CXXFLAGS += $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) pkg-config --cflags-only-I $(SDK_PKGS))
CXXFLAGS += $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) PKG_CONFIG_SYSROOT_DIR= pkg-config --cflags-only-I $(OWN_PKGS))
LDLIBS += $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) pkg-config --libs $(SDK_PKGS))
LDLIBS += $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) PKG_CONFIG_SYSROOT_DIR= pkg-config --libs $(SDK_PKGS) $(OWN_PKGS))

CXXFLAGS += -I$(SDKTARGETSYSROOT)/usr/include/opencv4 -I$(CURDIR)/include
CXXFLAGS += -I$(CURDIR)/include
LDFLAGS = -L./lib -Wl,--no-as-needed,-rpath,'$$ORIGIN/lib'
LDLIBS += -lm -lopencv_core -lopencv_imgproc -lopencv_video -lpthread
LDLIBS += -lm -lpthread

# Set DEBUG_WRITE to write debug images to storage
ifneq ($(DEBUG_WRITE),)
CXXFLAGS += -DDEBUG_WRITE
LDLIBS += -lopencv_imgcodecs
DOCKER_ARGS += --build-arg DEBUG_WRITE=$(DEBUG_WRITE)
endif

Expand All @@ -29,7 +31,7 @@ $(TARGET): $(OBJECTS)

# docker build container targets
%.eap:
DOCKER_BUILDKIT=1 docker build $(DOCKER_ARGS) --build-arg ARCH=$(basename $@) -o type=local,dest=. "$(CURDIR)"
DOCKER_BUILDKIT=1 docker build $(DOCKER_ARGS) --build-arg ARCH=$(*F) -o type=local,dest=. "$(CURDIR)"

dockerbuild: armv7hf.eap aarch64.eap

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"embeddedSdkVersion": "3.0",
"vendorUrl": "https://www.axis.com/",
"runMode": "respawn",
"version": "2.0.1"
"version": "2.0.2"
},
"configuration": {
"settingPage": "settings.html",
Expand Down

0 comments on commit f9a8ba9

Please sign in to comment.