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.

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