From 2b83fdc57bcc3a446c546866eaa166574e1e280c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=B0=E9=98=85?= <43716063+Baiyuetribe@users.noreply.github.com> Date: Tue, 31 Dec 2024 19:22:26 +0800 Subject: [PATCH] fix #5857 --- setup.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 75b3e0807..c28933d4e 100644 --- a/setup.py +++ b/setup.py @@ -23,6 +23,7 @@ def find_version(): return version_major[0] + "." + version_minor[0] + "." + ncnn_version raise RuntimeError("Unable to find version string.") + # Parse environment variables Vulkan_LIBRARY = os.environ.get("Vulkan_LIBRARY", "") CMAKE_TOOLCHAIN_FILE = os.environ.get("CMAKE_TOOLCHAIN_FILE", "") @@ -38,11 +39,13 @@ ENABLE_BITCODE = os.environ.get("ENABLE_BITCODE", "") ENABLE_ARC = os.environ.get("ENABLE_ARC", "") ENABLE_VISIBILITY = os.environ.get("ENABLE_VISIBILITY", "") + # Parse variables from command line with setup.py install class InstallCommand(install): user_options = install.user_options + [ - ('vulkan=', None, 'Enable the usage of Vulkan.'), + ("vulkan=", None, "Enable the usage of Vulkan."), ] + def initialize_options(self): install.initialize_options(self) self.vulkan = None @@ -53,6 +56,7 @@ class InstallCommand(install): def run(self): install.run(self) + # Convert distutils Windows platform specifiers to CMake -A arguments PLAT_TO_CMAKE = { "win32": "Win32", @@ -61,6 +65,7 @@ PLAT_TO_CMAKE = { "win-arm64": "ARM64", } + # A CMakeExtension needs a sourcedir instead of a file list. # The name must be the _single_ output extension from the CMake build. # If you need multiple extensions, see scikit-build. @@ -88,13 +93,16 @@ class CMakeBuild(build_ext): # Set Python_EXECUTABLE instead if you use PYBIND11_FINDPYTHON # EXAMPLE_VERSION_INFO shows you how to pass a value into the C++ code # from Python. + enable_vulkan = "ON" + if Vulkan_LIBRARY == "": + enable_vulkan = "OFF" cmake_args = [ "-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={}".format(extdir), "-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE={}".format(extdir), "-DPYTHON_EXECUTABLE={}".format(sys.executable), "-DCMAKE_BUILD_TYPE={}".format(cfg), # not used on MSVC, but no harm "-DNCNN_PYTHON=ON", - "-DNCNN_VULKAN=ON", + "-DNCNN_VULKAN={}".format(enable_vulkan), "-DNCNN_DISABLE_RTTI=OFF", "-DNCNN_DISABLE_EXCEPTION=OFF", "-DNCNN_BUILD_BENCHMARK=OFF", @@ -208,5 +216,5 @@ setup( package_dir={"": "python"}, install_requires=requirements, ext_modules=[CMakeExtension("ncnn")], - cmdclass={'install': InstallCommand, "build_ext": CMakeBuild}, + cmdclass={"install": InstallCommand, "build_ext": CMakeBuild}, )