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.

275 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 "StoRM (CudaPlugin) - CUDA_PATH is ${CUDA_PATH} or $ENV{CUDA_PATH}")
  11. #############################################################
  12. ##
  13. ## CMake options of StoRM
  14. ##
  15. #############################################################
  16. option(CUDAFORSTORM_DEBUG "Sets whether the DEBUG mode is used" ON)
  17. option(LINK_LIBCXXABI "Sets whether libc++abi should be linked." OFF)
  18. option(USE_LIBCXX "Sets whether the standard library is libc++." OFF)
  19. set(ADDITIONAL_INCLUDE_DIRS "" CACHE STRING "Additional directories added to the include directories.")
  20. set(ADDITIONAL_LINK_DIRS "" CACHE STRING "Additional directories added to the link directories.")
  21. set(STORM_LIB_INSTALL_DIR "${PROJECT_SOURCE_DIR}/../../build/cudaForStorm" CACHE STRING "The Build directory of storm, where the library files should be installed to (if available).")
  22. #############################################################
  23. ##
  24. ## Inclusion of required libraries
  25. ##
  26. #############################################################
  27. # Add the resources/cmake folder to Module Search Path for FindTBB.cmake
  28. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/../cmake/")
  29. # Set the hint for CUSP
  30. set(CUSP_HINT "${PROJECT_SOURCE_DIR}/../3rdparty/cusplibrary")
  31. find_package(CUDA REQUIRED)
  32. find_package(Cusp REQUIRED)
  33. find_package(Doxygen REQUIRED)
  34. find_package(Thrust REQUIRED)
  35. # If the DEBUG option was turned on, we will target a debug version and a release version otherwise
  36. if (CUDAFORSTORM_DEBUG)
  37. set (CMAKE_BUILD_TYPE "DEBUG")
  38. else()
  39. set (CMAKE_BUILD_TYPE "RELEASE")
  40. endif()
  41. message(STATUS "StoRM (CudaPlugin) - Building ${CMAKE_BUILD_TYPE} version.")
  42. message(STATUS "StoRM (CudaPlugin) - CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
  43. message(STATUS "StoRM (CudaPlugin) - CMAKE_BUILD_TYPE (ENV): $ENV{CMAKE_BUILD_TYPE}")
  44. #############################################################
  45. ##
  46. ## CUDA Options
  47. ##
  48. #############################################################
  49. SET (CUDA_VERBOSE_BUILD ON CACHE BOOL "nvcc verbose" FORCE)
  50. set(CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE ON)
  51. set(BUILD_SHARED_LIBS OFF)
  52. set(CUDA_SEPARABLE_COMPILATION ON)
  53. #set(CUDA_NVCC_FLAGS "-arch=sm_30")
  54. # Because the FindCUDA.cmake file has a path related bug, two folders have to be present
  55. file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/CMakeFiles/cudaForStorm.dir/Debug")
  56. file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/CMakeFiles/cudaForStorm.dir/Release")
  57. #############################################################
  58. ##
  59. ## Compiler specific settings and definitions
  60. ##
  61. #############################################################
  62. if(CMAKE_COMPILER_IS_GNUCC)
  63. message(STATUS "StoRM (CudaPlugin) - Using Compiler Configuration: GCC")
  64. # Set standard flags for GCC
  65. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -funroll-loops")
  66. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -pedantic")
  67. elseif(MSVC)
  68. message(STATUS "StoRM (CudaPlugin) - Using Compiler Configuration: MSVC")
  69. # required for GMM to compile, ugly error directive in their code
  70. add_definitions(/D_SCL_SECURE_NO_DEPRECATE /D_CRT_SECURE_NO_WARNINGS)
  71. # 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)
  72. add_definitions(/bigobj)
  73. # required by GTest and PrismGrammar::createIntegerVariable
  74. add_definitions(/D_VARIADIC_MAX=10)
  75. # Windows.h breaks GMM in gmm_except.h because of its macro definition for min and max
  76. add_definitions(/DNOMINMAX)
  77. else(CLANG)
  78. message(STATUS "StoRM (CudaPlugin) - Using Compiler Configuration: Clang (LLVM)")
  79. # As CLANG is not set as a variable, we need to set it in case we have not matched another compiler.
  80. set (CLANG ON)
  81. # Set standard flags for clang
  82. set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -funroll-loops -O3")
  83. if(UNIX AND NOT APPLE AND NOT USE_LIBCXX)
  84. set(CLANG_STDLIB libstdc++)
  85. message(STATUS "StoRM (CudaPlugin) - Linking against libstdc++")
  86. else()
  87. set(CLANG_STDLIB libc++)
  88. message(STATUS "StoRM (CudaPlugin) - Linking against libc++")
  89. # Set up some Xcode specific settings
  90. set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++11")
  91. set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
  92. endif()
  93. 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")
  94. set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
  95. endif()
  96. #############################################################
  97. ##
  98. ## CMake-generated Config File for StoRM
  99. ##
  100. #############################################################
  101. # Test for type alignment
  102. try_run(STORM_CUDA_RUN_RESULT_TYPEALIGNMENT STORM_CUDA_COMPILE_RESULT_TYPEALIGNMENT
  103. ${PROJECT_BINARY_DIR} "${PROJECT_SOURCE_DIR}/CMakeAlignmentCheck.cpp"
  104. COMPILE_OUTPUT_VARIABLE OUTPUT_TEST_VAR
  105. )
  106. if(NOT STORM_CUDA_COMPILE_RESULT_TYPEALIGNMENT)
  107. message(FATAL_ERROR "StoRM (CudaPlugin) - Could not test type alignment, there was an Error while compiling the file ${PROJECT_SOURCE_DIR}/CMakeAlignmentCheck.cpp: ${OUTPUT_TEST_VAR}")
  108. elseif(STORM_CUDA_RUN_RESULT_TYPEALIGNMENT EQUAL 0)
  109. message(STATUS "StoRM (CudaPlugin) - Result of Type Alignment Check: OK.")
  110. else()
  111. message(FATAL_ERROR "StoRM (CudaPlugin) - Result of Type Alignment Check: FAILED (Code ${STORM_CUDA_RUN_RESULT_TYPEALIGNMENT})")
  112. endif()
  113. #
  114. # Make a version file containing the current version from git.
  115. #
  116. include(GetGitRevisionDescription)
  117. git_describe_checkout(STORM_GIT_VERSION_STRING)
  118. # Parse the git Tag into variables
  119. string(REGEX REPLACE "^([0-9]+)\\..*" "\\1" STORM_CUDAPLUGIN_VERSION_MAJOR "${STORM_GIT_VERSION_STRING}")
  120. string(REGEX REPLACE "^[0-9]+\\.([0-9]+).*" "\\1" STORM_CUDAPLUGIN_VERSION_MINOR "${STORM_GIT_VERSION_STRING}")
  121. string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" STORM_CUDAPLUGIN_VERSION_PATCH "${STORM_GIT_VERSION_STRING}")
  122. string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.[0-9]+\\-([0-9]+)\\-.*" "\\1" STORM_CUDAPLUGIN_VERSION_COMMITS_AHEAD "${STORM_GIT_VERSION_STRING}")
  123. string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.[0-9]+\\-[0-9]+\\-([a-z0-9]+).*" "\\1" STORM_CUDAPLUGIN_VERSION_HASH "${STORM_GIT_VERSION_STRING}")
  124. string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.[0-9]+\\-[0-9]+\\-[a-z0-9]+\\-(.*)" "\\1" STORM_CUDAPLUGIN_VERSION_APPENDIX "${STORM_GIT_VERSION_STRING}")
  125. if ("${STORM_CUDAPLUGIN_VERSION_APPENDIX}" MATCHES "^.*dirty.*$")
  126. set(STORM_CUDAPLUGIN_VERSION_DIRTY 1)
  127. else()
  128. set(STORM_CUDAPLUGIN_VERSION_DIRTY 0)
  129. endif()
  130. message(STATUS "StoRM (CudaPlugin) - Version information: ${STORM_CUDAPLUGIN_VERSION_MAJOR}.${STORM_CUDAPLUGIN_VERSION_MINOR}.${STORM_CUDAPLUGIN_VERSION_PATCH} (${STORM_CUDAPLUGIN_VERSION_COMMITS_AHEAD} commits ahead of Tag) build from ${STORM_CUDAPLUGIN_VERSION_HASH} (Dirty: ${STORM_CUDAPLUGIN_VERSION_DIRTY})")
  131. # Configure a header file to pass some of the CMake settings to the source code
  132. configure_file (
  133. "${PROJECT_SOURCE_DIR}/storm-cudaplugin-config.h.in"
  134. "${PROJECT_BINARY_DIR}/include/storm-cudaplugin-config.h"
  135. )
  136. # Add the binary dir include directory for storm-config.h
  137. include_directories("${PROJECT_BINARY_DIR}/include")
  138. # Add the main source directory for includes
  139. include_directories("${PROJECT_SOURCE_DIR}/../../src")
  140. #############################################################
  141. ##
  142. ## Source file aggregation and clustering
  143. ##
  144. #############################################################
  145. file(GLOB_RECURSE CUDAFORSTORM_HEADERS ${PROJECT_SOURCE_DIR}/src/*.h)
  146. file(GLOB_RECURSE CUDAFORSTORM_SOURCES ${PROJECT_SOURCE_DIR}/src/*.cpp)
  147. file(GLOB_RECURSE CUDAFORSTORM_CUDA_SOURCES "${PROJECT_SOURCE_DIR}/srcCuda/*.cu")
  148. file(GLOB_RECURSE CUDAFORSTORM_CUDA_HEADERS "${PROJECT_SOURCE_DIR}/srcCuda/*.h")
  149. # Additional include files like the storm-config.h
  150. file(GLOB_RECURSE CUDAFORSTORM_BUILD_HEADERS ${PROJECT_BINARY_DIR}/include/*.h)
  151. # Group the headers and sources
  152. source_group(main FILES ${CUDAFORSTORM_HEADERS} ${CUDAFORSTORM_SOURCES})
  153. source_group(cuda FILES ${CUDAFORSTORM_CUDA_SOURCES} ${CUDAFORSTORM_CUDA_HEADERS})
  154. # Add custom additional include or link directories
  155. if (ADDITIONAL_INCLUDE_DIRS)
  156. message(STATUS "StoRM (CudaPlugin) - Using additional include directories ${ADDITIONAL_INCLUDE_DIRS}")
  157. include_directories(${ADDITIONAL_INCLUDE_DIRS})
  158. endif(ADDITIONAL_INCLUDE_DIRS)
  159. if (ADDITIONAL_LINK_DIRS)
  160. message(STATUS "StoRM (CudaPlugin) - Using additional link directories ${ADDITIONAL_LINK_DIRS}")
  161. link_directories(${ADDITIONAL_LINK_DIRS})
  162. endif(ADDITIONAL_LINK_DIRS)
  163. #############################################################
  164. ##
  165. ## Pre executable-creation link_directories setup
  166. ##
  167. #############################################################
  168. #############################################################
  169. ##
  170. ## CUDA
  171. ##
  172. #############################################################
  173. #set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} --gpu-architecture sm_30)
  174. #target_link_libraries(cudaLibrary ${CUDA_cusparse_LIBRARY})
  175. #ADD_DEPENDENCIES(cudaForStorm cudaLibrary)
  176. #target_link_libraries(cudaForStorm cudaLibrary)
  177. message(STATUS "StoRM (CudaPlugin) - Found CUDA SDK in Version ${CUDA_VERSION_STRING}, sparse lib is ${CUDA_cusparse_LIBRARY}")
  178. include_directories(${CUDA_INCLUDE_DIRS})
  179. #############################################################
  180. ##
  181. ## CUSP
  182. ##
  183. #############################################################
  184. if(CUSP_FOUND)
  185. include_directories(${CUSP_INCLUDE_DIR})
  186. cuda_include_directories(${CUSP_INCLUDE_DIR})
  187. message(STATUS "StoRM (CudaPlugin) - Found CUSP Version ${CUSP_VERSION} in location ${CUSP_INCLUDE_DIR}")
  188. else()
  189. message(FATAL_ERROR "StoRM (CudaPlugin) - Could not find CUSP!")
  190. endif()
  191. #############################################################
  192. ##
  193. ## Thrust
  194. ##
  195. #############################################################
  196. if(THRUST_FOUND)
  197. include_directories(${THRUST_INCLUDE_DIR})
  198. cuda_include_directories(${THRUST_INCLUDE_DIR})
  199. message(STATUS "StoRM (CudaPlugin) - Found Thrust Version ${THRUST_VERSION} in location ${THRUST_INCLUDE_DIR}")
  200. else()
  201. message(FATAL_ERROR "StoRM (CudaPlugin) - Could not find Thrust! Check your CUDA installation.")
  202. endif()
  203. ###############################################################################
  204. ## #
  205. ## Executable Creation #
  206. ## #
  207. ## All link_directories() calls AND include_directories() calls #
  208. ## MUST be made before this point #
  209. ## #
  210. ###############################################################################
  211. include (GenerateExportHeader)
  212. cuda_add_library(cudaForStorm SHARED
  213. ${CUDAFORSTORM_CUDA_SOURCES} ${CUDAFORSTORM_CUDA_HEADERS}
  214. OPTIONS -DSTUFF="" -arch=sm_30
  215. RELEASE -DNDEBUG
  216. DEBUG -g -DDEBUG
  217. )
  218. GENERATE_EXPORT_HEADER( cudaForStorm
  219. BASE_NAME cudaForStorm
  220. EXPORT_MACRO_NAME cudaForStorm_EXPORT
  221. EXPORT_FILE_NAME include/cudaForStorm_Export.h
  222. STATIC_DEFINE cudaForStorm_BUILT_AS_STATIC
  223. )
  224. if (MSVC)
  225. # Add the DebugHelper DLL
  226. set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES} Dbghelp.lib")
  227. target_link_libraries(cudaForStorm "Dbghelp.lib")
  228. endif(MSVC)
  229. # Link against libc++abi if requested. May be needed to build on Linux systems using clang.
  230. if (LINK_LIBCXXABI)
  231. message (STATUS "StoRM (CudaPlugin) - Linking against libc++abi.")
  232. target_link_libraries(cudaForStorm "c++abi")
  233. endif(LINK_LIBCXXABI)
  234. # Install Directive
  235. install(TARGETS cudaForStorm DESTINATION "${STORM_LIB_INSTALL_DIR}/lib")
  236. install(FILES "${PROJECT_SOURCE_DIR}/srcCuda/cudaForStorm.h" "${PROJECT_BINARY_DIR}/include/cudaForStorm_Export.h" DESTINATION "${STORM_LIB_INSTALL_DIR}/include")