From 24ae166aa736def3e97be04fa2d2e58333167c9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Mon, 10 Feb 2025 16:35:04 +0100 Subject: [PATCH] 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. --- pyproject.toml | 1 - setup.py | 12 ++++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 4c539dc6..e8fa7831 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,7 +18,6 @@ [build-system] requires = ["wheel", "setuptools >= 30.3.0", - "cmake >= 3.16", "numpy", "nanobind >= 1.6"] build-backend = "setuptools.build_meta" diff --git a/setup.py b/setup.py index 1467797c..fdb7c2f8 100644 --- a/setup.py +++ b/setup.py @@ -21,6 +21,7 @@ import os import sys import platform +import shutil import subprocess import re from datetime import datetime, timezone @@ -35,11 +36,9 @@ def __init__(self, name, sourcedir=''): class CMakeBuild(build_ext): def run(self): - try: - subprocess.check_output(['cmake', '--version']) - except OSError: + if shutil.which('cmake') is None: raise RuntimeError( - "CMake >= 3.12 must be installed to build the following extensions: " + + "CMake >= 3.16 must be installed to build the following extensions: " + ", ".join(e.name for e in self.extensions)) for ext in self.extensions: @@ -89,6 +88,10 @@ def build_extension(self, ext): ds_version = re.sub('@DT@', dt.strftime('%Y%m%d'), ds_version) ds_version = re.sub('@HHMM@', 'dev' + dt.strftime('%H%M'), ds_version) +setup_requires = [] +if shutil.which('cmake') is None: + setup_requires += ['cmake >= 3.16'] + setup( name='datasketches', version=ds_version, @@ -104,6 +107,7 @@ def build_extension(self, ext): # may need to add all source paths for sdist packages w/o MANIFEST.in ext_modules=[CMakeExtension('datasketches','.')], cmdclass={'build_ext': CMakeBuild}, + setup_requires=setup_requires, install_requires=['numpy'], zip_safe=False )