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.

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