Browse Source

Build python bindings from cmake

Former-commit-id: cd5526ee59
tempestpy_adaptions
Mavo 8 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(FORCE_COLOR "Force color output" OFF)
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)
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).")
@ -83,9 +82,6 @@ endif()
# Base path for test files
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.
set(MACOSX 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(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"
)
# Python bindings for storm
if(STORM_PYTHON)
add_subdirectory(stormpy)
endif()
add_subdirectory(src)

81
stormpy/CMakeLists.txt

@ -1,39 +1,42 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT("stormpy")
SET(STORMPY_OUTPUT_DIR "${PROJECT_BINARY_DIR}/stormpy")
FIND_PACKAGE ( PythonInterp REQUIRED )
FIND_PACKAGE ( PythonLibs REQUIRED )
file(STRINGS "${PROJECT_SOURCE_DIR}/setup.cfg" include_dirs
REGEX "^include_dirs=.*$")
string(REGEX REPLACE "^include_dirs=(.+)$" "\\1" include_dirs "${include_dirs}")
string(REPLACE ":" ";" include_dirs ${include_dirs})
file(STRINGS "${PROJECT_SOURCE_DIR}/setup.cfg" library_dirs
REGEX "^library_dirs=.*$")
string(REGEX REPLACE "^library_dirs=(.+)$" "\\1" library_dirs "${library_dirs}")
string(REPLACE ":" ";" library_dirs ${library_dirs})
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/resources/pybind11/include ${include_dirs} ${PYTHON_INCLUDE_DIRS})
LINK_DIRECTORIES(${library_dirs})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
ADD_SUBDIRECTORY( src )
add_custom_target(stormpy_files)
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(stormpy DEPENDS
stormpy_files
stormpy_core
stormpy_info
stormpy_expressions
stormpy_storage
stormpy_logic
)
find_package(PythonInterp REQUIRED)
find_package(PythonLibs REQUIRED)
set(STORMPY_OUTPUT_DIR "${PROJECT_BINARY_DIR}/stormpy")
set(STORMPY_SOURCE_DIR "${PROJECT_SOURCE_DIR}/stormpy")
if(STORM_HAVE_CLN)
set(STORMPY_USE_CLN 1)
else()
set(STORMPY_USE_CLN 0)
endif()
# Set configuration file
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_COMPILE_ARGS ${CMAKE_CXX_FLAGS})
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"
)
# Add targets
add_custom_target(PythonBindingsBuild
COMMAND ${PYTHON_EXECUTABLE} setup.py build
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS storm
)
add_custom_target(PythonBindingsDevelop
COMMAND ${PYTHON_EXECUTABLE} setup.py develop
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS storm
)
add_custom_target(PythonBindingsInstall
COMMAND ${PYTHON_EXECUTABLE} setup.py install --user
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS storm
)

1
stormpy/setup.cfg.in

@ -1,4 +1,5 @@
[build_ext]
compile_flags=@STORMPY_COMPILE_ARGS@
use-cln=@STORMPY_USE_CLN@
include_dirs=@STORMPY_INCLUDE_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
include_dirs = [PROJECT_DIR, os.path.join(PROJECT_DIR, 'src'),
os.path.join(PROJECT_DIR, 'resources', 'pybind11', 'include')]
library_dirs = []
libraries = ['storm']
extra_compile_args = ['-std=c++11']
library_dirs = []
extra_compile_args = []
define_macros = []
extra_link_args = []
@ -84,6 +84,8 @@ class build_ext(orig_build_ext):
user_options = orig_build_ext.user_options + [
('use-cln', None,
"use cln numbers instead of gmpxx"),
('compile-flags', None,
"compile flags for C++"),
]
boolean_options = orig_build_ext.boolean_options + ['use-cln']
@ -91,6 +93,7 @@ class build_ext(orig_build_ext):
def initialize_options (self):
super(build_ext, self).initialize_options()
self.use_cln = None
self.compile_flags = None
def finalize_options(self):
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
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",
version="0.9",
author="M. Volk",

Loading…
Cancel
Save