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.

370 lines
14 KiB

  1. cmake_minimum_required (VERSION 2.8.6)
  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 "Builds 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. option(CONFIGURE_STORMPY "Generate setup.cfg for stormpy" ON)
  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_XERCES ${XML_SUPPORT})
  47. mark_as_advanced(USE_XERCES)
  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. # By default, we build a release version.
  53. if (NOT CMAKE_BUILD_TYPE)
  54. set(CMAKE_BUILD_TYPE "RELEASE")
  55. endif()
  56. # If the STORM_DEVELOPER option was turned on, we target a debug version.
  57. if (STORM_DEVELOPER)
  58. set(CMAKE_BUILD_TYPE "DEBUG")
  59. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSTORM_DEV")
  60. endif()
  61. message(STATUS "Storm - Building ${CMAKE_BUILD_TYPE} version.")
  62. if(STORM_COMPILE_WITH_CCACHE)
  63. find_program(CCACHE_FOUND ccache)
  64. mark_as_advanced(CCACHE_FOUND)
  65. if(CCACHE_FOUND)
  66. message(STATUS "Storm - Using ccache")
  67. set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
  68. set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
  69. else()
  70. message(STATUS "Storm - Could not find ccache.")
  71. endif()
  72. endif()
  73. # Base path for test files
  74. set(STORM_CPP_TESTS_BASE_PATH "${PROJECT_SOURCE_DIR}/src/test")
  75. set(STORMPY_OUTPUT_DIR "${PROJECT_BINARY_DIR}/stormpy")
  76. set(STORMPY_SOURCE_DIR "${PROJECT_SOURCE_DIR}/stormpy")
  77. # Auto-detect operating system.
  78. set(MACOSX 0)
  79. set(LINUX 0)
  80. if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  81. # Mac OS
  82. set(OPERATING_SYSTEM "Mac OS")
  83. set(MACOSX 1)
  84. elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
  85. # Linux
  86. set(OPERATING_SYSTEM "Linux")
  87. set(LINUX 1)
  88. elseif(WIN32)
  89. # Assuming Windows.
  90. set(OPERATING_SYSTEM "Windows")
  91. else()
  92. message(WARNING "We are unsure about your operating system.")
  93. set(OPERATING_SYSTEM "Linux")
  94. set(LINUX 1)
  95. ENDIF()
  96. message(STATUS "Storm - Detected operating system ${OPERATING_SYSTEM}.")
  97. set(DYNAMIC_EXT ".so")
  98. set(STATIC_EXT ".a")
  99. set(LIB_PREFIX "lib")
  100. if(MACOSX)
  101. set(DYNAMIC_EXT ".dylib")
  102. set(STATIC_EXT ".a")
  103. set(LIB_PREFIX "lib")
  104. elseif (WIN32)
  105. set(DYNAMIC_EXT ".dll")
  106. set(STATIC_EXT ".lib")
  107. set(LIB_PREFIX "")
  108. endif()
  109. message(STATUS "Assuming extension for shared libraries: ${DYNAMIC_EXT}")
  110. message(STATUS "Assuming extension for static libraries: ${STATIC_EXT}")
  111. if(BUILD_SHARED_LIBS)
  112. set(LIB_EXT ${DYNAMIC_EXT})
  113. message(STATUS "Build dynamic libraries.")
  114. else()
  115. set(LIB_EXT ${STATIC_EXT})
  116. message(STATUS "Build static libraries.")
  117. endif()
  118. #############################################################
  119. ##
  120. ## Compiler detection and initial configuration
  121. ##
  122. #############################################################
  123. if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  124. # using Clang
  125. if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.2)
  126. message(FATAL_ERROR "Clang version must be at least 3.2.")
  127. endif()
  128. set(STORM_COMPILER_CLANG ON)
  129. set(CLANG ON)
  130. set(STORM_COMPILER_ID "clang")
  131. elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
  132. # using GCC
  133. if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.3)
  134. message(FATAL_ERROR "AppleClang version must be at least 7.3.")
  135. endif()
  136. set(STORM_COMPILER_APPLECLANG ON)
  137. set(CLANG ON)
  138. set(STORM_COMPILER_ID "AppleClang")
  139. set(CMAKE_MACOSX_RPATH ON)
  140. elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
  141. # using GCC
  142. if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
  143. message(FATAL_ERROR "gcc version must be at least 5.0.")
  144. endif()
  145. set(STORM_COMPILER_GCC ON)
  146. set(STORM_COMPILER_ID "gcc")
  147. elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
  148. message(FATAL_ERROR "Intel compiler is currently not supported.")
  149. elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
  150. message(FATAL_ERROR "Visual Studio compiler is currently not supported.")
  151. endif()
  152. if(CCACHE_FOUND)
  153. set(STORM_COMPILER_ID "${STORM_COMPILER_ID} (ccache)")
  154. endif()
  155. #############################################################
  156. ##
  157. ## Compiler independent settings
  158. ##
  159. #############################################################
  160. if (STORM_USE_POPCNT)
  161. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mpopcnt")
  162. endif()
  163. # TODO: remove forcing the old version of optional as soon as the related Spirit bug is fixed:
  164. # https://svn.boost.org/trac/boost/ticket/12349
  165. # Fix thanks to: https://github.com/freeorion/freeorion/issues/777
  166. add_definitions(-DBOOST_RESULT_OF_USE_DECLTYPE -DBOOST_OPTIONAL_CONFIG_USE_OLD_IMPLEMENTATION_OF_OPTIONAL)
  167. #############################################################
  168. ##
  169. ## Compiler specific settings
  170. ##
  171. #############################################################
  172. if (STORM_COMPILER_CLANG OR STORM_COMPILER_APPLECLANG)
  173. if(FORCE_COLOR)
  174. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcolor-diagnostics")
  175. endif()
  176. if (LINUX)
  177. set(CLANG_STDLIB libstdc++)
  178. else()
  179. set(CLANG_STDLIB libc++)
  180. endif()
  181. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -stdlib=${CLANG_STDLIB} -ftemplate-depth=1024")
  182. set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto -ffast-math -fno-finite-math-only")
  183. set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-export_dynamic")
  184. set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-export_dynamic")
  185. elseif (STORM_COMPILER_GCC)
  186. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
  187. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto -fprefetch-loop-arrays -ffast-math -fno-finite-math-only")
  188. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -rdynamic")
  189. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -rdynamic")
  190. endif ()
  191. # In release mode, we turn on even more optimizations if we do not have to provide a portable binary.
  192. if (NOT STORM_PORTABLE_RELEASE)
  193. set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -march=native")
  194. endif ()
  195. if (STORM_DEVELOPER)
  196. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")
  197. if (STORM_ALLWARNINGS)
  198. if (CLANG)
  199. # Enable strictly every warning and then disable selected ones.
  200. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weverything")
  201. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-c++98-compat -Wno-c++98-compat-pedantic")
  202. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-old-style-cast")
  203. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-reserved-id-macro")
  204. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-newline-eof")
  205. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-documentation")
  206. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-weak-vtables")
  207. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-global-constructors")
  208. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-exit-time-destructors")
  209. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-switch-enum")
  210. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-covered-switch-default")
  211. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-padded")
  212. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-float-equal")
  213. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-local-typedef")
  214. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-variable-declarations")
  215. endif ()
  216. else ()
  217. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
  218. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-pragmas")
  219. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-local-typedefs")
  220. endif ()
  221. else()
  222. set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fomit-frame-pointer")
  223. endif()
  224. #############################################################
  225. ##
  226. ## Generator specific settings
  227. ##
  228. #############################################################
  229. if ("${CMAKE_GENERATOR}" STREQUAL "Xcode")
  230. set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++11")
  231. set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
  232. endif()
  233. # Display information about build configuration.
  234. message(STATUS "Storm - Using compiler configuration ${STORM_COMPILER_ID}.")
  235. if (STORM_DEVELOPER)
  236. message(STATUS "Storm - CXX Flags: ${CMAKE_CXX_FLAGS}")
  237. message(STATUS "Storm - CXX Debug Flags: ${CMAKE_CXX_FLAGS_DEBUG}")
  238. message(STATUS "Storm - CXX Release Flags: ${CMAKE_CXX_FLAGS_RELEASE}")
  239. message(STATUS "Storm - Build type: ${CMAKE_BUILD_TYPE}")
  240. endif()
  241. #############################################################
  242. #############################################################
  243. ##
  244. ## Inclusion of required libraries
  245. ##
  246. #############################################################
  247. #############################################################
  248. #############################################################
  249. ##
  250. ## Include the targets for non-system resources
  251. ##
  252. #############################################################
  253. # In 3rdparty, targets are being defined that can be used
  254. # in the the system does not have a library
  255. include(resources/3rdparty/CMakeLists.txt)
  256. #############################################################
  257. ##
  258. ## Doxygen
  259. ##
  260. #############################################################
  261. find_package(Doxygen)
  262. # Add a target to generate API documentation with Doxygen
  263. if(DOXYGEN_FOUND)
  264. set(CMAKE_DOXYGEN_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/doc")
  265. string(REGEX REPLACE ";" " " CMAKE_DOXYGEN_INPUT_LIST "${PROJECT_SOURCE_DIR}/src")
  266. configure_file("${CMAKE_CURRENT_SOURCE_DIR}/resources/doxygen/Doxyfile.in" "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile" @ONLY)
  267. add_custom_target(doc ${DOXYGEN_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile" DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile" COMMENT "Generating API documentation with Doxygen" VERBATIM)
  268. endif(DOXYGEN_FOUND)
  269. #############################################################
  270. ##
  271. ## CMake-generated Config File for Storm
  272. ##
  273. #############################################################
  274. # Make a version file containing the current version from git.
  275. include(GetGitRevisionDescription)
  276. git_describe_checkout(STORM_GIT_VERSION_STRING)
  277. message(STATUS "Storm -- Git version string is ${STORM_GIT_VERSION_STRING}.")
  278. # Parse the git Tag into variables
  279. string(REGEX REPLACE "^([0-9]+)\\..*" "\\1" STORM_CPP_VERSION_MAJOR "${STORM_GIT_VERSION_STRING}")
  280. string(REGEX REPLACE "^[0-9]+\\.([0-9]+).*" "\\1" STORM_CPP_VERSION_MINOR "${STORM_GIT_VERSION_STRING}")
  281. string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" STORM_CPP_VERSION_PATCH "${STORM_GIT_VERSION_STRING}")
  282. string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.[0-9]+\\-([0-9]+)\\-.*" "\\1" STORM_CPP_VERSION_COMMITS_AHEAD "${STORM_GIT_VERSION_STRING}")
  283. string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.[0-9]+\\-[0-9]+\\-([a-z0-9]+).*" "\\1" STORM_CPP_VERSION_HASH "${STORM_GIT_VERSION_STRING}")
  284. string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.[0-9]+\\-[0-9]+\\-[a-z0-9]+\\-(.*)" "\\1" STORM_CPP_VERSION_APPENDIX "${STORM_GIT_VERSION_STRING}")
  285. if ("${STORM_CPP_VERSION_APPENDIX}" MATCHES "^.*dirty.*$")
  286. set(STORM_CPP_VERSION_DIRTY 1)
  287. else()
  288. set(STORM_CPP_VERSION_DIRTY 0)
  289. endif()
  290. 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}).")
  291. # Configure a header file to pass some of the CMake settings to the source code
  292. configure_file (
  293. "${PROJECT_SOURCE_DIR}/storm-config.h.in"
  294. "${PROJECT_BINARY_DIR}/include/storm-config.h"
  295. )
  296. # Configure a header file to pass the storm version to the source code
  297. configure_file (
  298. "${PROJECT_SOURCE_DIR}/storm-version.cpp.in"
  299. "${PROJECT_SOURCE_DIR}/src/storm/utility/storm-version.cpp"
  300. )
  301. set(STORM_GENERATED_SOURCES "${PROJECT_BINARY_DIR}/src/storm/utility/storm-version.cpp")
  302. # Add the binary dir include directory for storm-config.h
  303. include_directories("${PROJECT_BINARY_DIR}/include")
  304. include(CTest)
  305. # Configure python binding setup file
  306. if(CONFIGURE_STORMPY)
  307. if(STORM_HAVE_CLN)
  308. set(STORMPY_USE_CLN 1)
  309. else()
  310. set(STORMPY_USE_CLN 0)
  311. endif()
  312. get_directory_property(STORMPY_INCLUDE_DIRS_PROP INCLUDE_DIRECTORIES)
  313. foreach(arg ${STORMPY_INCLUDE_DIRS_PROP})
  314. set(STORMPY_INCLUDE_DIRS "${STORMPY_INCLUDE_DIRS}${sep}${arg}")
  315. set(sep ":")
  316. endforeach()
  317. set(STORMPY_LIBRARY_DIRS "${PROJECT_BINARY_DIR}/src")
  318. set(STORMPY_RPATH "${PROJECT_BINARY_DIR}/src")
  319. configure_file (
  320. "${PROJECT_SOURCE_DIR}/stormpy/setup.cfg.in"
  321. "${PROJECT_SOURCE_DIR}/stormpy/setup.cfg"
  322. )
  323. endif()
  324. add_subdirectory(src)
  325. add_subdirectory(test)
  326. include(StormCPackConfig.cmake)