Skip to content

Commit d573466

Browse files
mgornyXuehaiPan
andauthored
feat(setup): support using system CMake (#188)
Co-authored-by: Xuehai Pan <XuehaiPan@pku.edu.cn>
1 parent 6808d38 commit d573466

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313

1414
### Added
1515

16-
-
16+
- Support using system `cmake` executable during setup by [@mgorny](https://github.com/mgorny) in [#188](https://github.com/metaopt/optree/pull/188).
1717

1818
### Changed
1919

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ Or, clone this repo and install manually:
6464
```bash
6565
git clone --depth=1 https://github.com/metaopt/optree.git
6666
cd optree
67+
68+
# export CMAKE_EXECUTABLE="/path/to/custom/cmake"
69+
# export CMAKE_BUILD_TYPE="Debug"
70+
# export pybind11_DIR="/path/to/custom/pybind11"
6771
pip3 install .
6872
```
6973

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Package ######################################################################
22

33
[build-system]
4-
requires = ["setuptools", "cmake >= 3.18", "pybind11 >= 2.12"]
4+
requires = ["setuptools", "pybind11 >= 2.12"]
55
build-backend = "setuptools.build_meta"
66

77
[project]

setup.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,21 @@ def __init__(self, name, source_dir='.', target=None, **kwargs):
2121
self.source_dir = Path(source_dir).absolute()
2222
self.target = target if target is not None else name.rpartition('.')[-1]
2323

24+
@classmethod
25+
def cmake_executable(cls):
26+
cmake = os.getenv('CMAKE_EXECUTABLE', '')
27+
if not cmake:
28+
cmake = shutil.which('cmake')
29+
return cmake
30+
2431

2532
class cmake_build_ext(build_ext): # noqa: N801
2633
def build_extension(self, ext): # noqa: C901
2734
if not isinstance(ext, CMakeExtension):
2835
super().build_extension(ext)
2936
return
3037

31-
cmake = shutil.which('cmake')
38+
cmake = ext.cmake_executable()
3239
if cmake is None:
3340
raise RuntimeError('Cannot find CMake executable.')
3441

@@ -141,4 +148,5 @@ def vcs_version(name, path):
141148
version=version.__version__,
142149
cmdclass={'build_ext': cmake_build_ext},
143150
ext_modules=[CMakeExtension('optree._C', source_dir=HERE)],
151+
setup_requires=(['cmake >= 3.18'] if CMakeExtension.cmake_executable() is None else []),
144152
)

0 commit comments

Comments
 (0)