Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issue where setup was failing on cmake >= 3.22.0. Works with ve… #92

Merged
merged 1 commit into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
numpy
cffi
cmake>=3.17.0
packaging
16 changes: 15 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import sys
import shutil
import os
import subprocess
from os import path
from packaging import version
from subprocess import call as execute

from setuptools.command.build_ext import build_ext
Expand Down Expand Up @@ -29,9 +31,16 @@ def initialize_options(self):
self.cmake_args = None
build_ext.initialize_options(self)

def get_cmake_version(self):
output = subprocess.check_output(['cmake', '--version']).decode('utf-8')
line = output.splitlines()[0]
version = line.split()[2]
return(version)

def run(self):
if 0 != os.system('cmake --version'):
sys.exit('\nError: Cannot find cmake. Install cmake, e.g. `pip install cmake`.')

for ext in self.extensions:
self.build_extension(ext)

Expand All @@ -43,6 +52,11 @@ def build_extension(self, ext):
shutil.rmtree(BUILD_TEMP, ignore_errors=True)
os.makedirs(BUILD_TEMP)

if version.parse(self.get_cmake_version()) < version.parse("3.22.0"):
cmake_passthru_flag = "--"
else:
cmake_passthru_flag = "-S"

# Run cmake
build_type = 'Debug' if self.debug else 'Release'
if 0 != execute(['cmake',
Expand All @@ -52,7 +66,7 @@ def build_extension(self, ext):
# set Debug and Release paths to the output directory on Windows
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG='{}'".format(EXT_DIR),
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE='{}'".format(EXT_DIR),
self.cmake_args or "--",
self.cmake_args or cmake_passthru_flag,
SOURCE_DIR], cwd=BUILD_TEMP):
sys.exit('\nERROR: Cannot generate Makefile. See above errors.')

Expand Down