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.3 KiB

  1. #!/usr/bin/env python
  2. import os
  3. import sys
  4. import subprocess
  5. from setuptools import setup, Extension
  6. from setuptools.command.build_ext import build_ext
  7. if sys.version_info[0] == 2:
  8. sys.exit('Sorry, Python 2.x is not supported')
  9. class CMakeExtension(Extension):
  10. def __init__(self, name, sourcedir='', subdir=''):
  11. Extension.__init__(self, name, sources=[])
  12. self.sourcedir = os.path.abspath(sourcedir)
  13. self.subdir = subdir
  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. _ = 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. def finalize_options(self):
  29. if hasattr(self, 'storm_dir'):
  30. print('The custom storm directory', self.storm_dir)
  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 += ['--', '-j{}'.format(os.cpu_count() if os.cpu_count() is not None else 2)]
  40. if hasattr(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', 'stormpy.utility'],
  59. package_dir={'': 'lib'},
  60. ext_package='stormpy',
  61. ext_modules=[CMakeExtension('core', subdir=''),
  62. CMakeExtension('info', subdir='info'),
  63. CMakeExtension('expressions', subdir='expressions'),
  64. CMakeExtension('logic', subdir='logic'),
  65. CMakeExtension('storage', subdir='storage'),
  66. CMakeExtension('utility', subdir='utility')
  67. ],
  68. cmdclass=dict(build_ext=CMakeBuild),
  69. zip_safe=False,
  70. install_requires=['pytest'],
  71. )