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.

349 lines
14 KiB

  1. cmake_minimum_required (VERSION 2.8.6)
  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}")
  7. include_directories("${PROJECT_SOURCE_DIR}/src")
  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. #############################################################
  13. ##
  14. ## CMake options of StoRM
  15. ##
  16. #############################################################
  17. option(STORM_DEVELOPER "Sets whether the development mode is used" OFF)
  18. option(STORM_USE_POPCNT "Sets whether the popcnt instruction is going to be used." ON)
  19. MARK_AS_ADVANCED(STORM_USE_POPCNT)
  20. option(USE_BOOST_STATIC_LIBRARIES "Sets whether the Boost libraries should be linked statically." ON)
  21. option(STORM_USE_INTELTBB "Sets whether the Intel TBB libraries should be used." OFF)
  22. option(STORM_USE_GUROBI "Sets whether Gurobi should be used." OFF)
  23. option(STORM_USE_COTIRE "Sets whether Cotire should be used (for building precompiled headers)." OFF)
  24. option(LINK_LIBCXXABI "Sets whether libc++abi should be linked." OFF)
  25. option(USE_LIBCXX "Sets whether the standard library is libc++." OFF)
  26. option(USE_CARL "Sets whether carl should be included." ON)
  27. option(XML_SUPPORT "Sets whether xml based format parsing should be included." ON)
  28. option(FORCE_COLOR "Force color output" OFF)
  29. mark_as_advanced(FORCE_COLOR)
  30. option(STORM_PYTHON "Builds the API for Python" OFF)
  31. option(STORM_COMPILE_WITH_CCACHE "Compile using CCache [if found]" ON)
  32. mark_as_advanced(STORM_COMPILE_WITH_CCACHE)
  33. option(STORM_LOG_DISABLE_DEBUG "Disable log and trace message support" OFF)
  34. option(STORM_USE_CLN_NUMBERS "Sets whether CLN or GMP numbers should be used" ON)
  35. set(BOOST_ROOT "" CACHE STRING "A hint to the root directory of Boost (optional).")
  36. set(GUROBI_ROOT "" CACHE STRING "A hint to the root directory of Gurobi (optional).")
  37. set(Z3_ROOT "" CACHE STRING "A hint to the root directory of Z3 (optional).")
  38. set(CUDA_ROOT "" CACHE STRING "The hint to the root directory of CUDA (optional).")
  39. set(MSAT_ROOT "" CACHE STRING "The hint to the root directory of MathSAT (optional).")
  40. set(ADDITIONAL_INCLUDE_DIRS "" CACHE STRING "Additional directories added to the include directories.")
  41. set(ADDITIONAL_LINK_DIRS "" CACHE STRING "Additional directories added to the link directories.")
  42. set(USE_XERCES ${XML_SUPPORT})
  43. mark_as_advanced(USE_XERCES)
  44. # Set some CMAKE Variables as advanced
  45. mark_as_advanced(CMAKE_OSX_ARCHITECTURES)
  46. mark_as_advanced(CMAKE_OSX_SYSROOT)
  47. mark_as_advanced(CMAKE_OSX_DEPLOYMENT_TARGET)
  48. # If the STORM_DEVELOPER option was turned on, we will target a debug version.
  49. if (STORM_DEVELOPER)
  50. message(STATUS "StoRM - Using development mode")
  51. set(CMAKE_BUILD_TYPE "DEBUG" CACHE STRING "Set the build type" FORCE)
  52. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSTORM_DEV")
  53. endif()
  54. message(STATUS "StoRM - Building ${CMAKE_BUILD_TYPE} version.")
  55. if(STORM_COMPILE_WITH_CCACHE)
  56. find_program(CCACHE_FOUND ccache)
  57. mark_as_advanced(CCACHE_FOUND)
  58. if(CCACHE_FOUND)
  59. message(STATUS "StoRM - Using ccache")
  60. set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
  61. set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
  62. else()
  63. message(STATUS "Could not find ccache")
  64. endif()
  65. endif()
  66. # Base path for test files
  67. set(STORM_CPP_TESTS_BASE_PATH "${PROJECT_SOURCE_DIR}/test")
  68. set(STORMPY_OUTPUT_DIR "${PROJECT_BINARY_DIR}/stormpy")
  69. set(STORMPY_SOURCE_DIR "${PROJECT_SOURCE_DIR}/stormpy")
  70. # Auto-detect operating system.
  71. set(MACOSX 0)
  72. set(LINUX 0)
  73. if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  74. # Mac OS
  75. set(OPERATING_SYSTEM "Mac OS")
  76. set(MACOSX 1)
  77. elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
  78. # Linux
  79. set(OPERATING_SYSTEM "Linux")
  80. set(LINUX 1)
  81. elseif(WIN32)
  82. # Assuming Windows.
  83. set(OPERATING_SYSTEM "Windows")
  84. else()
  85. message(WARNING "We are unsure about your operating system.")
  86. set(OPERATING_SYSTEM "Linux")
  87. set(LINUX 1)
  88. ENDIF()
  89. message(STATUS "Operating system: ${OPERATING_SYSTEM}")
  90. set(DYNAMIC_EXT ".so")
  91. set(STATIC_EXT ".a")
  92. if(MACOSX)
  93. set(DYNAMIC_EXT ".dylib")
  94. set(STATIC_EXT ".a")
  95. elseif (WIN32)
  96. set(DYNAMIC_EXT ".dll")
  97. set(STATIC_EXT ".lib")
  98. endif()
  99. message(STATUS "Assuming extension for shared libraries: ${DYNAMIC_EXT}")
  100. message(STATUS "Assuming extension for static libraries: ${STATIC_EXT}")
  101. #############################################################
  102. ##
  103. ## Compiler specific settings and definitions
  104. ##
  105. #############################################################
  106. # Path to the no-strict-aliasing target
  107. set(CONVERSIONHELPER_TARGET "${PROJECT_SOURCE_DIR}/src/utility/ConversionHelper.cpp")
  108. if(CMAKE_COMPILER_IS_GNUCC)
  109. set(STORM_COMPILED_BY "GCC")
  110. # Set standard flags for GCC
  111. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -funroll-loops")
  112. set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -funroll-loops")
  113. # TODO: remove forcing the old version of optional as soon as the related Spirit bug is fixed:
  114. # https://svn.boost.org/trac/boost/ticket/12349
  115. # Fix thanks to: https://github.com/freeorion/freeorion/issues/777
  116. add_definitions(-DBOOST_RESULT_OF_USE_DECLTYPE -DBOOST_OPTIONAL_CONFIG_USE_OLD_IMPLEMENTATION_OF_OPTIONAL)
  117. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -pedantic -Wno-deprecated-declarations -Wno-unused-local-typedefs -Wno-unknown-pragmas")
  118. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -pedantic -Wno-deprecated-declarations")
  119. if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
  120. message(FATAL_ERROR "GCC version must be at least 5.0!")
  121. endif()
  122. # Turn on popcnt instruction if desired (yes by default)
  123. if (STORM_USE_POPCNT)
  124. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mpopcnt")
  125. endif(STORM_USE_POPCNT)
  126. # Set the no-strict-aliasing target for GCC
  127. set_source_files_properties(${CONVERSIONHELPER_TARGET} PROPERTIES COMPILE_FLAGS " -fno-strict-aliasing")
  128. elseif(MSVC)
  129. set(STORM_COMPILED_BY "MSVC")
  130. # required for GMM to compile, ugly error directive in their code
  131. add_definitions(/D_SCL_SECURE_NO_DEPRECATE /D_CRT_SECURE_NO_WARNINGS)
  132. # required as the PRCTL Parser bloats object files (COFF) beyond their maximum size (see http://msdn.microsoft.com/en-us/library/8578y171(v=vs.110).aspx)
  133. add_definitions(/bigobj)
  134. # required by GTest and PrismGrammar::createIntegerVariable
  135. add_definitions(/D_VARIADIC_MAX=10)
  136. # Windows.h breaks GMM in gmm_except.h because of its macro definition for min and max
  137. add_definitions(/DNOMINMAX)
  138. # Boost Defs, required for using boost's transform iterator
  139. add_definitions(/DBOOST_RESULT_OF_USE_DECLTYPE)
  140. # since nobody cares at the moment
  141. add_definitions(/wd4250)
  142. # MSVC does not do strict-aliasing, so no option needed
  143. else(CLANG)
  144. set(STORM_COMPILED_BY "Clang (LLVM)")
  145. # As CLANG is not set as a variable, we need to set it in case we have not matched another compiler.
  146. set (CLANG ON)
  147. # Set standard flags for clang
  148. set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -funroll-loops -O3")
  149. if(UNIX AND NOT APPLE)
  150. if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.2)
  151. message(FATAL_ERROR "Clang version must be at least 3.2!")
  152. endif()
  153. endif()
  154. if(UNIX AND APPLE)
  155. if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.3)
  156. message(FATAL_ERROR "Clang version must be at least 7.3!")
  157. endif()
  158. endif()
  159. if(UNIX AND NOT APPLE AND NOT USE_LIBCXX)
  160. set(CLANG_STDLIB libstdc++)
  161. message(STATUS "StoRM - Linking against libstdc++")
  162. else()
  163. set(CLANG_STDLIB libc++)
  164. message(STATUS "StoRM - Linking against libc++")
  165. # Disable Cotire
  166. set(STORM_USE_COTIRE OFF)
  167. # Set up some Xcode specific settings
  168. set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++11")
  169. set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
  170. endif()
  171. # TODO: remove forcing the old version of optional as soon as the related Spirit bug is fixed:
  172. # https://svn.boost.org/trac/boost/ticket/12349
  173. # Fix thanks to: https://github.com/freeorion/freeorion/issues/777
  174. add_definitions(-DBOOST_RESULT_OF_USE_DECLTYPE -DBOOST_OPTIONAL_CONFIG_USE_OLD_IMPLEMENTATION_OF_OPTIONAL)
  175. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -stdlib=${CLANG_STDLIB} -Wall -pedantic -Wno-newline-eof -Wno-mismatched-tags -Wno-unused-local-typedefs -ftemplate-depth=1024 -Wno-parentheses-equality")
  176. if(FORCE_COLOR)
  177. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcolor-diagnostics")
  178. endif()
  179. # Turn on popcnt instruction if desired (yes by default)
  180. if (STORM_USE_POPCNT)
  181. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mpopcnt")
  182. endif(STORM_USE_POPCNT)
  183. # Set the no-strict-aliasing target for Clang
  184. set_source_files_properties(${CONVERSIONHELPER_TARGET} PROPERTIES COMPILE_FLAGS " -fno-strict-aliasing ")
  185. endif()
  186. if(CCACHE_FOUND)
  187. set(STORM_COMPILED_BY "${STORM_COMPILED_BY} (ccache)")
  188. endif()
  189. message(STATUS "StoRM - Using Compiler Configuration: ${STORM_COMPILED_BY}")
  190. #############################################################
  191. #############################################################
  192. ##
  193. ## Inclusion of required libraries
  194. ##
  195. #############################################################
  196. #############################################################
  197. #############################################################
  198. ##
  199. ## Include the targets for non-system resources
  200. ##
  201. #############################################################
  202. # In 3rdparty, targets are being defined that can be used
  203. # in the the system does not have a library
  204. include(resources/3rdparty/CMakeLists.txt)
  205. #############################################################
  206. ##
  207. ## Cotire
  208. ##
  209. #############################################################
  210. message (STATUS "StoRM - Using Cotire: ${STORM_USE_COTIRE}")
  211. if (STORM_USE_COTIRE)
  212. # Include Cotire for PCH Generation
  213. set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/resources/cmake")
  214. include(cotire)
  215. cotire(storm)
  216. target_link_libraries(storm_unity ${Boost_LIBRARIES})
  217. #cotire(storm-functional-tests)
  218. #cotire(storm-performance-tests)
  219. endif()
  220. #############################################################
  221. ##
  222. ## libc++abi
  223. ##
  224. #############################################################
  225. # Link against libc++abi if requested. May be needed to build on Linux systems using clang.
  226. if (LINK_LIBCXXABI)
  227. message (STATUS "StoRM - Linking against libc++abi.")
  228. target_link_libraries(storm "c++abi")
  229. endif(LINK_LIBCXXABI)
  230. #############################################################
  231. ##
  232. ## Doxygen
  233. ##
  234. #############################################################
  235. find_package(Doxygen)
  236. # Add a target to generate API documentation with Doxygen
  237. if(DOXYGEN_FOUND)
  238. set(CMAKE_DOXYGEN_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/doc")
  239. string(REGEX REPLACE ";" " " CMAKE_DOXYGEN_INPUT_LIST "${PROJECT_SOURCE_DIR}/src")
  240. configure_file("${CMAKE_CURRENT_SOURCE_DIR}/resources/doxygen/Doxyfile.in" "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile" @ONLY)
  241. add_custom_target(doc ${DOXYGEN_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile" DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile" COMMENT "Generating API documentation with Doxygen" VERBATIM)
  242. endif(DOXYGEN_FOUND)
  243. #############################################################
  244. ##
  245. ## CMake-generated Config File for StoRM
  246. ##
  247. #############################################################
  248. #
  249. # Make a version file containing the current version from git.
  250. #
  251. include(GetGitRevisionDescription)
  252. git_describe_checkout(STORM_GIT_VERSION_STRING)
  253. message(STATUS "STORM_GIT_VERSION_STRING: ${STORM_GIT_VERSION_STRING}")
  254. # Parse the git Tag into variables
  255. string(REGEX REPLACE "^([0-9]+)\\..*" "\\1" STORM_CPP_VERSION_MAJOR "${STORM_GIT_VERSION_STRING}")
  256. string(REGEX REPLACE "^[0-9]+\\.([0-9]+).*" "\\1" STORM_CPP_VERSION_MINOR "${STORM_GIT_VERSION_STRING}")
  257. string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" STORM_CPP_VERSION_PATCH "${STORM_GIT_VERSION_STRING}")
  258. string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.[0-9]+\\-([0-9]+)\\-.*" "\\1" STORM_CPP_VERSION_COMMITS_AHEAD "${STORM_GIT_VERSION_STRING}")
  259. string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.[0-9]+\\-[0-9]+\\-([a-z0-9]+).*" "\\1" STORM_CPP_VERSION_HASH "${STORM_GIT_VERSION_STRING}")
  260. string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.[0-9]+\\-[0-9]+\\-[a-z0-9]+\\-(.*)" "\\1" STORM_CPP_VERSION_APPENDIX "${STORM_GIT_VERSION_STRING}")
  261. if ("${STORM_CPP_VERSION_APPENDIX}" MATCHES "^.*dirty.*$")
  262. set(STORM_CPP_VERSION_DIRTY 1)
  263. else()
  264. set(STORM_CPP_VERSION_DIRTY 0)
  265. endif()
  266. message(STATUS "StoRM - Version information: ${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})")
  267. # Configure a header file to pass some of the CMake settings to the source code
  268. configure_file (
  269. "${PROJECT_SOURCE_DIR}/storm-config.h.in"
  270. "${PROJECT_BINARY_DIR}/include/storm-config.h"
  271. )
  272. # Configure a header file to pass the storm version to the source code
  273. configure_file (
  274. "${PROJECT_SOURCE_DIR}/storm-version.cpp.in"
  275. "${PROJECT_SOURCE_DIR}/src/utility/storm-version.cpp"
  276. )
  277. set(STORM_GENERATED_SOURCES "${PROJECT_BINARY_DIR}/src/utility/storm-version.cpp")
  278. # Add the binary dir include directory for storm-config.h
  279. include_directories("${PROJECT_BINARY_DIR}/include")
  280. add_subdirectory(src)
  281. add_subdirectory(test)
  282. #############################################################
  283. ##
  284. ## memcheck targets
  285. ##
  286. #############################################################
  287. add_custom_target(memcheck valgrind --leak-check=full --show-reachable=yes ${PROJECT_BINARY_DIR}/storm -v --fix-deadlocks ${PROJECT_SOURCE_DIR}/examples/dtmc/crowds/crowds5_5.tra examples/dtmc/crowds/crowds5_5.lab DEPENDS storm)
  288. add_custom_target(memcheck-functional-tests valgrind --leak-check=full --show-reachable=yes ${PROJECT_BINARY_DIR}/storm-functional-tests -v --fix-deadlocks DEPENDS storm-functional-tests)
  289. add_custom_target(memcheck-performance-tests valgrind --leak-check=full --show-reachable=yes ${PROJECT_BINARY_DIR}/storm-performance-tests -v --fix-deadlocks DEPENDS storm-performance-tests)
  290. set(CPPLINT_ARGS --filter=-whitespace/tab,-whitespace/line_length,-legal/copyright,-readability/streams)
  291. add_custom_target(style python resources/3rdparty/cpplint/cpplint.py ${CPPLINT_ARGS} `find ./src/ -iname "*.h" -or -iname "*.cpp" `)
  292. include(StormCPackConfig.cmake)