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.

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