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.

255 lines
11 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. # Configure a header file to pass some of the CMake settings to the source code
  114. configure_file (
  115. "${PROJECT_SOURCE_DIR}/storm-cudaplugin-config.h.in"
  116. "${PROJECT_BINARY_DIR}/include/storm-cudaplugin-config.h"
  117. )
  118. # Add the binary dir include directory for storm-config.h
  119. include_directories("${PROJECT_BINARY_DIR}/include")
  120. # Add the main source directory for includes
  121. include_directories("${PROJECT_SOURCE_DIR}/../../src")
  122. #############################################################
  123. ##
  124. ## Source file aggregation and clustering
  125. ##
  126. #############################################################
  127. file(GLOB_RECURSE CUDAFORSTORM_HEADERS ${PROJECT_SOURCE_DIR}/src/*.h)
  128. file(GLOB_RECURSE CUDAFORSTORM_SOURCES ${PROJECT_SOURCE_DIR}/src/*.cpp)
  129. file(GLOB_RECURSE CUDAFORSTORM_CUDA_SOURCES "${PROJECT_SOURCE_DIR}/srcCuda/*.cu")
  130. file(GLOB_RECURSE CUDAFORSTORM_CUDA_HEADERS "${PROJECT_SOURCE_DIR}/srcCuda/*.h")
  131. # Additional include files like the storm-config.h
  132. file(GLOB_RECURSE CUDAFORSTORM_BUILD_HEADERS ${PROJECT_BINARY_DIR}/include/*.h)
  133. # Group the headers and sources
  134. source_group(main FILES ${CUDAFORSTORM_HEADERS} ${CUDAFORSTORM_SOURCES})
  135. source_group(cuda FILES ${CUDAFORSTORM_CUDA_SOURCES} ${CUDAFORSTORM_CUDA_HEADERS})
  136. # Add custom additional include or link directories
  137. if (ADDITIONAL_INCLUDE_DIRS)
  138. message(STATUS "StoRM (CudaPlugin) - Using additional include directories ${ADDITIONAL_INCLUDE_DIRS}")
  139. include_directories(${ADDITIONAL_INCLUDE_DIRS})
  140. endif(ADDITIONAL_INCLUDE_DIRS)
  141. if (ADDITIONAL_LINK_DIRS)
  142. message(STATUS "StoRM (CudaPlugin) - Using additional link directories ${ADDITIONAL_LINK_DIRS}")
  143. link_directories(${ADDITIONAL_LINK_DIRS})
  144. endif(ADDITIONAL_LINK_DIRS)
  145. #############################################################
  146. ##
  147. ## Pre executable-creation link_directories setup
  148. ##
  149. #############################################################
  150. #############################################################
  151. ##
  152. ## CUDA
  153. ##
  154. #############################################################
  155. #set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} --gpu-architecture sm_30)
  156. #target_link_libraries(cudaLibrary ${CUDA_cusparse_LIBRARY})
  157. #ADD_DEPENDENCIES(cudaForStorm cudaLibrary)
  158. #target_link_libraries(cudaForStorm cudaLibrary)
  159. message(STATUS "StoRM (CudaPlugin) - Found CUDA SDK in Version ${CUDA_VERSION_STRING}, sparse lib is ${CUDA_cusparse_LIBRARY}")
  160. include_directories(${CUDA_INCLUDE_DIRS})
  161. #############################################################
  162. ##
  163. ## CUSP
  164. ##
  165. #############################################################
  166. if(CUSP_FOUND)
  167. include_directories(${CUSP_INCLUDE_DIR})
  168. cuda_include_directories(${CUSP_INCLUDE_DIR})
  169. message(STATUS "StoRM (CudaPlugin) - Found CUSP Version ${CUSP_VERSION} in location ${CUSP_INCLUDE_DIR}")
  170. else()
  171. message(FATAL_ERROR "StoRM (CudaPlugin) - Could not find CUSP!")
  172. endif()
  173. #############################################################
  174. ##
  175. ## Thrust
  176. ##
  177. #############################################################
  178. if(THRUST_FOUND)
  179. include_directories(${THRUST_INCLUDE_DIR})
  180. cuda_include_directories(${THRUST_INCLUDE_DIR})
  181. message(STATUS "StoRM (CudaPlugin) - Found Thrust Version ${THRUST_VERSION} in location ${THRUST_INCLUDE_DIR}")
  182. else()
  183. message(FATAL_ERROR "StoRM (CudaPlugin) - Could not find Thrust! Check your CUDA installation.")
  184. endif()
  185. ###############################################################################
  186. ## #
  187. ## Executable Creation #
  188. ## #
  189. ## All link_directories() calls AND include_directories() calls #
  190. ## MUST be made before this point #
  191. ## #
  192. ###############################################################################
  193. include (GenerateExportHeader)
  194. cuda_add_library(cudaForStorm SHARED
  195. ${CUDAFORSTORM_CUDA_SOURCES} ${CUDAFORSTORM_CUDA_HEADERS}
  196. OPTIONS -DSTUFF="" -arch=sm_30
  197. RELEASE -DNDEBUG
  198. DEBUG -g -DDEBUG
  199. )
  200. GENERATE_EXPORT_HEADER( cudaForStorm
  201. BASE_NAME cudaForStorm
  202. EXPORT_MACRO_NAME cudaForStorm_EXPORT
  203. EXPORT_FILE_NAME include/cudaForStorm_Export.h
  204. STATIC_DEFINE cudaForStorm_BUILT_AS_STATIC
  205. )
  206. if (MSVC)
  207. # Add the DebugHelper DLL
  208. set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES} Dbghelp.lib")
  209. target_link_libraries(cudaForStorm "Dbghelp.lib")
  210. endif(MSVC)
  211. # Link against libc++abi if requested. May be needed to build on Linux systems using clang.
  212. if (LINK_LIBCXXABI)
  213. message (STATUS "StoRM (CudaPlugin) - Linking against libc++abi.")
  214. target_link_libraries(cudaForStorm "c++abi")
  215. endif(LINK_LIBCXXABI)
  216. # Install Directive
  217. install(TARGETS cudaForStorm DESTINATION "${STORM_LIB_INSTALL_DIR}/lib")
  218. install(FILES "${PROJECT_SOURCE_DIR}/srcCuda/cudaForStorm.h" "${PROJECT_BINARY_DIR}/include/cudaForStorm_Export.h" DESTINATION "${STORM_LIB_INSTALL_DIR}/include")