Browse Source

Build python bindings from cmake

Former-commit-id: cd5526ee59
main
Mavo 9 years ago
committed by Matthias Volk
parent
commit
7e53f7d084
  1. 28
      CMakeLists.txt
  2. 81
      stormpy/CMakeLists.txt
  3. 1
      stormpy/setup.cfg.in
  4. 10
      stormpy/setup.py

28
CMakeLists.txt

@ -34,13 +34,12 @@ option(USE_HYPRO "Sets whether HyPro should be included." OFF)
option(XML_SUPPORT "Sets whether xml based format parsing should be included." ON) option(XML_SUPPORT "Sets whether xml based format parsing should be included." ON)
option(FORCE_COLOR "Force color output" OFF) option(FORCE_COLOR "Force color output" OFF)
mark_as_advanced(FORCE_COLOR) mark_as_advanced(FORCE_COLOR)
option(STORM_PYTHON "Builds the API for Python" OFF) option(STORM_PYTHON "Build the API for Python" OFF)
option(STORM_COMPILE_WITH_CCACHE "Compile using CCache [if found]" ON) option(STORM_COMPILE_WITH_CCACHE "Compile using CCache [if found]" ON)
mark_as_advanced(STORM_COMPILE_WITH_CCACHE) mark_as_advanced(STORM_COMPILE_WITH_CCACHE)
option(STORM_LOG_DISABLE_DEBUG "Disable log and trace message support" OFF) 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(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(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(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(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).") set(Z3_ROOT "" CACHE STRING "A hint to the root directory of Z3 (optional).")
@ -83,9 +82,6 @@ endif()
# Base path for test files # Base path for test files
set(STORM_CPP_TESTS_BASE_PATH "${PROJECT_SOURCE_DIR}/src/test") set(STORM_CPP_TESTS_BASE_PATH "${PROJECT_SOURCE_DIR}/src/test")
set(STORMPY_OUTPUT_DIR "${PROJECT_BINARY_DIR}/stormpy")
set(STORMPY_SOURCE_DIR "${PROJECT_SOURCE_DIR}/stormpy")
# Auto-detect operating system. # Auto-detect operating system.
set(MACOSX 0) set(MACOSX 0)
set(LINUX 0) set(LINUX 0)
@ -344,24 +340,10 @@ set(STORM_GENERATED_SOURCES "${PROJECT_BINARY_DIR}/src/storm/utility/storm-versi
include_directories("${PROJECT_BINARY_DIR}/include") include_directories("${PROJECT_BINARY_DIR}/include")
include(CTest) include(CTest)
# Configure python binding setup file # Python bindings for storm
if(CONFIGURE_STORMPY) if(STORM_PYTHON)
if(STORM_HAVE_CLN) add_subdirectory(stormpy)
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() endif()
add_subdirectory(src) add_subdirectory(src)

81
stormpy/CMakeLists.txt

@ -1,39 +1,42 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.8) find_package(PythonInterp REQUIRED)
find_package(PythonLibs REQUIRED)
PROJECT("stormpy") set(STORMPY_OUTPUT_DIR "${PROJECT_BINARY_DIR}/stormpy")
set(STORMPY_SOURCE_DIR "${PROJECT_SOURCE_DIR}/stormpy")
SET(STORMPY_OUTPUT_DIR "${PROJECT_BINARY_DIR}/stormpy") if(STORM_HAVE_CLN)
set(STORMPY_USE_CLN 1)
FIND_PACKAGE ( PythonInterp REQUIRED ) else()
FIND_PACKAGE ( PythonLibs REQUIRED ) set(STORMPY_USE_CLN 0)
endif()
file(STRINGS "${PROJECT_SOURCE_DIR}/setup.cfg" include_dirs # Set configuration file
REGEX "^include_dirs=.*$") get_directory_property(STORMPY_INCLUDE_DIRS_PROP INCLUDE_DIRECTORIES)
string(REGEX REPLACE "^include_dirs=(.+)$" "\\1" include_dirs "${include_dirs}") foreach(arg ${STORMPY_INCLUDE_DIRS_PROP})
string(REPLACE ":" ";" include_dirs ${include_dirs}) set(STORMPY_INCLUDE_DIRS "${STORMPY_INCLUDE_DIRS}${sep}${arg}")
set(sep ":")
file(STRINGS "${PROJECT_SOURCE_DIR}/setup.cfg" library_dirs endforeach()
REGEX "^library_dirs=.*$") set(STORMPY_COMPILE_ARGS ${CMAKE_CXX_FLAGS})
string(REGEX REPLACE "^library_dirs=(.+)$" "\\1" library_dirs "${library_dirs}") set(STORMPY_LIBRARY_DIRS "${PROJECT_BINARY_DIR}/src")
string(REPLACE ":" ";" library_dirs ${library_dirs}) set(STORMPY_RPATH "${PROJECT_BINARY_DIR}/src")
configure_file (
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/resources/pybind11/include ${include_dirs} ${PYTHON_INCLUDE_DIRS}) "${PROJECT_SOURCE_DIR}/stormpy/setup.cfg.in"
LINK_DIRECTORIES(${library_dirs}) "${PROJECT_SOURCE_DIR}/stormpy/setup.cfg"
)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") # Add targets
add_custom_target(PythonBindingsBuild
ADD_SUBDIRECTORY( src ) COMMAND ${PYTHON_EXECUTABLE} setup.py build
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
add_custom_target(stormpy_files) DEPENDS storm
add_custom_command(TARGET stormpy_files POST_BUILD COMMAND ${CMAKE_COMMAND} -E )
copy_directory ${CMAKE_SOURCE_DIR}/lib/stormpy ${STORMPY_OUTPUT_DIR} add_custom_target(PythonBindingsDevelop
) COMMAND ${PYTHON_EXECUTABLE} setup.py develop
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
add_custom_target(stormpy DEPENDS DEPENDS storm
stormpy_files )
stormpy_core add_custom_target(PythonBindingsInstall
stormpy_info COMMAND ${PYTHON_EXECUTABLE} setup.py install --user
stormpy_expressions WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
stormpy_storage DEPENDS storm
stormpy_logic )
)

1
stormpy/setup.cfg.in

@ -1,4 +1,5 @@
[build_ext] [build_ext]
compile_flags=@STORMPY_COMPILE_ARGS@
use-cln=@STORMPY_USE_CLN@ use-cln=@STORMPY_USE_CLN@
include_dirs=@STORMPY_INCLUDE_DIRS@ include_dirs=@STORMPY_INCLUDE_DIRS@
library_dirs=@STORMPY_LIBRARY_DIRS@ library_dirs=@STORMPY_LIBRARY_DIRS@

10
stormpy/setup.py

@ -17,9 +17,9 @@ storage_sources = glob(os.path.join('src', 'storage', '*.cpp'))
# Configuration shared between external modules follows # Configuration shared between external modules follows
include_dirs = [PROJECT_DIR, os.path.join(PROJECT_DIR, 'src'), include_dirs = [PROJECT_DIR, os.path.join(PROJECT_DIR, 'src'),
os.path.join(PROJECT_DIR, 'resources', 'pybind11', 'include')] os.path.join(PROJECT_DIR, 'resources', 'pybind11', 'include')]
library_dirs = []
libraries = ['storm'] libraries = ['storm']
extra_compile_args = ['-std=c++11'] library_dirs = []
extra_compile_args = []
define_macros = [] define_macros = []
extra_link_args = [] extra_link_args = []
@ -84,6 +84,8 @@ class build_ext(orig_build_ext):
user_options = orig_build_ext.user_options + [ user_options = orig_build_ext.user_options + [
('use-cln', None, ('use-cln', None,
"use cln numbers instead of gmpxx"), "use cln numbers instead of gmpxx"),
('compile-flags', None,
"compile flags for C++"),
] ]
boolean_options = orig_build_ext.boolean_options + ['use-cln'] boolean_options = orig_build_ext.boolean_options + ['use-cln']
@ -91,6 +93,7 @@ class build_ext(orig_build_ext):
def initialize_options (self): def initialize_options (self):
super(build_ext, self).initialize_options() super(build_ext, self).initialize_options()
self.use_cln = None self.use_cln = None
self.compile_flags = None
def finalize_options(self): def finalize_options(self):
super(build_ext, self).finalize_options() super(build_ext, self).finalize_options()
@ -117,6 +120,9 @@ class build_ext(orig_build_ext):
# If rpath is used on OS X, set this option # If rpath is used on OS X, set this option
e.extra_link_args.append('-Wl,-rpath,'+self.rpath[0]) e.extra_link_args.append('-Wl,-rpath,'+self.rpath[0])
for e in self.extensions:
e.extra_compile_args += self.compile_flags.split()
setup(name="stormpy", setup(name="stormpy",
version="0.9", version="0.9",
author="M. Volk", author="M. Volk",

|||||||
100:0
Loading…
Cancel
Save