From 697c30e048017339caa994f53a690ff6dcecee5c Mon Sep 17 00:00:00 2001 From: hbruintjes Date: Wed, 29 Jun 2016 15:19:47 +0200 Subject: [PATCH] Use CMake to generate setup.cfg for include and library paths Former-commit-id: 45f1e210d46fb4155770d837354cc64b4fd611ba --- CMakeLists.txt | 22 ++++++++++++++++- stormpy/setup.cfg | 3 --- stormpy/setup.cfg.in | 5 ++++ stormpy/setup.py | 56 ++++++++++++-------------------------------- 4 files changed, 41 insertions(+), 45 deletions(-) delete mode 100644 stormpy/setup.cfg create mode 100644 stormpy/setup.cfg.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 40aa7e182..47afbbc11 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,7 @@ mark_as_advanced(STORM_COMPILE_WITH_CCACHE) option(STORM_LOG_DISABLE_DEBUG "Disable log and trace message support" OFF) option(STORM_USE_CLN_NUMBERS "Sets whether CLN or GMP numbers should be used" ON) option(BUILD_SHARED_LIBS "Build the Storm library dynamically" OFF) +option(CONFIGURE_STORMPY "Generate setup.cfg for stormpy" ON) set(BOOST_ROOT "" CACHE STRING "A hint to the root directory of Boost (optional).") set(GUROBI_ROOT "" CACHE STRING "A hint to the root directory of Gurobi (optional).") set(Z3_ROOT "" CACHE STRING "A hint to the root directory of Z3 (optional).") @@ -335,8 +336,27 @@ set(STORM_GENERATED_SOURCES "${PROJECT_BINARY_DIR}/src/storm/utility/storm-versi include_directories("${PROJECT_BINARY_DIR}/include") include(CTest) - +# Configure python binding setup file +if(CONFIGURE_STORMPY) + if(STORM_HAVE_CLN) + set(STORMPY_USE_CLN 1) + else() + set(STORMPY_USE_CLN 0) + endif() + get_directory_property(STORMPY_INCLUDE_DIRS_PROP INCLUDE_DIRECTORIES) + foreach(arg ${STORMPY_INCLUDE_DIRS_PROP}) + set(STORMPY_INCLUDE_DIRS "${STORMPY_INCLUDE_DIRS}${sep}${arg}") + set(sep ":") + endforeach() + set(STORMPY_LIBRARY_DIRS "${PROJECT_BINARY_DIR}/src") + set(STORMPY_RPATH "${PROJECT_BINARY_DIR}/src") +configure_file ( + "${PROJECT_SOURCE_DIR}/stormpy/setup.cfg.in" + "${PROJECT_SOURCE_DIR}/stormpy/setup.cfg" +) +endif() add_subdirectory(src) +add_subdirectory(test) include(StormCPackConfig.cmake) diff --git a/stormpy/setup.cfg b/stormpy/setup.cfg deleted file mode 100644 index ce16455c6..000000000 --- a/stormpy/setup.cfg +++ /dev/null @@ -1,3 +0,0 @@ -[build_ext] -use-cln=0 -carl_src=../../carl/src/ diff --git a/stormpy/setup.cfg.in b/stormpy/setup.cfg.in new file mode 100644 index 000000000..c52aa8ac7 --- /dev/null +++ b/stormpy/setup.cfg.in @@ -0,0 +1,5 @@ +[build_ext] +use-cln=@STORMPY_USE_CLN@ +include_dirs=@STORMPY_INCLUDE_DIRS@ +library_dirs=@STORMPY_LIBRARY_DIRS@ +rpath=@STORMPY_RPATH@ diff --git a/stormpy/setup.py b/stormpy/setup.py index 6e9504a74..81e38b8eb 100755 --- a/stormpy/setup.py +++ b/stormpy/setup.py @@ -1,7 +1,7 @@ #!/usr/bin/env python from setuptools import setup from distutils.core import Extension -from distutils.command.build_ext import build_ext +from distutils.command.build_ext import build_ext as orig_build_ext import os.path import platform from glob import glob @@ -15,36 +15,13 @@ logic_sources = glob(os.path.join('src', 'logic', '*.cpp')) storage_sources = glob(os.path.join('src', 'storage', '*.cpp')) # Configuration shared between external modules follows - -# To help along, if storm and/or pybind is not system installed, retrieve from storm distribution -include_dirs = ['.', 'src', 'resources/pybind11/include/'] -# Add more include dirs -# TODO handle by cmake -include_dirs.extend(['../build/include/', '../resources/3rdparty/sylvan/src/', '../resources/3rdparty/exprtk/', '../resources/3rdparty/gmm-5.0/include/']) -boost_dir = '/usr/local/include/' -include_dirs.append(boost_dir) -cudd_dirs = ['../resources/3rdparty/cudd-3.0.0/cplusplus/', '../resources/3rdparty/cudd-3.0.0/mtr/', '../resources/3rdparty/cudd-3.0.0/cudd/'] -include_dirs.extend(cudd_dirs) -log4cplus_dirs = ['../resources/3rdparty/log4cplus-1.1.3-rc1/include/', '../build/resources/3rdparty/log4cplus-1.1.3-rc1/include/'] -include_dirs.extend(log4cplus_dirs) - -local_storm_path = os.path.join(PROJECT_DIR, '..') -if os.path.exists(local_storm_path): - include_dirs.append(local_storm_path) - -# Like includes, also add local path for library, assuming made in 'build' +include_dirs = [PROJECT_DIR, os.path.join(PROJECT_DIR, 'src'), + os.path.join(PROJECT_DIR, 'resources', 'pybind11', 'include')] library_dirs = [] -local_storm_lib_path = os.path.join(PROJECT_DIR, '..', 'build/src') -if os.path.exists(local_storm_lib_path): - library_dirs.append(local_storm_lib_path) - libraries = ['storm'] extra_compile_args = ['-std=c++11'] define_macros = [] - extra_link_args = [] -if platform.system() == 'Darwin': - extra_link_args.append('-Wl,-rpath,'+library_dirs[0]) ext_core = Extension( name='core', @@ -101,27 +78,22 @@ ext_storage = Extension( extra_link_args=extra_link_args ) -class stormpy_build_ext(build_ext): +class build_ext(orig_build_ext): """Extend build_ext to provide CLN toggle option """ - user_options = build_ext.user_options + [ + user_options = orig_build_ext.user_options + [ ('use-cln', None, "use cln numbers instead of gmpxx"), - ('carl_src', None, - "path to src directory of CaRL"), - ] - def __init__(self, *args, **kwargs): - build_ext.__init__(self, *args, **kwargs) + boolean_options = orig_build_ext.boolean_options + ['use-cln'] def initialize_options (self): - build_ext.initialize_options(self) + super(build_ext, self).initialize_options() self.use_cln = None - self.carl_src = None def finalize_options(self): - build_ext.finalize_options(self) + super(build_ext, self).finalize_options() if self.use_cln: self.libraries += ['cln'] @@ -136,12 +108,14 @@ class stormpy_build_ext(build_ext): self.undef = [] self.undef += ['STORMPY_USE_CLN'] - if library_dirs: + if self.library_dirs: # Makes local storm library lookup that much easier - self.rpath += library_dirs + self.rpath += self.library_dirs - print("Add carl_src: {}".format(self.carl_src)) - include_dirs.append(self.carl_src) + if platform.system() == 'Darwin' and len(self.rpath) > 0: + for e in self.extensions: + # If rpath is used on OS X, set this option + e.extra_link_args.append('-Wl,-rpath,'+self.rpath[0]) setup(name="stormpy", version="0.9", @@ -157,6 +131,6 @@ setup(name="stormpy", ext_modules=[ext_core, ext_info, ext_expressions, ext_logic, ext_storage ], cmdclass={ - 'build_ext': stormpy_build_ext, + 'build_ext': build_ext, } )