Add some lib directories compiler option (#255)

* Add OPENCV_DIRECTORY option to provide the ability to specify the installed opecv lib pat

* Use find_package for opencv in windows, mac and linux

* Fix opencv cmake

* Fix python lib rpath setting

* fix mac python package

* Add some promt when use different opencv lib

* add status message

* Fix the backslash

* Fix python package user defined libs

* Fix windows python process libs

* Add windows lib set path
This commit is contained in:
Jack Zhou
2022-09-21 13:25:56 +08:00
committed by GitHub
parent addce837bc
commit e7f741292e
6 changed files with 83 additions and 155 deletions

View File

@@ -16,6 +16,8 @@ import logging
import os
import sys
user_specified_dirs = ['@OPENCV_DIRECTORY@', ]
def is_built_with_gpu() -> bool:
return True if "@WITH_GPU@" == "ON" else False
@@ -143,11 +145,13 @@ if os.name == "nt":
current_path = os.path.abspath(__file__)
dirname = os.path.dirname(current_path)
third_libs_dir = os.path.join(dirname, "libs")
add_dll_search_dir(third_libs_dir)
for root, dirs, filenames in os.walk(third_libs_dir):
for d in dirs:
if d == "lib" or d == "bin":
add_dll_search_dir(os.path.join(dirname, root, d))
all_dirs = user_specified_dirs + [third_libs_dir]
for dir in all_dirs:
add_dll_search_dir(dir)
for root, dirs, filenames in os.walk(dir):
for d in dirs:
if d == "lib" or d == "bin":
add_dll_search_dir(os.path.join(dirname, root, d))
try:

View File

@@ -18,6 +18,7 @@ import shutil
import subprocess
import platform
user_specified_dirs = ['@OPENCV_DIRECTORY@', ]
def process_on_linux(current_dir):
rpaths = ["$ORIGIN:$ORIGIN/libs"]
@@ -31,13 +32,15 @@ def process_on_linux(current_dir):
fd_libs.append(filename)
third_libs_path = os.path.join(libs_path, "third_libs")
for root, dirs, files in os.walk(third_libs_path):
for d in dirs:
if d != "lib":
continue
rel_path = os.path.relpath(os.path.join(root, d), libs_path)
rpath = "$ORIGIN/" + rel_path
rpaths.append(rpath)
all_libs_paths = [third_libs_path] + user_specified_dirs
for path in all_libs_paths:
for root, dirs, files in os.walk(path):
for d in dirs:
if d not in ["lib", "lib64"]:
continue
rel_path = os.path.relpath(os.path.join(root, d), libs_path)
rpath = "$ORIGIN/" + rel_path
rpaths.append(rpath)
for lib in fd_libs:
command = "patchelf --set-rpath '{}' {}".format(":".join(rpaths), lib)
@@ -66,18 +69,20 @@ def process_on_mac(current_dir):
commands = list()
third_libs_path = os.path.join(libs_path, "third_libs")
for root, dirs, files in os.walk(third_libs_path):
for d in dirs:
if d != "lib":
continue
rel_path = rel_path = os.path.relpath(os.path.join(root, d), libs_path)
rpath = "$loader_path/" + rel_path
for lib in fd_libs:
pre_commands.append(
"install_name_tool -delete_rpath '@loader_path/{}' {}".format(
rpath, lib))
commands.append("install_name_tool -add_rpath 'loader_path/{}' {}".
format(rpath, lib))
all_libs_paths = [third_libs_path] + user_specified_dirs
for path in all_libs_paths:
for root, dirs, files in os.walk(path):
for d in dirs:
if d not in ["lib", "lib64"]:
continue
rel_path = rel_path = os.path.relpath(os.path.join(root, d), libs_path)
rpath = "$loader_path/" + rel_path
for lib in fd_libs:
pre_commands.append(
"install_name_tool -delete_rpath '@loader_path/{}' {}".format(
rpath, lib))
commands.append("install_name_tool -add_rpath 'loader_path/{}' {}".
format(rpath, lib))
for cmd in pre_commands:
try:
@@ -136,6 +141,7 @@ def process_libraries(current_dir):
package_data.append(
os.path.relpath(f, os.path.join(current_dir,
"fastdeploy")))
return package_data
filters = [".vcxproj", ".png", ".java", ".h", ".cc", ".cpp", ".hpp"]
@@ -145,7 +151,12 @@ def process_libraries(current_dir):
if f.count(flt) > 0:
remain = False
filename = os.path.split(f)[-1]
if filename in ["libnvinfer_plugin.so", "libnvinfer_plugin.so.8.4.1", "libnvinfer.so", "libnvinfer.so.8.4.1", "libnvonnxparser.so", "libnvonnxparser.so.8.4.1", "libnvparsers.so", "libnvparsers.so.8.4.1"]:
if filename in [
"libnvinfer_plugin.so", "libnvinfer_plugin.so.8.4.1",
"libnvinfer.so", "libnvinfer.so.8.4.1", "libnvonnxparser.so",
"libnvonnxparser.so.8.4.1", "libnvparsers.so",
"libnvparsers.so.8.4.1"
]:
continue
if remain:
package_data.append(

View File

@@ -62,6 +62,7 @@ setup_configs["CUDA_DIRECTORY"] = os.getenv("CUDA_DIRECTORY",
"/usr/local/cuda")
setup_configs["LIBRARY_NAME"] = PACKAGE_NAME
setup_configs["PY_LIBRARY_NAME"] = PACKAGE_NAME + "_main"
setup_configs["OPENCV_DIRECTORY"] = os.getenv("OPENCV_DIRECTORY", "")
if setup_configs["WITH_GPU"] == "ON":
wheel_name = "fastdeploy-gpu-python"
@@ -327,8 +328,7 @@ ext_modules = [
# no need to do fancy stuff so far
if PACKAGE_NAME != "fastdeploy":
packages = setuptools.find_packages(
exclude=['fastdeploy*', 'scripts'])
packages = setuptools.find_packages(exclude=['fastdeploy*', 'scripts'])
else:
packages = setuptools.find_packages(exclude=['scripts'])
@@ -353,7 +353,8 @@ if sys.argv[1] == "install" or sys.argv[1] == "bdist_wheel":
shutil.copy(
os.path.join(TOP_DIR, "LICENSE"), os.path.join(TOP_DIR, PACKAGE_NAME))
if not os.path.exists(
os.path.join(TOP_DIR, "python", "fastdeploy", "libs", "third_libs")):
os.path.join(TOP_DIR, "python", "fastdeploy", "libs",
"third_libs")):
print(
"Didn't detect path: fastdeploy/libs/third_libs exist, please execute `python setup.py build` first"
)