我们的项目使用了虚幻引擎4.26.2和OpenCV 3.4.0 (是的,我们需要这个旧版本!)目前,我正在尝试将构建Opencv的现有shell脚本转换为Conan菜谱。
在构建最终应用程序之前,一切都很顺利。
问题是,OpenCV和UE都包含了int64
和uint64
的相互冲突的定义。
以及安装目录中的shell脚本补丁OpenCV头,如下所示
补丁文件:
--- opencv2/core/hal/interface.old.h 2019-11-26 12:34:40.260333132 +0300
+++ opencv2/core/hal/interface.h 2019-11-26 17:13:27.232585976 +0300
@@ -58,8 +58,8 @@
# define CV_BIG_INT(n) n##I64
# define CV_BIG_UINT(n) n##UI64
#else
- typedef int64_t int64;
- typedef uint64_t uint64;
+// typedef int64_t int64;
+// typedef uint64_t uint64;
# define CV_BIG_INT(n) n##LL
# define CV_BIG_UINT(n) n##ULL
#endif
和shell脚本的大纲:
git clone --depth=1 https://github.com/opencv/opencv.git -b 3.4.0
git clone --depth=1 https://github.com/opencv/opencv_contrib.git -b 3.4.0
mkdir build
cd build
cmake .. .....
make
make install
patch -N -p4 $INSTALL_DIR/include/opencv2/core/hal/interface.h $SCRIPT_DIR/opencv_02.patch
我怎么能和柯南做同样的事?
这是我的conanfile.py
from conans import ConanFile, CMake, tools
class OpenCVUE4Conan(ConanFile):
name = "opencv-ue4"
version = "3.4.0"
url = ""
description = "OpenCV custom build for UE4"
license = "BSD"
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"
exports_sources = 'patches/cmakes.patch', 'patches/check_function.patch
def requirements(self):
self.requires("ue4util/ue4@adamrehn/profile")
self.requires("zlib/ue4@adamrehn/{}".format(self.channel))
self.requires("UElibPNG/ue4@adamrehn/{}".format(self.channel))
def cmake_flags(self):
flags = [
"-DOPENCV_ENABLE_NONFREE=OFF",
# other flags
]
return flags
def source(self):
self.run("git clone --depth=1 https://github.com/opencv/opencv.git -b {}".format(self.version))
self.run("git clone --depth=1 https://github.com/opencv/opencv_contrib.git -b {}".format(self.version))
def build(self):
# Patch OpenCV to avoid build errors
for p in self.exports_sources:
if p.endswith(".patch"):
tools.patch(base_path='opencv', patch_file=p, fuzz=True)
cmake = CMake(self)
cmake.configure(source_folder="opencv", args=self.cmake_flags())
cmake.build()
cmake.install()
我想,我应该在tools.patch
之后再添加一个cmake.install
调用
发布于 2022-11-15 07:49:42
这是非常明显的:只需在调用tools.patch
之后移动相应的cmake.install()
调用
class OpenCVUE4Conan(ConanFile):
...
# List all patches here, prebuild and post-build, to have them handled by conan
exports_sources = 'patches/cmakes.patch', 'patches/check_function.patch', 'patches/typedefs.patch'
# First two patch CMakeLists.txt and rename one of functions in OpenCV sources.
# Its name `check` conflicts with the macro `check`, defined in UE.
# The last one is listed above.
...
def build(self):
# Patch OpenCV to avoid build errors,
# but skip `typedefs.patch`
tools.patch(base_path='opencv', patch_file='patches/cmakes.patch', fuzz=True)
tools.patch(base_path='opencv', patch_file='patches/check_function.patch', fuzz=True)
cmake = CMake(self)
cmake.configure(source_folder="opencv", args=self.cmake_flags())
cmake.build()
cmake.install()
# Apply "typedefs.patch" based on `package_folder`
tools.patch(base_path=self.package_folder, patch_file="patches/typedefs.patch", fuzz=True)
生成的软件包将只在基于UE的项目中编译,该项目是用虚拟构建工具构建的.
构建OpenCV本身需要注释掉的类型,但之后它们与UE的类似类型冲突。
我已经研究过UE的来源,但还没有找到任何可靠的方法来检测存在冲突的类型。
另一种方法是使用OpenCV在其CMakeLists.txt中定义的宏CMakeLists.txt来检测我们正在构建OpenCV,因此需要这些类型防御。然而,效果是一样的。
https://stackoverflow.com/questions/74433909
复制相似问题