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.

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