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.

86 lines
3.3 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. if sys.version_info[0] == 2:
  11. sys.exit('Sorry, Python 2.x is not supported')
  12. class CMakeExtension(Extension):
  13. def __init__(self, name, sourcedir='', subdir=''):
  14. Extension.__init__(self, name, sources=[])
  15. self.sourcedir = os.path.abspath(sourcedir)
  16. self.subdir = subdir
  17. class CMakeBuild(build_ext):
  18. user_options = build_ext.user_options + [
  19. ('storm-dir=', None, 'Path to storm root (binary) location')
  20. ]
  21. def run(self):
  22. try:
  23. out = subprocess.check_output(['cmake', '--version'])
  24. except OSError:
  25. raise RuntimeError("CMake must be installed to build the following extensions: " +
  26. ", ".join(e.name for e in self.extensions))
  27. for ext in self.extensions:
  28. self.build_extension(ext)
  29. def initialize_options(self):
  30. build_ext.initialize_options(self)
  31. self.storm_dir = None
  32. def finalize_options(self):
  33. if self.storm_dir:
  34. print('The custom storm directory', self.storm_dir)
  35. build_ext.finalize_options(self)
  36. def build_extension(self, ext):
  37. extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
  38. cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + os.path.join(extdir, ext.subdir),
  39. '-DPYTHON_EXECUTABLE=' + sys.executable]
  40. cfg = 'Release'# if self.debug else 'Release'
  41. build_args = ['--config', cfg]
  42. cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg]
  43. build_args += ['--', '-j2']
  44. if self.storm_dir:
  45. cmake_args += ['-Dstorm_DIR=' + self.storm_dir]
  46. env = os.environ.copy()
  47. env['CXXFLAGS'] = '{} -DVERSION_INFO=\\"{}\\"'.format(env.get('CXXFLAGS', ''),
  48. self.distribution.get_version())
  49. if not os.path.exists(self.build_temp):
  50. os.makedirs(self.build_temp)
  51. subprocess.check_call(['cmake', ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env)
  52. subprocess.check_call(['cmake', '--build', '.', '--target', ext.name] + build_args, cwd=self.build_temp)
  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('core', subdir=''), CMakeExtension('info', subdir='info'),CMakeExtension('expressions', subdir='expressions'), CMakeExtension('logic', subdir='logic'), CMakeExtension('storage', subdir='storage')],
  66. cmdclass=dict(build_ext=CMakeBuild),
  67. zip_safe=False,
  68. install_requires=['pytest'],
  69. )