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.

88 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. self.storm_dir = None
  29. def finalize_options(self):
  30. if self.storm_dir is not None:
  31. print('The custom storm directory', self.storm_dir)
  32. build_ext.finalize_options(self)
  33. def build_extension(self, ext):
  34. extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
  35. cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + os.path.join(extdir, ext.subdir),
  36. '-DPYTHON_EXECUTABLE=' + sys.executable]
  37. cfg = 'Release' # if self.debug else 'Release'
  38. build_args = ['--config', cfg]
  39. cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg]
  40. build_args += ['--', '-j{}'.format(os.cpu_count() if os.cpu_count() is not None else 2)]
  41. if self.storm_dir is not None:
  42. cmake_args += ['-Dstorm_DIR=' + self.storm_dir]
  43. env = os.environ.copy()
  44. env['CXXFLAGS'] = '{} -DVERSION_INFO=\\"{}\\"'.format(env.get('CXXFLAGS', ''),
  45. self.distribution.get_version())
  46. if not os.path.exists(self.build_temp):
  47. os.makedirs(self.build_temp)
  48. subprocess.check_call(['cmake', ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env)
  49. subprocess.check_call(['cmake', '--build', '.', '--target', ext.name] + build_args, cwd=self.build_temp)
  50. setup(
  51. name="stormpy",
  52. version="0.9",
  53. author="M. Volk",
  54. author_email="matthias.volk@cs.rwth-aachen.de",
  55. maintainer="S. Junges",
  56. maintainer_email="sebastian.junges@cs.rwth-aachen.de",
  57. url="http://moves.rwth-aachen.de",
  58. description="stormpy - Python Bindings for Storm",
  59. packages=['stormpy', 'stormpy.info', 'stormpy.expressions', 'stormpy.logic', 'stormpy.storage', 'stormpy.utility'],
  60. package_dir={'': 'lib'},
  61. ext_package='stormpy',
  62. ext_modules=[CMakeExtension('core', subdir=''),
  63. CMakeExtension('info', subdir='info'),
  64. CMakeExtension('expressions', subdir='expressions'),
  65. CMakeExtension('logic', subdir='logic'),
  66. CMakeExtension('storage', subdir='storage'),
  67. CMakeExtension('utility', subdir='utility')
  68. ],
  69. cmdclass=dict(build_ext=CMakeBuild),
  70. zip_safe=False,
  71. install_requires=['pytest'],
  72. )