Skip to content

Commit 24ae166

Browse files
committed
Use system CMake when available
Replace the unconditional build requirement of `cmake` with one that is added only if system CMake is not available, in order to facilitate building against system CMake when available. This avoids unnecessary dependency on some systems, and improves portability when the particular target requires downstream patching of CMake. While at it, also update the existing CMake check to use `shutil.which()` which is more efficient than spawning a subprocess, and update the error message to reference matching CMake version.
1 parent e1c68cc commit 24ae166

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
[build-system]
1919
requires = ["wheel",
2020
"setuptools >= 30.3.0",
21-
"cmake >= 3.16",
2221
"numpy",
2322
"nanobind >= 1.6"]
2423
build-backend = "setuptools.build_meta"

setup.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import os
2222
import sys
2323
import platform
24+
import shutil
2425
import subprocess
2526
import re
2627
from datetime import datetime, timezone
@@ -35,11 +36,9 @@ def __init__(self, name, sourcedir=''):
3536

3637
class CMakeBuild(build_ext):
3738
def run(self):
38-
try:
39-
subprocess.check_output(['cmake', '--version'])
40-
except OSError:
39+
if shutil.which('cmake') is None:
4140
raise RuntimeError(
42-
"CMake >= 3.12 must be installed to build the following extensions: " +
41+
"CMake >= 3.16 must be installed to build the following extensions: " +
4342
", ".join(e.name for e in self.extensions))
4443

4544
for ext in self.extensions:
@@ -89,6 +88,10 @@ def build_extension(self, ext):
8988
ds_version = re.sub('@DT@', dt.strftime('%Y%m%d'), ds_version)
9089
ds_version = re.sub('@HHMM@', 'dev' + dt.strftime('%H%M'), ds_version)
9190

91+
setup_requires = []
92+
if shutil.which('cmake') is None:
93+
setup_requires += ['cmake >= 3.16']
94+
9295
setup(
9396
name='datasketches',
9497
version=ds_version,
@@ -104,6 +107,7 @@ def build_extension(self, ext):
104107
# may need to add all source paths for sdist packages w/o MANIFEST.in
105108
ext_modules=[CMakeExtension('datasketches','.')],
106109
cmdclass={'build_ext': CMakeBuild},
110+
setup_requires=setup_requires,
107111
install_requires=['numpy'],
108112
zip_safe=False
109113
)

0 commit comments

Comments
 (0)