Skip to content

Commit 37f1b07

Browse files
authored
Support using system CMake & Ninja (#5899)
Add the dependencies on PyPI `cmake` and `ninja` packages only if they are not available, in order to facilitate using the system tools. This avoids unnecessarily installing third-party binaries, and improves portability by permitting users to use downstream-patched CMake.
1 parent 5ea7681 commit 37f1b07

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

pyproject.toml

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
requires = [
33
"setuptools>=42",
44
"wheel",
5-
"ninja; sys_platform != 'win32'",
6-
"cmake>=3.12",
75
"importlib-metadata",
86
]
97
build-backend = "setuptools.build_meta"

setup.py

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import sys
44
import time
55
import re
6+
import shutil
67
import subprocess
78

89
from setuptools import setup, find_packages, Extension
@@ -176,6 +177,11 @@ def build_extension(self, ext):
176177
sys.exit("Sorry, Python < 3.0 is not supported")
177178

178179
requirements = ["numpy", "tqdm", "requests", "portalocker", "opencv-python"]
180+
setup_requires = []
181+
if shutil.which("cmake") is None:
182+
setup_requires += ["cmake>=3.12"]
183+
if shutil.which("ninja") is None:
184+
setup_requires += ["ninja; sys_platform != 'win32'"]
179185

180186
with io.open("README.md", encoding="utf-8") as h:
181187
long_description = h.read()
@@ -206,6 +212,7 @@ def build_extension(self, ext):
206212
python_requires=">=3.5",
207213
packages=find_packages("python"),
208214
package_dir={"": "python"},
215+
setup_requires=setup_requires,
209216
install_requires=requirements,
210217
ext_modules=[CMakeExtension("ncnn")],
211218
cmdclass={'install': InstallCommand, "build_ext": CMakeBuild},

0 commit comments

Comments
 (0)