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.

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