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.

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