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.

375 lines
15 KiB

  1. cmake_minimum_required (VERSION 3.2)
  2. cmake_policy(VERSION 3.2)
  3. # Set project name
  4. project (storm CXX C)
  5. # Add base folder for better inclusion paths
  6. include_directories("${PROJECT_SOURCE_DIR}/src")
  7. include_directories("${PROJECT_SOURCE_DIR}/src/storm")
  8. # Add the resources/cmake folder to Module Search Path for FindTBB.cmake
  9. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/resources/cmake/find_modules" "${PROJECT_SOURCE_DIR}/resources/cmake/macros")
  10. include(ExternalProject)
  11. include(RegisterSourceGroup)
  12. include(imported)
  13. #############################################################
  14. ##
  15. ## CMake options of Storm
  16. ##
  17. #############################################################
  18. option(STORM_DEVELOPER "Sets whether the development mode is used." OFF)
  19. option(STORM_ALLWARNINGS "Compile with even more warnings" OFF)
  20. option(STORM_PORTABLE_RELEASE "Sets whether a release build needs to be portable to another machine. This is only effective for release builds in non-development mode." OFF)
  21. MARK_AS_ADVANCED(STORM_PORTABLE_RELEASE)
  22. option(STORM_USE_POPCNT "Sets whether the popcnt instruction is going to be used." ON)
  23. MARK_AS_ADVANCED(STORM_USE_POPCNT)
  24. option(USE_BOOST_STATIC_LIBRARIES "Sets whether the Boost libraries should be linked statically." OFF)
  25. option(STORM_USE_INTELTBB "Sets whether the Intel TBB libraries should be used." OFF)
  26. option(STORM_USE_GUROBI "Sets whether Gurobi should be used." OFF)
  27. option(USE_CARL "Sets whether carl should be included." ON)
  28. option(USE_SMTRAT "Sets whether SMT-RAT should be included." OFF)
  29. option(USE_HYPRO "Sets whether HyPro should be included." OFF)
  30. option(XML_SUPPORT "Sets whether xml based format parsing should be included." ON)
  31. option(FORCE_COLOR "Force color output" OFF)
  32. mark_as_advanced(FORCE_COLOR)
  33. option(STORM_PYTHON "Build the API for Python" OFF)
  34. option(STORM_COMPILE_WITH_CCACHE "Compile using CCache [if found]" ON)
  35. mark_as_advanced(STORM_COMPILE_WITH_CCACHE)
  36. option(STORM_LOG_DISABLE_DEBUG "Disable log and trace message support" OFF)
  37. option(STORM_USE_CLN_NUMBERS "Sets whether CLN or GMP numbers should be used" ON)
  38. option(BUILD_SHARED_LIBS "Build the Storm library dynamically" OFF)
  39. set(BOOST_ROOT "" CACHE STRING "A hint to the root directory of Boost (optional).")
  40. set(GUROBI_ROOT "" CACHE STRING "A hint to the root directory of Gurobi (optional).")
  41. set(Z3_ROOT "" CACHE STRING "A hint to the root directory of Z3 (optional).")
  42. set(CUDA_ROOT "" CACHE STRING "The hint to the root directory of CUDA (optional).")
  43. set(MSAT_ROOT "" CACHE STRING "The hint to the root directory of MathSAT (optional).")
  44. set(ADDITIONAL_INCLUDE_DIRS "" CACHE STRING "Additional directories added to the include directories.")
  45. set(ADDITIONAL_LINK_DIRS "" CACHE STRING "Additional directories added to the link directories.")
  46. set(USE_XERCESC ${XML_SUPPORT})
  47. mark_as_advanced(USE_XERCESC)
  48. # Set some CMAKE Variables as advanced
  49. mark_as_advanced(CMAKE_OSX_ARCHITECTURES)
  50. mark_as_advanced(CMAKE_OSX_SYSROOT)
  51. mark_as_advanced(CMAKE_OSX_DEPLOYMENT_TARGET)
  52. # Offer the user the choice of overriding the installation directories
  53. set(INCLUDE_INSTALL_DIR include/ CACHE PATH "Installation directory for header files" )
  54. set(LIB_INSTALL_DIR lib/ CACHE PATH "Installation directory for libraries")
  55. #set(SYSCONFIG_INSTALL_DIR etc/carl/ CACHE PATH "Installation for system configuration files)
  56. set(BIN_INSTALL_DIR lib/ CACHE PATH "Installation directory for executables")
  57. # By default, we build a release version.
  58. if (NOT CMAKE_BUILD_TYPE)
  59. set(CMAKE_BUILD_TYPE "RELEASE")
  60. endif()
  61. # Install dir for cmake files (info for other libraries that include storm)
  62. set(DEF_INSTALL_CMAKE_DIR "lib/CMake/storm")
  63. set(CMAKE_INSTALL_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files")
  64. message("CMAKE_INSTALL_DIR: ${CMAKE_INSTALL_DIR}")
  65. # If the STORM_DEVELOPER option was turned on, we target a debug version.
  66. if (STORM_DEVELOPER)
  67. set(CMAKE_BUILD_TYPE "DEBUG")
  68. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSTORM_DEV")
  69. endif()
  70. message(STATUS "Storm - Building ${CMAKE_BUILD_TYPE} version.")
  71. if(STORM_COMPILE_WITH_CCACHE)
  72. find_program(CCACHE_FOUND ccache)
  73. mark_as_advanced(CCACHE_FOUND)
  74. if(CCACHE_FOUND)
  75. message(STATUS "Storm - Using ccache")
  76. set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
  77. set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
  78. else()
  79. message(STATUS "Storm - Could not find ccache.")
  80. endif()
  81. endif()
  82. # Directory for test resources.
  83. set(STORM_TEST_RESOURCES_DIR "${PROJECT_SOURCE_DIR}/resources/examples/testfiles")
  84. # Auto-detect operating system.
  85. set(MACOSX 0)
  86. set(LINUX 0)
  87. if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  88. # Mac OS
  89. set(OPERATING_SYSTEM "Mac OS")
  90. set(MACOSX 1)
  91. elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
  92. # Linux
  93. set(OPERATING_SYSTEM "Linux")
  94. set(LINUX 1)
  95. elseif(WIN32)
  96. # Assuming Windows.
  97. set(OPERATING_SYSTEM "Windows")
  98. else()
  99. message(WARNING "We are unsure about your operating system.")
  100. set(OPERATING_SYSTEM "Linux")
  101. set(LINUX 1)
  102. ENDIF()
  103. message(STATUS "Storm - Detected operating system ${OPERATING_SYSTEM}.")
  104. set(DYNAMIC_EXT ".so")
  105. set(STATIC_EXT ".a")
  106. set(LIB_PREFIX "lib")
  107. if(MACOSX)
  108. set(DYNAMIC_EXT ".dylib")
  109. set(STATIC_EXT ".a")
  110. set(LIB_PREFIX "lib")
  111. elseif (WIN32)
  112. set(DYNAMIC_EXT ".dll")
  113. set(STATIC_EXT ".lib")
  114. set(LIB_PREFIX "")
  115. endif()
  116. message(STATUS "Assuming extension for shared libraries: ${DYNAMIC_EXT}")
  117. message(STATUS "Assuming extension for static libraries: ${STATIC_EXT}")
  118. # Python bindings need shared library
  119. if(STORM_PYTHON)
  120. set(BUILD_SHARED_LIBS ON CACHE BOOL "Build the Storm library dynamically" FORCE)
  121. endif()
  122. if(BUILD_SHARED_LIBS)
  123. set(LIB_EXT ${DYNAMIC_EXT})
  124. message(STATUS "Build dynamic libraries.")
  125. else()
  126. set(LIB_EXT ${STATIC_EXT})
  127. message(STATUS "Build static libraries.")
  128. endif()
  129. #############################################################
  130. ##
  131. ## Compiler detection and initial configuration
  132. ##
  133. #############################################################
  134. if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  135. # using Clang
  136. if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.2)
  137. message(FATAL_ERROR "Clang version must be at least 3.2.")
  138. endif()
  139. set(STORM_COMPILER_CLANG ON)
  140. set(CLANG ON)
  141. set(STORM_COMPILER_ID "clang")
  142. elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
  143. # using AppleClang
  144. if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.3)
  145. message(FATAL_ERROR "AppleClang version must be at least 7.3.")
  146. endif()
  147. set(STORM_COMPILER_APPLECLANG ON)
  148. set(CLANG ON)
  149. set(STORM_COMPILER_ID "AppleClang")
  150. set(CMAKE_MACOSX_RPATH ON)
  151. elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
  152. # using GCC
  153. if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
  154. message(FATAL_ERROR "gcc version must be at least 5.0.")
  155. endif()
  156. set(STORM_COMPILER_GCC ON)
  157. set(STORM_COMPILER_ID "gcc")
  158. elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
  159. message(FATAL_ERROR "Intel compiler is currently not supported.")
  160. elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
  161. message(FATAL_ERROR "Visual Studio compiler is currently not supported.")
  162. endif()
  163. set(STORM_COMPILER_VERSION ${CMAKE_CXX_COMPILER_VERSION})
  164. if(CCACHE_FOUND)
  165. set(STORM_COMPILER_ID "${STORM_COMPILER_ID} (ccache)")
  166. endif()
  167. #############################################################
  168. ##
  169. ## Compiler independent settings
  170. ##
  171. #############################################################
  172. if (STORM_USE_POPCNT)
  173. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mpopcnt")
  174. endif()
  175. # TODO: remove forcing the old version of optional as soon as the related Spirit bug is fixed:
  176. # https://svn.boost.org/trac/boost/ticket/12349
  177. # Fix thanks to: https://github.com/freeorion/freeorion/issues/777
  178. add_definitions(-DBOOST_RESULT_OF_USE_DECLTYPE -DBOOST_OPTIONAL_CONFIG_USE_OLD_IMPLEMENTATION_OF_OPTIONAL)
  179. #############################################################
  180. ##
  181. ## Compiler specific settings
  182. ##
  183. #############################################################
  184. if (STORM_COMPILER_CLANG OR STORM_COMPILER_APPLECLANG)
  185. if(FORCE_COLOR)
  186. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcolor-diagnostics")
  187. endif()
  188. if (LINUX)
  189. set(CLANG_STDLIB libstdc++)
  190. else()
  191. set(CLANG_STDLIB libc++)
  192. endif()
  193. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -stdlib=${CLANG_STDLIB} -ftemplate-depth=1024")
  194. set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto -ffast-math -fno-finite-math-only")
  195. set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-export_dynamic")
  196. set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-export_dynamic")
  197. elseif (STORM_COMPILER_GCC)
  198. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
  199. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto -fprefetch-loop-arrays -ffast-math -fno-finite-math-only")
  200. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -rdynamic")
  201. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -rdynamic")
  202. endif ()
  203. # In release mode, we turn on even more optimizations if we do not have to provide a portable binary.
  204. if (NOT STORM_PORTABLE_RELEASE)
  205. set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -march=native")
  206. endif ()
  207. if (STORM_DEVELOPER)
  208. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")
  209. if (STORM_ALLWARNINGS)
  210. if (CLANG)
  211. # Enable strictly every warning and then disable selected ones.
  212. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weverything")
  213. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-c++98-compat -Wno-c++98-compat-pedantic")
  214. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-old-style-cast")
  215. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-reserved-id-macro")
  216. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-newline-eof")
  217. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-documentation")
  218. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-weak-vtables")
  219. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-global-constructors")
  220. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-exit-time-destructors")
  221. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-switch-enum")
  222. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-covered-switch-default")
  223. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-padded")
  224. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-float-equal")
  225. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-local-typedef")
  226. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-variable-declarations")
  227. endif ()
  228. else ()
  229. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
  230. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-pragmas")
  231. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-local-typedefs")
  232. endif ()
  233. else()
  234. set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fomit-frame-pointer")
  235. endif()
  236. #############################################################
  237. ##
  238. ## Generator specific settings
  239. ##
  240. #############################################################
  241. if ("${CMAKE_GENERATOR}" STREQUAL "Xcode")
  242. set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++11")
  243. set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
  244. endif()
  245. # Display information about build configuration.
  246. message(STATUS "Storm - Using compiler configuration ${STORM_COMPILER_ID} ${STORM_COMPILER_VERSION}.")
  247. if (STORM_DEVELOPER)
  248. message(STATUS "Storm - CXX Flags: ${CMAKE_CXX_FLAGS}")
  249. message(STATUS "Storm - CXX Debug Flags: ${CMAKE_CXX_FLAGS_DEBUG}")
  250. message(STATUS "Storm - CXX Release Flags: ${CMAKE_CXX_FLAGS_RELEASE}")
  251. message(STATUS "Storm - Build type: ${CMAKE_BUILD_TYPE}")
  252. endif()
  253. #############################################################
  254. #############################################################
  255. ##
  256. ## Inclusion of required libraries
  257. ##
  258. #############################################################
  259. #############################################################
  260. #############################################################
  261. ##
  262. ## Include the targets for non-system resources
  263. ##
  264. #############################################################
  265. # In 3rdparty, targets are being defined that can be used
  266. # in the the system does not have a library
  267. include(resources/3rdparty/CMakeLists.txt)
  268. #############################################################
  269. ##
  270. ## Doxygen
  271. ##
  272. #############################################################
  273. find_package(Doxygen)
  274. # Add a target to generate API documentation with Doxygen
  275. if(DOXYGEN_FOUND)
  276. set(CMAKE_DOXYGEN_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/doc")
  277. string(REGEX REPLACE ";" " " CMAKE_DOXYGEN_INPUT_LIST "${PROJECT_SOURCE_DIR}/src")
  278. configure_file("${CMAKE_CURRENT_SOURCE_DIR}/resources/doxygen/Doxyfile.in" "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile" @ONLY)
  279. add_custom_target(doc ${DOXYGEN_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile" DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile" COMMENT "Generating API documentation with Doxygen" VERBATIM)
  280. endif(DOXYGEN_FOUND)
  281. #############################################################
  282. ##
  283. ## CMake-generated Config File for Storm
  284. ##
  285. #############################################################
  286. # Make a version file containing the current version from git.
  287. include(GetGitRevisionDescription)
  288. git_describe_checkout(STORM_GIT_VERSION_STRING)
  289. message(STATUS "Storm -- Git version string is ${STORM_GIT_VERSION_STRING}.")
  290. # Parse the git Tag into variables
  291. string(REGEX REPLACE "^([0-9]+)\\..*" "\\1" STORM_CPP_VERSION_MAJOR "${STORM_GIT_VERSION_STRING}")
  292. string(REGEX REPLACE "^[0-9]+\\.([0-9]+).*" "\\1" STORM_CPP_VERSION_MINOR "${STORM_GIT_VERSION_STRING}")
  293. string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" STORM_CPP_VERSION_PATCH "${STORM_GIT_VERSION_STRING}")
  294. string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.[0-9]+\\-([0-9]+)\\-.*" "\\1" STORM_CPP_VERSION_COMMITS_AHEAD "${STORM_GIT_VERSION_STRING}")
  295. string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.[0-9]+\\-[0-9]+\\-([a-z0-9]+).*" "\\1" STORM_CPP_VERSION_HASH "${STORM_GIT_VERSION_STRING}")
  296. string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.[0-9]+\\-[0-9]+\\-[a-z0-9]+\\-(.*)" "\\1" STORM_CPP_VERSION_APPENDIX "${STORM_GIT_VERSION_STRING}")
  297. if ("${STORM_CPP_VERSION_APPENDIX}" MATCHES "^.*dirty.*$")
  298. set(STORM_CPP_VERSION_DIRTY 1)
  299. else()
  300. set(STORM_CPP_VERSION_DIRTY 0)
  301. endif()
  302. message(STATUS "Storm - Version is ${STORM_CPP_VERSION_MAJOR}.${STORM_CPP_VERSION_MINOR}.${STORM_CPP_VERSION_PATCH} (${STORM_CPP_VERSION_COMMITS_AHEAD} commits ahead of Tag) build from ${STORM_CPP_VERSION_HASH} (Dirty: ${STORM_CPP_VERSION_DIRTY}).")
  303. # Configure a header file to pass some of the CMake settings to the source code
  304. configure_file (
  305. "${PROJECT_SOURCE_DIR}/storm-config.h.in"
  306. "${PROJECT_BINARY_DIR}/include/storm-config.h"
  307. )
  308. # Configure a source file to pass the storm version to the source code
  309. configure_file (
  310. "${PROJECT_SOURCE_DIR}/storm-version.cpp.in"
  311. "${PROJECT_SOURCE_DIR}/src/storm/utility/storm-version.cpp"
  312. )
  313. set(STORM_GENERATED_SOURCES "${PROJECT_BINARY_DIR}/src/storm/utility/storm-version.cpp")
  314. # Add the binary dir include directory for storm-config.h
  315. include_directories("${PROJECT_BINARY_DIR}/include")
  316. include(CTest)
  317. # Python bindings for storm
  318. if(STORM_PYTHON)
  319. add_subdirectory(stormpy)
  320. endif()
  321. set(STORM_TARGETS "")
  322. add_subdirectory(src)
  323. message("STORM_TARGETS: ${STORM_TARGETS}")
  324. include(export)
  325. include(StormCPackConfig.cmake)