Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import pathlib
- from setuptools import setup, Extension
- from setuptools.command.build_ext import build_ext as build_ext_orig
- class CMakeExtension(Extension):
- def __init__(self, name, cmake_lists_dir='.', **kwa):
- Extension.__init__(self, name, sources=[], **kwa)
- self.cmake_lists_dir = os.path.abspath(cmake_lists_dir)
- class build_ext(build_ext_orig):
- def run(self):
- for ext in self.extensions:
- self.build_cmake(ext)
- super().run()
- def build_cmake(self, ext):
- cwd = pathlib.Path().absolute()
- # these dirs will be created in build_py, so if you don't have
- # any python sources to bundle, the dirs will be missing
- build_temp = pathlib.Path(self.build_temp)
- build_temp.mkdir(parents=True, exist_ok=True)
- extdir = pathlib.Path(self.get_ext_fullpath(ext.name))
- extdir.mkdir(parents=True, exist_ok=True)
- # example of cmake args
- config = 'Debug' if self.debug else 'Release'
- cmake_args = [
- '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + str(extdir.parent.absolute()),
- '-DCMAKE_BUILD_TYPE=' + config
- ]
- # example of build args
- build_args = [
- '--config', config,
- '--', '-j4'
- ]
- os.chdir(str(build_temp))
- self.spawn(['cmake', str(cwd)] + cmake_args)
- if not self.dry_run:
- self.spawn(['cmake', '--build', '.'] + build_args)
- os.chdir(str(cwd))
- def main():
- setup(name="spexi",
- version="1.0.0",
- description="Python interface for the Spexi Geospatial functions",
- author="Colin Basnett",
- author_email="colin@spexigeo.com",
- ext_modules=[CMakeExtension('spexi')],
- cmdclass={
- 'build_ext': build_ext,
- })
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement