This repository contains demo code for using the Conan packages from the conan-ue4cli repository to build a custom OpenCV package that links against the UE4-bundled versions of zlib and libpng, and then consume the custom-built OpenCV package in a simple UE4 project.
You can find the full details of the conan-ue4cli workflow in this article: http://adamrehn.com/articles/cross-platform-library-integration-in-unreal-engine-4/.
Note that Unreal Engine 4.19.0 or newer is required.
Follow the instructions from the README of the conan-ue4cli repository to generate and install the wrapper packages for the UE4-bundled libraries.
The packages directory contains a Conan recipe for our custom build of OpenCV that uses the UE4-bundled versions of zlib and libpng.
To build the OpenCV package, run python3 ./build.py
from the packages/opencv-ue4
subdirectory.
The project directory contains a simple UE4 test project that consumes the Conan package we created in Step 2. Open the file project/OpenCVDemo/OpenCVDemo.uproject
in the Unreal Editor and allow it to compile the modules for the project.
The build rules for the project are in project/OpenCVDemo/Source/OpenCVDemo/OpenCVDemo.Build.cs. The code in this file invokes conan install
as a child process in the root directory of the project and then parses the JSON output to retrieve the build flags from Conan and pass them to UnrealBuildTool. Under Windows, you will see a command window flash briefly during the build process - this is the Conan command being run by UnrealBuildTool.
Once the project has built, select the map "default.umap" and hit the Play button. The text "3.3.0" should appear in the top-left of the game preview. If you open the level blueprint for the map, you can see that this is the OpenCV version string that is being retrieved and printed.
The source code for the "Get OpenCV Version" blueprint function is in project/OpenCVDemo/Source/OpenCVDemo/OpenCVBlueprint.cpp. It simply includes the OpenCV <opencv2/core/version.hpp>
header and casts the CV_VERSION
macro to an FString
instance.
Example Jenkinsfiles are provided that use the Windows and Linux Docker images from docker-ue4 to build both the custom OpenCV Conan package and the UE4 project that consumes it. Performing an automated build requires a bit of up-front configuration to get working but is extremely straightforward once the required infrastructure is in place.
To get everything up and running:
Follow the instructions in the docker-ue4 repository README to create the Docker images for Unreal Engine 4 that will be used for performing builds. The example Jenkinsfile requires Unreal Engine 4.19.1. Create a Windows Docker image on a Windows host and a Linux Docker image on either a Linux or macOS host (Linux is recommended since a macOS host will require additional configuration to set the appropriate memory and disk limits.) Note that the example code does not currently support Linux containers running under a Windows host.
Next, spin up two Docker containers for the required servers:
docker.bintray.io/jfrog/artifactory-cpp-ce
Docker image.jenkins/jenkins
Docker image. The latest
tag is recommended since a recent version of Jenkins with the latest version of the Pipeline Plugin is required.Run through the setup wizard to configure the Artifactory CE instance. At the end of the wizard, opt to create a Conan repository. This will create a repository called conan-local
that will be used to store the packages produced by the automated build process.
Run through the setup wizard to configure the Jenkins instance. Be sure to install the following plugins:
Configure the Jenkins build agents:
windows-containers
.linux-containers
.Configure the Jenkins credentials related to the Conan repository:
jenkins-conan-server
containing the Conan repository URL (you can find this by selecting conan-local
from the "Set Me Up" section of the web interface of the Artifactory instance.)jenkins-conan-username
containing the administrator username for the Artifactory instance.jenkins-conan-password
containing the administrator password for the Artifactory instance.To build the custom OpenCV Conan package:
https://github.com/adamrehn/ue4-opencv-demo.git
. No credentials are required.packages/opencv-ue4/Jenkinsfile
.To build the UE4 project:
https://github.com/adamrehn/ue4-opencv-demo.git
. No credentials are required.project/OpenCVDemo/Jenkinsfile
.ue4 build
command should be sufficient.