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.

230 lines
9.8 KiB

  1. cmake_minimum_required (VERSION 2.6)
  2. # Set project name
  3. project (storm CXX C)
  4. # Set the version number
  5. set (STORM_CPP_VERSION_MAJOR 1)
  6. set (STORM_CPP_VERSION_MINOR 0)
  7. # Set all GTest references to the version in the repository and show it as output
  8. set (GTEST_INCLUDE_DIR resources/3rdparty/gtest-1.6.0/include)
  9. if(MSVC)
  10. set (STORM_LIB_SUFFIX lib)
  11. set (GTEST_LIBRARY_DEBUG ${PROJECT_SOURCE_DIR}/resources/3rdparty/gtest-1.6.0/build/Debug/gtest.${STORM_LIB_SUFFIX})
  12. set (GTEST_MAIN_LIBRARY_DEBUG ${PROJECT_SOURCE_DIR}/resources/3rdparty/gtest-1.6.0/build/Debug/gtest_main.${STORM_LIB_SUFFIX})
  13. set (GTEST_LIBRARY ${PROJECT_SOURCE_DIR}/resources/3rdparty/gtest-1.6.0/build/Release/gtest.${STORM_LIB_SUFFIX})
  14. set (GTEST_MAIN_LIBRARY ${PROJECT_SOURCE_DIR}/resources/3rdparty/gtest-1.6.0/build/Release/gtest_main.${STORM_LIB_SUFFIX})
  15. set (GTEST_LIBRARIES optimized ${GTEST_LIBRARY} debug ${GTEST_LIBRARY_DEBUG})
  16. else()
  17. set (STORM_LIB_SUFFIX a)
  18. set (GTEST_LIBRARY ${PROJECT_SOURCE_DIR}/resources/3rdparty/gtest-1.6.0/libgtest.${STORM_LIB_SUFFIX})
  19. set (GTEST_MAIN_LIBRARY ${PROJECT_SOURCE_DIR}/resources/3rdparty/gtest-1.6.0/libgtest_main.${STORM_LIB_SUFFIX})
  20. set (GTEST_LIBRARIES ${GTEST_LIBRARY}) # as we dont use FindGTest anymore
  21. endif()
  22. message(STATUS "GTEST_INCLUDE_DIR is ${GTEST_INCLUDE_DIR}")
  23. message(STATUS "GTEST_LIBRARY is ${GTEST_LIBRARY}")
  24. message(STATUS "GTEST_MAIN_LIBRARY is ${GTEST_MAIN_LIBRARY}")
  25. # Set all log4cplus references the version in the repository
  26. set (LOG4CPLUS_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/resources/3rdparty/log4cplus-1.1.0/include)
  27. if (MSVC)
  28. set (LOG4CPLUS_LIBRARIES optimized ${PROJECT_SOURCE_DIR}/resources/3rdparty/log4cplus-1.1.0/msvc10/x64/bin.Release/log4cplusS.${STORM_LIB_SUFFIX} debug ${PROJECT_SOURCE_DIR}/resources/3rdparty/log4cplus-1.1.0/msvc10/x64/bin.Debug/log4cplusSD.${STORM_LIB_SUFFIX})
  29. else()
  30. set (LOG4CPLUS_LIBRARIES ${PROJECT_SOURCE_DIR}/resources/3rdparty/log4cplus-1.1.0/src/liblog4cplus.${STORM_LIB_SUFFIX})
  31. endif()
  32. message(STATUS "LOG4CPLUS_INCLUDE_DIR is ${LOG4CPLUS_INCLUDE_DIR}")
  33. message(STATUS "LOG4CPLUS_LIBRARY is ${LOG4CPLUS_LIBRARIES}")
  34. # Set all Eigen references the version in the repository
  35. set(EIGEN3_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/resources/3rdparty/eigen)
  36. message(STATUS "EIGEN3_INCLUDE_DIR is ${EIGEN3_INCLUDE_DIR}")
  37. # Set all Eigen references the version in the repository
  38. set(GMMXX_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/resources/3rdparty/gmm-4.2/include)
  39. message(STATUS "GMMXX_INCLUDE_DIR is ${GMMXX_INCLUDE_DIR}")
  40. # Now define all available custom options
  41. option(DEBUG "Sets whether the DEBUG mode is used" ON)
  42. option(USE_POPCNT "Sets whether the popcnt instruction is going to be used." ON)
  43. option(USE_BOOST_STATIC_LIBRARIES "Sets whether the Boost libraries should be linked statically." ON)
  44. option(LINK_LIBCXXABI "Sets whether libc++abi should be linked" OFF)
  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(CUSTOM_BOOST_ROOT "" CACHE STRING "A custom path to the Boost root directory.")
  48. # If the DEBUG option was turned on, we will target a debug version and a release version otherwise
  49. if (DEBUG)
  50. set (CMAKE_BUILD_TYPE "DEBUG")
  51. message(STATUS "Building DEBUG version.")
  52. else()
  53. set (CMAKE_BUILD_TYPE "RELEASE")
  54. message(STATUS "Building RELEASE version.")
  55. endif()
  56. if(CMAKE_COMPILER_IS_GNUCC)
  57. # Set standard flags for GCC
  58. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -funroll-loops")
  59. set (CMAKE_CXX_FLAGS "-std=c++0x -Wall -pedantic")
  60. # -Werror is atm removed as this gave some problems with existing code
  61. # May be re-set later
  62. # (Thomas Heinemann, 2012-12-21)
  63. # Turn on popcnt instruction if desired (yes by default)
  64. if (USE_POPCNT)
  65. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mpopcnt")
  66. endif(USE_POPCNT)
  67. elseif(MSVC)
  68. # required for GMM to compile, ugly error directive in their code
  69. add_definitions(/D_SCL_SECURE_NO_DEPRECATE)
  70. else(CLANG)
  71. # As CLANG is not set as a variable, we need to set it in case we have not matched another compiler.
  72. set (CLANG ON)
  73. # Set standard flags for clang
  74. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -funroll-loops")
  75. # TODO: activate -Werror asap
  76. set (CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++ -Wall -pedantic -Wno-unused-variable -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE")
  77. # Turn on popcnt instruction if desired (yes by default)
  78. if (USE_POPCNT)
  79. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mpopcnt")
  80. endif(USE_POPCNT)
  81. endif()
  82. # Add the binary folder to the search path for include files so that we will find storm-config.h
  83. include_directories("${PROJECT_BINARY_DIR}")
  84. # Base path for test files
  85. set(STORM_CPP_TESTS_BASE_PATH ${PROJECT_SOURCE_DIR}/test)
  86. message(STATUS "STORM_CPP_TESTS_BASE_PATH is ${STORM_CPP_TESTS_BASE_PATH}")
  87. # Main Sources
  88. file(GLOB_RECURSE STORM_HEADERS ${PROJECT_SOURCE_DIR}/src/*.h)
  89. file(GLOB_RECURSE STORM_SOURCES ${PROJECT_SOURCE_DIR}/src/*.cpp)
  90. # Test Sources
  91. # Note that the tests also need the source files, except for the main file
  92. file(GLOB_RECURSE STORM_TEST_HEADERS ${PROJECT_SOURCE_DIR}/test/*.h)
  93. file(GLOB_RECURSE STORM_TEST_SOURCES ${PROJECT_SOURCE_DIR}/test/*.cpp ${PROJECT_SOURCE_DIR}/src/*/*.cpp)
  94. # Main Grouping
  95. source_group(Headers FILES ${STORM_HEADERS})
  96. source_group(Sources FILES ${STORM_SOURCES})
  97. # Test Grouping
  98. source_group(Headers FILES ${STORM_TEST_HEADERS})
  99. source_group(Sources FILES ${STORM_TEST_SOURCES})
  100. # Add base folder for better inclusion paths
  101. include_directories("${PROJECT_SOURCE_DIR}")
  102. include_directories("${PROJECT_SOURCE_DIR}/src")
  103. # Set required external packages
  104. find_package(Threads REQUIRED)
  105. find_package(Doxygen REQUIRED)
  106. set(Boost_USE_STATIC_LIBS ON)
  107. set(Boost_USE_MULTITHREADED ON)
  108. set(Boost_USE_STATIC_RUNTIME OFF)
  109. # If a custom boost root directory was specified, we set the corresponding hint for the script to find it.
  110. if(CUSTOM_BOOST_ROOT)
  111. set(BOOST_ROOT "${CUSTOM_BOOST_ROOT}")
  112. endif(CUSTOM_BOOST_ROOT)
  113. find_package(Boost REQUIRED COMPONENTS program_options)
  114. if(Boost_FOUND)
  115. if ((NOT Boost_LIBRARY_DIRS) OR ("${Boost_LIBRARY_DIRS}" STREQUAL ""))
  116. set(Boost_LIBRARY_DIRS "${Boost_INCLUDE_DIRS}/stage/lib")
  117. endif ()
  118. message(STATUS "BOOST_INCLUDE_DIRS is ${Boost_INCLUDE_DIRS}")
  119. message(STATUS "BOOST_LIBRARY_DIRS is ${Boost_LIBRARY_DIRS}")
  120. include_directories(${Boost_INCLUDE_DIRS})
  121. link_directories(${Boost_LIBRARY_DIRS})
  122. endif(Boost_FOUND)
  123. # Add Eigen to the included directories
  124. include_directories(${EIGEN3_INCLUDE_DIR})
  125. # Add GMMXX to the included directories
  126. include_directories(${GMMXX_INCLUDE_DIR})
  127. # Add custom additional include or link directories
  128. if (ADDITIONAL_INCLUDE_DIRS)
  129. message(STATUS "Using additional include directories ${ADDITIONAL_INCLUDE_DIRS}")
  130. include_directories(${ADDITIONAL_INCLUDE_DIRS})
  131. endif(ADDITIONAL_INCLUDE_DIRS)
  132. if (ADDITIONAL_LINK_DIRS)
  133. message(STATUS "Using additional link directories ${ADDITIONAL_LINK_DIRS}")
  134. link_directories(${ADDITIONAL_LINK_DIRS})
  135. endif(ADDITIONAL_LINK_DIRS)
  136. # Add the executables
  137. # Must be created *after* Boost was added because of LINK_DIRECTORIES
  138. add_executable(storm ${STORM_SOURCES} ${STORM_HEADERS})
  139. add_executable(storm-tests ${STORM_TEST_SOURCES} ${STORM_TEST_HEADERS})
  140. # Add target link deps for Boost program options
  141. target_link_libraries(storm ${Boost_LIBRARIES})
  142. target_link_libraries(storm-tests ${Boost_LIBRARIES})
  143. # Link against libc++abi if requested. May be needed to build on Linux systems using clang.
  144. if (LINK_LIBCXXABI)
  145. message (STATUS "Linking against libc++abi.")
  146. target_link_libraries(storm "c++abi")
  147. target_link_libraries(storm-tests "c++abi")
  148. endif(LINK_LIBCXXABI)
  149. # Add a target to generate API documentation with Doxygen
  150. if(DOXYGEN_FOUND)
  151. set(CMAKE_DOXYGEN_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/doc")
  152. string(REGEX REPLACE ";" " " CMAKE_DOXYGEN_INPUT_LIST "${PROJECT_SOURCE_DIR}/src")
  153. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
  154. add_custom_target(doc ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile COMMENT "Generating API documentation with Doxygen" VERBATIM)
  155. endif(DOXYGEN_FOUND)
  156. if (GTEST_INCLUDE_DIR)
  157. # For make-based builds, defines make target named test.
  158. # For Visual Studio builds, defines Visual Studio project named RUN_TESTS.
  159. enable_testing()
  160. include_directories(${GTEST_INCLUDE_DIR})
  161. target_link_libraries(storm-tests ${GTEST_LIBRARIES})
  162. add_test(NAME storm-tests COMMAND storm-tests)
  163. if(MSVC) # VS2012 doesn't support correctly the tuples yet
  164. add_definitions( /D _VARIADIC_MAX=10 )
  165. endif()
  166. endif(GTEST_INCLUDE_DIR)
  167. if (LOG4CPLUS_INCLUDE_DIR)
  168. include_directories(${LOG4CPLUS_INCLUDE_DIR})
  169. target_link_libraries(storm ${LOG4CPLUS_LIBRARIES})
  170. target_link_libraries(storm-tests ${LOG4CPLUS_LIBRARIES})
  171. # On Linux, we have to link against librt
  172. if (UNIX AND NOT APPLE)
  173. target_link_libraries(storm rt)
  174. target_link_libraries(storm-tests rt)
  175. endif(UNIX AND NOT APPLE)
  176. endif(LOG4CPLUS_INCLUDE_DIR)
  177. if (THREADS_FOUND)
  178. include_directories(${THREADS_INCLUDE_DIRS})
  179. target_link_libraries (storm ${CMAKE_THREAD_LIBS_INIT})
  180. target_link_libraries (storm-tests ${CMAKE_THREAD_LIBS_INIT})
  181. endif(THREADS_FOUND)
  182. # Configure a header file to pass some of the CMake settings to the source code
  183. configure_file (
  184. "${PROJECT_SOURCE_DIR}/storm-config.h.in"
  185. "${PROJECT_BINARY_DIR}/storm-config.h"
  186. )
  187. add_custom_target(memcheck valgrind --leak-check=full --show-reachable=yes ${PROJECT_BINARY_DIR}/storm ${PROJECT_SOURCE_DIR}/examples/dtmc/crowds/crowds5_5.tra examples/dtmc/crowds/crowds5_5.lab
  188. DEPENDS storm)
  189. add_custom_target(memcheck-tests valgrind --leak-check=full --show-reachable=yes ${PROJECT_BINARY_DIR}/storm-tests
  190. DEPENDS storm-tests)