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.

333 lines
12 KiB

  1. cmake_minimum_required (VERSION 2.8.6)
  2. # Set project name
  3. project (cudaForStorm CXX C)
  4. # Set the version number
  5. set (STORM_CPP_VERSION_MAJOR 1)
  6. set (STORM_CPP_VERSION_MINOR 0)
  7. # Add base folder for better inclusion paths
  8. include_directories("${PROJECT_SOURCE_DIR}")
  9. include_directories("${PROJECT_SOURCE_DIR}/src")
  10. message(STATUS "CUDA_PATH is ${CUDA_PATH} or $ENV{CUDA_PATH}")
  11. #############################################################
  12. ##
  13. ## CMake options of StoRM
  14. ##
  15. #############################################################
  16. option(DEBUG "Sets whether the DEBUG mode is used" ON)
  17. option(USE_POPCNT "Sets whether the popcnt instruction is going to be used." ON)
  18. option(LINK_LIBCXXABI "Sets whether libc++abi should be linked." OFF)
  19. option(USE_LIBCXX "Sets whether the standard library is libc++." OFF)
  20. option(ENABLE_GLPK "Sets whether StoRM is built with support for glpk." OFF)
  21. set(GUROBI_ROOT "" CACHE STRING "The root directory of Gurobi (if available).")
  22. set(Z3_ROOT "" CACHE STRING "The root directory of Z3 (if available).")
  23. set(ADDITIONAL_INCLUDE_DIRS "" CACHE STRING "Additional directories added to the include directories.")
  24. set(ADDITIONAL_LINK_DIRS "" CACHE STRING "Additional directories added to the link directories.")
  25. #############################################################
  26. ##
  27. ## Inclusion of required libraries
  28. ##
  29. #############################################################
  30. # Add the resources/cmake folder to Module Search Path for FindTBB.cmake
  31. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/../cmake/")
  32. find_package(CUDA REQUIRED)
  33. find_package(Doxygen REQUIRED)
  34. find_package(Threads REQUIRED)
  35. # If the DEBUG option was turned on, we will target a debug version and a release version otherwise
  36. if (DEBUG)
  37. set (CMAKE_BUILD_TYPE "DEBUG")
  38. else()
  39. set (CMAKE_BUILD_TYPE "RELEASE")
  40. endif()
  41. message(STATUS "StoRM - Building ${CMAKE_BUILD_TYPE} version.")
  42. if ("${GUROBI_ROOT}" STREQUAL "")
  43. set(ENABLE_GUROBI OFF)
  44. else()
  45. set(ENABLE_GUROBI ON)
  46. endif()
  47. if ("${Z3_ROOT}" STREQUAL "")
  48. set(ENABLE_Z3 OFF)
  49. else()
  50. set(ENABLE_Z3 ON)
  51. set(Z3_LIB_NAME "z3")
  52. endif()
  53. message(STATUS "StoRM - CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
  54. message(STATUS "StoRM - CMAKE_BUILD_TYPE (ENV): $ENV{CMAKE_BUILD_TYPE}")
  55. #############################################################
  56. ##
  57. ## CUDA Options
  58. ##
  59. #############################################################
  60. SET (CUDA_VERBOSE_BUILD ON CACHE BOOL "nvcc verbose" FORCE)
  61. set(CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE ON)
  62. set(BUILD_SHARED_LIBS OFF)
  63. set(CUDA_SEPARABLE_COMPILATION ON)
  64. #set(CUDA_NVCC_FLAGS "-arch=sm_30")
  65. #############################################################
  66. ##
  67. ## Compiler specific settings and definitions
  68. ##
  69. #############################################################
  70. # Path to the no-strict-aliasing target
  71. set(CONVERSIONHELPER_TARGET "${PROJECT_SOURCE_DIR}/src/utility/ConversionHelper.cpp")
  72. if(CMAKE_COMPILER_IS_GNUCC)
  73. message(STATUS "StoRM - Using Compiler Configuration: GCC")
  74. # Set standard flags for GCC
  75. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -funroll-loops")
  76. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -pedantic")
  77. # -Werror is atm removed as this gave some problems with existing code
  78. # May be re-set later
  79. # (Thomas Heinemann, 2012-12-21)
  80. # Turn on popcnt instruction if desired (yes by default)
  81. if (USE_POPCNT)
  82. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mpopcnt")
  83. endif(USE_POPCNT)
  84. # Set the no-strict-aliasing target for GCC
  85. set_source_files_properties(${CONVERSIONHELPER_TARGET} PROPERTIES COMPILE_FLAGS " -fno-strict-aliasing ")
  86. elseif(MSVC)
  87. message(STATUS "StoRM - Using Compiler Configuration: MSVC")
  88. # required for GMM to compile, ugly error directive in their code
  89. add_definitions(/D_SCL_SECURE_NO_DEPRECATE /D_CRT_SECURE_NO_WARNINGS)
  90. # 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)
  91. add_definitions(/bigobj)
  92. # required by GTest and PrismGrammar::createIntegerVariable
  93. add_definitions(/D_VARIADIC_MAX=10)
  94. # Windows.h breaks GMM in gmm_except.h because of its macro definition for min and max
  95. add_definitions(/DNOMINMAX)
  96. if(ENABLE_Z3)
  97. set(Z3_LIB_NAME "libz3")
  98. endif()
  99. # MSVC does not do strict-aliasing, so no option needed
  100. else(CLANG)
  101. message(STATUS "StoRM - Using Compiler Configuration: Clang (LLVM)")
  102. # As CLANG is not set as a variable, we need to set it in case we have not matched another compiler.
  103. set (CLANG ON)
  104. # Set standard flags for clang
  105. set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -funroll-loops -O3")
  106. if(UNIX AND NOT APPLE AND NOT USE_LIBCXX)
  107. set(CLANG_STDLIB libstdc++)
  108. message(STATUS "StoRM - Linking against libstdc++")
  109. else()
  110. set(CLANG_STDLIB libc++)
  111. message(STATUS "StoRM - Linking against libc++")
  112. # Disable Cotire
  113. set(STORM_USE_COTIRE OFF)
  114. # Set up some Xcode specific settings
  115. set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++11")
  116. set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
  117. endif()
  118. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=${CLANG_STDLIB} -Wall -pedantic -Wno-unused-variable -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -ftemplate-depth=1024")
  119. set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
  120. # Turn on popcnt instruction if desired (yes by default)
  121. if (USE_POPCNT)
  122. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mpopcnt")
  123. endif(USE_POPCNT)
  124. # Set the no-strict-aliasing target for Clang
  125. set_source_files_properties(${CONVERSIONHELPER_TARGET} PROPERTIES COMPILE_FLAGS " -fno-strict-aliasing ")
  126. endif()
  127. #############################################################
  128. ##
  129. ## CMake-generated Config File for StoRM
  130. ##
  131. #############################################################
  132. # Base path for test files
  133. set(STORM_CPP_TESTS_BASE_PATH "${PROJECT_SOURCE_DIR}/test")
  134. # Gurobi Defines
  135. if (ENABLE_GUROBI)
  136. set(STORM_CPP_GUROBI_DEF "define")
  137. else()
  138. set(STORM_CPP_GUROBI_DEF "undef")
  139. endif()
  140. # glpk defines
  141. if (ENABLE_GLPK)
  142. set(STORM_CPP_GLPK_DEF "define")
  143. else()
  144. set(STORM_CPP_GLPK_DEF "undef")
  145. endif()
  146. # Z3 Defines
  147. if (ENABLE_Z3)
  148. set(STORM_CPP_Z3_DEF "define")
  149. else()
  150. set(STORM_CPP_Z3_DEF "undef")
  151. endif()
  152. # Intel TBB Defines
  153. if (TBB_FOUND AND ENABLE_INTELTBB)
  154. set(STORM_CPP_INTELTBB_DEF "define")
  155. else()
  156. set(STORM_CPP_INTELTBB_DEF "undef")
  157. endif()
  158. # Configure a header file to pass some of the CMake settings to the source code
  159. configure_file (
  160. "${PROJECT_SOURCE_DIR}/../../storm-config.h.in"
  161. "${PROJECT_BINARY_DIR}/include/storm-config.h"
  162. )
  163. # Add the binary dir include directory for storm-config.h
  164. include_directories("${PROJECT_BINARY_DIR}/include")
  165. # Add the main source directory for includes
  166. include_directories("${PROJECT_SOURCE_DIR}/../../src")
  167. #############################################################
  168. ##
  169. ## Source file aggregation and clustering
  170. ##
  171. #############################################################
  172. file(GLOB_RECURSE CUDAFORSTORM_HEADERS ${PROJECT_SOURCE_DIR}/src/*.h)
  173. file(GLOB_RECURSE CUDAFORSTORM_SOURCES ${PROJECT_SOURCE_DIR}/src/*.cpp)
  174. file(GLOB_RECURSE CUDAFORSTORM_CUDA_SOURCES "${PROJECT_SOURCE_DIR}/srcCuda/*.cu")
  175. file(GLOB_RECURSE CUDAFORSTORM_CUDA_HEADERS "${PROJECT_SOURCE_DIR}/srcCuda/*.h")
  176. # Additional include files like the storm-config.h
  177. file(GLOB_RECURSE STORM_BUILD_HEADERS ${PROJECT_BINARY_DIR}/include/*.h)
  178. # Group the headers and sources
  179. source_group(main FILES ${CUDAFORSTORM_HEADERS} ${CUDAFORSTORM_SOURCES})
  180. source_group(cuda FILES ${CUDAFORSTORM_CUDA_SOURCES} ${CUDAFORSTORM_CUDA_HEADERS})
  181. # Add custom additional include or link directories
  182. if (ADDITIONAL_INCLUDE_DIRS)
  183. message(STATUS "StoRM - Using additional include directories ${ADDITIONAL_INCLUDE_DIRS}")
  184. include_directories(${ADDITIONAL_INCLUDE_DIRS})
  185. endif(ADDITIONAL_INCLUDE_DIRS)
  186. if (ADDITIONAL_LINK_DIRS)
  187. message(STATUS "StoRM - Using additional link directories ${ADDITIONAL_LINK_DIRS}")
  188. link_directories(${ADDITIONAL_LINK_DIRS})
  189. endif(ADDITIONAL_LINK_DIRS)
  190. #############################################################
  191. ##
  192. ## Pre executable-creation link_directories setup
  193. ##
  194. #############################################################
  195. if (ENABLE_GUROBI)
  196. link_directories("${GUROBI_ROOT}/lib")
  197. endif()
  198. if (ENABLE_Z3)
  199. link_directories("${Z3_ROOT}/bin")
  200. endif()
  201. if ((NOT Boost_LIBRARY_DIRS) OR ("${Boost_LIBRARY_DIRS}" STREQUAL ""))
  202. set(Boost_LIBRARY_DIRS "${Boost_INCLUDE_DIRS}/stage/lib")
  203. endif ()
  204. link_directories(${Boost_LIBRARY_DIRS})
  205. if (TBB_FOUND AND ENABLE_INTELTBB)
  206. link_directories(${TBB_LIBRARY_DIRS})
  207. endif()
  208. ###############################################################################
  209. ## #
  210. ## Executable Creation #
  211. ## #
  212. ## All link_directories() calls MUST be made before this point #
  213. ## #
  214. ###############################################################################
  215. # Since this will be a library
  216. include (GenerateExportHeader)
  217. add_library(cudaForStorm STATIC ${CUDAFORSTORM_HEADERS} ${CUDAFORSTORM_SOURCES})
  218. GENERATE_EXPORT_HEADER( cudaForStorm
  219. BASE_NAME cudaForStorm
  220. EXPORT_MACRO_NAME cudaForStorm_EXPORT
  221. EXPORT_FILE_NAME cudaForStorm_Export.h
  222. STATIC_DEFINE cudaForStorm_BUILT_AS_STATIC
  223. )
  224. #############################################################
  225. ##
  226. ## CUDA
  227. ##
  228. #############################################################
  229. #set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} --gpu-architecture sm_30)
  230. cuda_add_library(cudaLibrary
  231. ${CUDAFORSTORM_CUDA_SOURCES} ${CUDAFORSTORM_CUDA_HEADERS}
  232. OPTIONS -DSTUFF="" -arch=sm_30
  233. RELEASE -DNDEBUG
  234. DEBUG -g -DDEBUG
  235. )
  236. target_link_libraries(cudaLibrary ${CUDA_cusparse_LIBRARY})
  237. ADD_DEPENDENCIES(cudaForStorm cudaLibrary)
  238. target_link_libraries(cudaForStorm cudaLibrary)
  239. message(STATUS "Found CUDA SDK in Version ${CUDA_VERSION_STRING}, sparse lib is ${CUDA_cusparse_LIBRARY}")
  240. include_directories(${CUDA_INCLUDE_DIRS})
  241. #############################################################
  242. ##
  243. ## Gurobi (optional)
  244. ##
  245. #############################################################
  246. if (ENABLE_GUROBI)
  247. message (STATUS "StoRM - Linking with Gurobi")
  248. include_directories("${GUROBI_ROOT}/include")
  249. target_link_libraries(cudaForStorm "gurobi56")
  250. endif(ENABLE_GUROBI)
  251. #############################################################
  252. ##
  253. ## glpk (optional)
  254. ##
  255. #############################################################
  256. if (ENABLE_GLPK)
  257. message (STATUS "StoRM - Linking with glpk")
  258. target_link_libraries(cudaForStorm "glpk")
  259. endif(ENABLE_GLPK)
  260. #############################################################
  261. ##
  262. ## Z3 (optional)
  263. ##
  264. #############################################################
  265. if (ENABLE_Z3)
  266. message (STATUS "StoRM - Linking with Z3")
  267. include_directories("${Z3_ROOT}/include")
  268. target_link_libraries(cudaForStorm ${Z3_LIB_NAME})
  269. endif(ENABLE_Z3)
  270. #############################################################
  271. ##
  272. ## Threads
  273. ##
  274. #############################################################
  275. include_directories(${THREADS_INCLUDE_DIRS})
  276. target_link_libraries(cudaForStorm ${CMAKE_THREAD_LIBS_INIT})
  277. if (MSVC)
  278. # Add the DebugHelper DLL
  279. set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES} Dbghelp.lib")
  280. target_link_libraries(cudaForStorm "Dbghelp.lib")
  281. endif(MSVC)
  282. # Link against libc++abi if requested. May be needed to build on Linux systems using clang.
  283. if (LINK_LIBCXXABI)
  284. message (STATUS "StoRM - Linking against libc++abi.")
  285. target_link_libraries(storm "c++abi")
  286. target_link_libraries(storm-functional-tests "c++abi")
  287. target_link_libraries(storm-performance-tests "c++abi")
  288. endif(LINK_LIBCXXABI)