From 1aa5c6a809a5fdeee0a4bb433ef2beec16e1986f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Thu, 16 Jan 2025 20:39:43 +0100 Subject: [PATCH] Depend on cmake only if there is no system package Rather than requiring using `cmake` from PyPI unconditionally, check if `cmake` is available on the system, and add the dependency only if it is not. This is the same approach as used e.g. by `scikit-build-core` build system. Besides avoiding unnecessarily installing (or building) a second copy of CMake, it improves portability, as system CMake is often patched downstream whereas the CMake version found on PyPI is not. --- pyproject.toml | 2 +- setup.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 9ec751f5b..4a85092d5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,3 @@ [build-system] -requires = ["setuptools>=61", "wheel", "cmake"] +requires = ["setuptools>=61", "wheel"] build-backend = "setuptools.build_meta" diff --git a/setup.py b/setup.py index a4bc500f2..9c67d8fde 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,6 @@ import os import re +import shutil import subprocess import sys import warnings @@ -161,6 +162,10 @@ def initialize_options(self): version_info = get_version_info() author_info = get_author_info() +setup_requires = [] +if not shutil.which('cmake'): + setup_requires.append('cmake') + setuptools.setup( name='OpenCC', version=version_info, @@ -178,6 +183,7 @@ def initialize_options(self): 'build_ext': BuildExtCommand, 'bdist_wheel': BDistWheelCommand }, + setup_requires=setup_requires, classifiers=[ 'Development Status :: 5 - Production/Stable',