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.

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