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