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.

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