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.

293 lines
13 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. # Test for Float 64bit Alignment
  114. try_run(STORM_CUDA_RUN_RESULT_FLOATALIGNMENT STORM_CUDA_COMPILE_RESULT_FLOATALIGNMENT
  115. ${PROJECT_BINARY_DIR} "${PROJECT_SOURCE_DIR}/CMakeFloatAlignmentCheck.cpp"
  116. COMPILE_OUTPUT_VARIABLE OUTPUT_TEST_VAR
  117. )
  118. if(NOT STORM_CUDA_COMPILE_RESULT_FLOATALIGNMENT)
  119. message(FATAL_ERROR "StoRM (CudaPlugin) - Could not test float type alignment, there was an Error while compiling the file ${PROJECT_SOURCE_DIR}/CMakeFloatAlignmentCheck.cpp: ${OUTPUT_TEST_VAR}")
  120. elseif(STORM_CUDA_RUN_RESULT_FLOATALIGNMENT EQUAL 2)
  121. message(STATUS "StoRM (CudaPlugin) - Result of Float Type Alignment Check: 64bit alignment active.")
  122. set(STORM_CUDAPLUGIN_FLOAT_64BIT_ALIGN_DEF "define")
  123. elseif(STORM_CUDA_RUN_RESULT_FLOATALIGNMENT EQUAL 3)
  124. message(STATUS "StoRM (CudaPlugin) - Result of Float Type Alignment Check: 64bit alignment disabled.")
  125. set(STORM_CUDAPLUGIN_FLOAT_64BIT_ALIGN_DEF "undef")
  126. else()
  127. message(FATAL_ERROR "StoRM (CudaPlugin) - Result of Float Type Alignment Check: FAILED (Code ${STORM_CUDA_RUN_RESULT_FLOATALIGNMENT})")
  128. endif()
  129. #
  130. # Make a version file containing the current version from git.
  131. #
  132. include(GetGitRevisionDescription)
  133. git_describe_checkout(STORM_GIT_VERSION_STRING)
  134. # Parse the git Tag into variables
  135. string(REGEX REPLACE "^([0-9]+)\\..*" "\\1" STORM_CUDAPLUGIN_VERSION_MAJOR "${STORM_GIT_VERSION_STRING}")
  136. string(REGEX REPLACE "^[0-9]+\\.([0-9]+).*" "\\1" STORM_CUDAPLUGIN_VERSION_MINOR "${STORM_GIT_VERSION_STRING}")
  137. string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" STORM_CUDAPLUGIN_VERSION_PATCH "${STORM_GIT_VERSION_STRING}")
  138. string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.[0-9]+\\-([0-9]+)\\-.*" "\\1" STORM_CUDAPLUGIN_VERSION_COMMITS_AHEAD "${STORM_GIT_VERSION_STRING}")
  139. string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.[0-9]+\\-[0-9]+\\-([a-z0-9]+).*" "\\1" STORM_CUDAPLUGIN_VERSION_HASH "${STORM_GIT_VERSION_STRING}")
  140. string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.[0-9]+\\-[0-9]+\\-[a-z0-9]+\\-(.*)" "\\1" STORM_CUDAPLUGIN_VERSION_APPENDIX "${STORM_GIT_VERSION_STRING}")
  141. if ("${STORM_CUDAPLUGIN_VERSION_APPENDIX}" MATCHES "^.*dirty.*$")
  142. set(STORM_CUDAPLUGIN_VERSION_DIRTY 1)
  143. else()
  144. set(STORM_CUDAPLUGIN_VERSION_DIRTY 0)
  145. endif()
  146. 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})")
  147. # Configure a header file to pass some of the CMake settings to the source code
  148. configure_file (
  149. "${PROJECT_SOURCE_DIR}/storm-cudaplugin-config.h.in"
  150. "${PROJECT_BINARY_DIR}/include/storm-cudaplugin-config.h"
  151. )
  152. # Add the binary dir include directory for storm-config.h
  153. include_directories("${PROJECT_BINARY_DIR}/include")
  154. # Add the main source directory for includes
  155. include_directories("${PROJECT_SOURCE_DIR}/../../src")
  156. #############################################################
  157. ##
  158. ## Source file aggregation and clustering
  159. ##
  160. #############################################################
  161. file(GLOB_RECURSE CUDAFORSTORM_HEADERS ${PROJECT_SOURCE_DIR}/src/*.h)
  162. file(GLOB_RECURSE CUDAFORSTORM_SOURCES ${PROJECT_SOURCE_DIR}/src/*.cpp)
  163. file(GLOB_RECURSE CUDAFORSTORM_CUDA_SOURCES "${PROJECT_SOURCE_DIR}/srcCuda/*.cu")
  164. file(GLOB_RECURSE CUDAFORSTORM_CUDA_HEADERS "${PROJECT_SOURCE_DIR}/srcCuda/*.h")
  165. # Additional include files like the storm-config.h
  166. file(GLOB_RECURSE CUDAFORSTORM_BUILD_HEADERS ${PROJECT_BINARY_DIR}/include/*.h)
  167. # Group the headers and sources
  168. source_group(main FILES ${CUDAFORSTORM_HEADERS} ${CUDAFORSTORM_SOURCES})
  169. source_group(cuda FILES ${CUDAFORSTORM_CUDA_SOURCES} ${CUDAFORSTORM_CUDA_HEADERS})
  170. # Add custom additional include or link directories
  171. if (ADDITIONAL_INCLUDE_DIRS)
  172. message(STATUS "StoRM (CudaPlugin) - Using additional include directories ${ADDITIONAL_INCLUDE_DIRS}")
  173. include_directories(${ADDITIONAL_INCLUDE_DIRS})
  174. endif(ADDITIONAL_INCLUDE_DIRS)
  175. if (ADDITIONAL_LINK_DIRS)
  176. message(STATUS "StoRM (CudaPlugin) - Using additional link directories ${ADDITIONAL_LINK_DIRS}")
  177. link_directories(${ADDITIONAL_LINK_DIRS})
  178. endif(ADDITIONAL_LINK_DIRS)
  179. #############################################################
  180. ##
  181. ## Pre executable-creation link_directories setup
  182. ##
  183. #############################################################
  184. #############################################################
  185. ##
  186. ## CUDA
  187. ##
  188. #############################################################
  189. #set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} --gpu-architecture sm_30)
  190. #target_link_libraries(cudaLibrary ${CUDA_cusparse_LIBRARY})
  191. #ADD_DEPENDENCIES(cudaForStorm cudaLibrary)
  192. #target_link_libraries(cudaForStorm cudaLibrary)
  193. message(STATUS "StoRM (CudaPlugin) - Found CUDA SDK in Version ${CUDA_VERSION_STRING}, sparse lib is ${CUDA_cusparse_LIBRARY}")
  194. include_directories(${CUDA_INCLUDE_DIRS})
  195. #############################################################
  196. ##
  197. ## CUSP
  198. ##
  199. #############################################################
  200. if(CUSP_FOUND)
  201. include_directories(${CUSP_INCLUDE_DIR})
  202. cuda_include_directories(${CUSP_INCLUDE_DIR})
  203. message(STATUS "StoRM (CudaPlugin) - Found CUSP Version ${CUSP_VERSION} in location ${CUSP_INCLUDE_DIR}")
  204. else()
  205. message(FATAL_ERROR "StoRM (CudaPlugin) - Could not find CUSP!")
  206. endif()
  207. #############################################################
  208. ##
  209. ## Thrust
  210. ##
  211. #############################################################
  212. if(THRUST_FOUND)
  213. include_directories(${THRUST_INCLUDE_DIR})
  214. cuda_include_directories(${THRUST_INCLUDE_DIR})
  215. message(STATUS "StoRM (CudaPlugin) - Found Thrust Version ${THRUST_VERSION} in location ${THRUST_INCLUDE_DIR}")
  216. else()
  217. message(FATAL_ERROR "StoRM (CudaPlugin) - Could not find Thrust! Check your CUDA installation.")
  218. endif()
  219. ###############################################################################
  220. ## #
  221. ## Executable Creation #
  222. ## #
  223. ## All link_directories() calls AND include_directories() calls #
  224. ## MUST be made before this point #
  225. ## #
  226. ###############################################################################
  227. include (GenerateExportHeader)
  228. cuda_add_library(cudaForStorm SHARED
  229. ${CUDAFORSTORM_CUDA_SOURCES} ${CUDAFORSTORM_CUDA_HEADERS}
  230. OPTIONS -DSTUFF="" -arch=sm_30
  231. RELEASE -DNDEBUG
  232. DEBUG -g -DDEBUG
  233. )
  234. GENERATE_EXPORT_HEADER( cudaForStorm
  235. BASE_NAME cudaForStorm
  236. EXPORT_MACRO_NAME cudaForStorm_EXPORT
  237. EXPORT_FILE_NAME include/cudaForStorm_Export.h
  238. STATIC_DEFINE cudaForStorm_BUILT_AS_STATIC
  239. )
  240. if (MSVC)
  241. # Add the DebugHelper DLL
  242. set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES} Dbghelp.lib")
  243. target_link_libraries(cudaForStorm "Dbghelp.lib")
  244. endif(MSVC)
  245. # Link against libc++abi if requested. May be needed to build on Linux systems using clang.
  246. if (LINK_LIBCXXABI)
  247. message (STATUS "StoRM (CudaPlugin) - Linking against libc++abi.")
  248. target_link_libraries(cudaForStorm "c++abi")
  249. endif(LINK_LIBCXXABI)
  250. # Install Directive
  251. install(TARGETS cudaForStorm DESTINATION "${STORM_LIB_INSTALL_DIR}/lib")
  252. install(FILES "${PROJECT_SOURCE_DIR}/srcCuda/cudaForStorm.h" "${PROJECT_BINARY_DIR}/include/cudaForStorm_Export.h" DESTINATION "${STORM_LIB_INSTALL_DIR}/include")