You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.7 KiB

  1. #!/usr/bin/env python
  2. import os
  3. import re
  4. import sys
  5. import platform
  6. import subprocess
  7. from setuptools import setup, Extension
  8. from setuptools.command.build_ext import build_ext
  9. from distutils.version import LooseVersion
  10. class CMakeExtension(Extension):
  11. def __init__(self, name, sourcedir=''):
  12. Extension.__init__(self, name, sources=[])
  13. self.sourcedir = os.path.abspath(sourcedir)
  14. class CMakeBuild(build_ext):
  15. def run(self):
  16. try:
  17. out = subprocess.check_output(['cmake', '--version'])
  18. except OSError:
  19. raise RuntimeError("CMake must be installed to build the following extensions: " +
  20. ", ".join(e.name for e in self.extensions))
  21. for ext in self.extensions:
  22. self.build_extension(ext)
  23. def build_extension(self, ext):
  24. extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
  25. cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir,
  26. '-DPYTHON_EXECUTABLE=' + sys.executable]
  27. cfg = 'Debug' if self.debug else 'Release'
  28. build_args = ['--config', cfg]
  29. cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg]
  30. build_args += ['--', '-j2']
  31. env = os.environ.copy()
  32. env['CXXFLAGS'] = '{} -DVERSION_INFO=\\"{}\\"'.format(env.get('CXXFLAGS', ''),
  33. self.distribution.get_version())
  34. if not os.path.exists(self.build_temp):
  35. os.makedirs(self.build_temp)
  36. subprocess.check_call(['cmake', ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env)
  37. try:
  38. subprocess.check_call(['cmake', '--build', '.', '--target', ext.name] + build_args, cwd=self.build_temp)
  39. except subprocess.CalledProcessError as e:
  40. if e.output:
  41. raise RuntimeError("CMake build returned with an error: " + e.output)
  42. print(e.stdout)
  43. setup(
  44. name="stormpy",
  45. version="0.9",
  46. author="M. Volk",
  47. author_email="matthias.volk@cs.rwth-aachen.de",
  48. maintainer="S. Junges",
  49. maintainer_email="sebastian.junges@cs.rwth-aachen.de",
  50. url="http://moves.rwth-aachen.de",
  51. description="stormpy - Python Bindings for Storm",
  52. packages=['stormpy', 'stormpy.info', 'stormpy.expressions', 'stormpy.logic', 'stormpy.storage'],
  53. package_dir={'':'lib'},
  54. ext_package='stormpy',
  55. ext_modules=[CMakeExtension('stormpy.core'), CMakeExtension('stormpy.info'),CMakeExtension('stormpy.expressions'), CMakeExtension('stormpy.logic'), CMakeExtension('stormpy.storage')],
  56. cmdclass=dict(build_ext=CMakeBuild),
  57. zip_safe=False
  58. )