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.

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