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.

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