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.

87 lines
3.2 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. user_options = build_ext.user_options + [
  16. ('storm-dir', None, 'Path to storm root (binary) location')
  17. ]
  18. def run(self):
  19. try:
  20. out = subprocess.check_output(['cmake', '--version'])
  21. except OSError:
  22. raise RuntimeError("CMake must be installed to build the following extensions: " +
  23. ", ".join(e.name for e in self.extensions))
  24. for ext in self.extensions:
  25. self.build_extension(ext)
  26. def initialize_options(self):
  27. build_ext.initialize_options(self)
  28. self.storm_dir = None
  29. def finalize_options(self):
  30. build_ext.finalize_options(self)
  31. def build_extension(self, ext):
  32. extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
  33. cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir,
  34. '-DPYTHON_EXECUTABLE=' + sys.executable]
  35. cfg = 'Debug' if self.debug else 'Release'
  36. build_args = ['--config', cfg]
  37. cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg]
  38. build_args += ['--', '-j2']
  39. if self.storm_dir:
  40. cmake_args += ['-Dstorm_DIR=' + self.storm_dir]
  41. env = os.environ.copy()
  42. env['CXXFLAGS'] = '{} -DVERSION_INFO=\\"{}\\"'.format(env.get('CXXFLAGS', ''),
  43. self.distribution.get_version())
  44. if not os.path.exists(self.build_temp):
  45. os.makedirs(self.build_temp)
  46. subprocess.check_call(['cmake', ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env)
  47. try:
  48. subprocess.check_call(['cmake', '--build', '.', '--target', ext.name] + build_args, cwd=self.build_temp)
  49. except subprocess.CalledProcessError as e:
  50. if e.output:
  51. raise RuntimeError("CMake build returned with an error: " + e.output)
  52. print(e.stdout)
  53. setup(
  54. name="stormpy",
  55. version="0.9",
  56. author="M. Volk",
  57. author_email="matthias.volk@cs.rwth-aachen.de",
  58. maintainer="S. Junges",
  59. maintainer_email="sebastian.junges@cs.rwth-aachen.de",
  60. url="http://moves.rwth-aachen.de",
  61. description="stormpy - Python Bindings for Storm",
  62. packages=['stormpy', 'stormpy.info', 'stormpy.expressions', 'stormpy.logic', 'stormpy.storage'],
  63. package_dir={'':'lib'},
  64. ext_package='stormpy',
  65. ext_modules=[CMakeExtension('stormpy.core'), CMakeExtension('stormpy.info'),CMakeExtension('stormpy.expressions'), CMakeExtension('stormpy.logic'), CMakeExtension('stormpy.storage')],
  66. cmdclass=dict(build_ext=CMakeBuild),
  67. zip_safe=False
  68. )