Browse Source

Only build stormpy.dft when storm-dft library was found

refactoring
Matthias Volk 8 years ago
parent
commit
e1d15a9d96
  1. 21
      CMakeLists.txt
  2. 15
      cmake/CMakeLists.txt
  3. 28
      setup.py

21
CMakeLists.txt

@ -1,7 +1,6 @@
cmake_minimum_required(VERSION 3.0.0)
project(pystorm)
option(STORMPY_DISABLE_SIGNATURE_DOC "disables the signature in the documentation" ON)
find_package(storm REQUIRED)
@ -9,12 +8,14 @@ add_subdirectory(resources/pybind11)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/src/generated/config.h)
set(STORMPY_LIB_DIR "${CMAKE_SOURCE_DIR}/lib/stormpy" CACHE STRING "Sets the storm library dir")
function(stormpy_module NAME)
# second, optional argument is LIBRARY_OUTPUT_DIRECTORY,
# defaults to subdir with module name
# third, optional argument are ADDITIONAL_LIBRARIES
# fourth, optional argument are ADDITIONAL_INCLUDES
if(ARGC GREATER 1)
set(LIB_PATH "${ARGV1}")
else()
@ -23,8 +24,15 @@ function(stormpy_module NAME)
file(GLOB_RECURSE "STORM_${NAME}_SOURCES" "${CMAKE_CURRENT_SOURCE_DIR}/src/${NAME}/*.cpp")
pybind11_add_module(${NAME} "${CMAKE_CURRENT_SOURCE_DIR}/src/mod_${NAME}.cpp" ${STORM_${NAME}_SOURCES})
target_include_directories(${NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${storm_INCLUDE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/src/generated)
target_link_libraries(${NAME} PRIVATE storm)
if(ARGC GREATER 2)
# Additional libraries
target_include_directories(${NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${storm_INCLUDE_DIR} ${ARGV3} ${CMAKE_CURRENT_BINARY_DIR}/src/generated)
target_link_libraries(${NAME} PRIVATE storm ${ARGV2})
else()
target_include_directories(${NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${storm_INCLUDE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/src/generated)
target_link_libraries(${NAME} PRIVATE storm)
endif()
# setup.py will override this (because pip may want a different install
# path), but also specifying it here has the advantage that invoking cmake
@ -33,10 +41,13 @@ function(stormpy_module NAME)
set_target_properties(${NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${LIB_PATH}")
endfunction(stormpy_module)
stormpy_module(core "${STORMPY_LIB_DIR}")
stormpy_module(info)
stormpy_module(expressions)
stormpy_module(logic)
stormpy_module(storage)
stormpy_module(utility)
if(HAVE_STORM_DFT)
stormpy_module(dft "${STORMPY_LIB_DIR}/dft" storm-dft "${storm-dft_INCLUDE_DIR}")
endif()

15
cmake/CMakeLists.txt

@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.0.0)
project(storm-version)
find_package(storm REQUIRED)
# Check for storm-dft
if(EXISTS "${storm_DIR}/lib/libstorm-dft.dylib")
set(HAVE_STORM_DFT TRUE)
elseif(EXISTS "${storm_DIR}/lib/libstorm-dft.so")
set(HAVE_STORM_DFT TRUE)
else()
set(HAVE_STORM_DFT FALSE)
endif()
message(STATUS "STORM-DIR: ${storm_DIR}")
message(STATUS "HAVE-STORM-DFT: ${HAVE_STORM_DFT}")

28
setup.py

@ -2,6 +2,7 @@
import os
import sys
import subprocess
import re
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
@ -29,9 +30,30 @@ class CMakeBuild(build_ext):
except OSError:
raise RuntimeError("CMake must be installed to build the following extensions: " +
", ".join(e.name for e in self.extensions))
build_temp_version = self.build_temp + "-version"
if not os.path.exists(build_temp_version):
os.makedirs(build_temp_version)
# Check cmake variable values
output = subprocess.check_output(['cmake', os.path.abspath("cmake")], cwd=build_temp_version)
output = output.decode('ascii')
match = re.search(r"STORM-DIR: (.*)", output)
assert(match)
storm_dir = match.group(1)
match = re.search(r"HAVE-STORM-DFT: (.*)", output)
assert(match)
self.have_storm_dft = True if match.group(1) == "TRUE" else False
for ext in self.extensions:
self.build_extension(ext)
if ext.name == "dft":
if self.have_storm_dft:
self.build_extension(ext)
else:
print("WARNING: storm-dft not found. No support for DFTs will be built.")
else:
self.build_extension(ext)
def initialize_options(self):
build_ext.initialize_options(self)
@ -55,6 +77,8 @@ class CMakeBuild(build_ext):
build_args += ['--', '-j{}'.format(os.cpu_count() if os.cpu_count() is not None else 2)]
if self.storm_dir is not None:
cmake_args += ['-Dstorm_DIR=' + self.storm_dir]
if self.have_storm_dft:
cmake_args += ['-DHAVE_STORM_DFT=ON']
env = os.environ.copy()
env['CXXFLAGS'] = '{} -DVERSION_INFO=\\"{}\\"'.format(env.get('CXXFLAGS', ''),

Loading…
Cancel
Save