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.

234 lines
9.6 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. find_package(CUDA REQUIRED)
  30. find_package(Doxygen REQUIRED)
  31. find_package(Threads REQUIRED)
  32. find_package(Thrust REQUIRED)
  33. # If the DEBUG option was turned on, we will target a debug version and a release version otherwise
  34. if (CUDAFORSTORM_DEBUG)
  35. set (CMAKE_BUILD_TYPE "DEBUG")
  36. else()
  37. set (CMAKE_BUILD_TYPE "RELEASE")
  38. endif()
  39. message(STATUS "StoRM (CudaPlugin) - Building ${CMAKE_BUILD_TYPE} version.")
  40. message(STATUS "StoRM (CudaPlugin) - CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
  41. message(STATUS "StoRM (CudaPlugin) - CMAKE_BUILD_TYPE (ENV): $ENV{CMAKE_BUILD_TYPE}")
  42. #############################################################
  43. ##
  44. ## CUDA Options
  45. ##
  46. #############################################################
  47. SET (CUDA_VERBOSE_BUILD ON CACHE BOOL "nvcc verbose" FORCE)
  48. set(CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE ON)
  49. set(BUILD_SHARED_LIBS OFF)
  50. set(CUDA_SEPARABLE_COMPILATION ON)
  51. #set(CUDA_NVCC_FLAGS "-arch=sm_30")
  52. # Because the FindCUDA.cmake file has a path related bug, two folders have to be present
  53. file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/CMakeFiles/cudaForStorm.dir/Debug")
  54. file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/CMakeFiles/cudaForStorm.dir/Release")
  55. #############################################################
  56. ##
  57. ## Compiler specific settings and definitions
  58. ##
  59. #############################################################
  60. if(CMAKE_COMPILER_IS_GNUCC)
  61. message(STATUS "StoRM (CudaPlugin) - Using Compiler Configuration: GCC")
  62. # Set standard flags for GCC
  63. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -funroll-loops")
  64. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -pedantic")
  65. elseif(MSVC)
  66. message(STATUS "StoRM (CudaPlugin) - Using Compiler Configuration: MSVC")
  67. # required for GMM to compile, ugly error directive in their code
  68. add_definitions(/D_SCL_SECURE_NO_DEPRECATE /D_CRT_SECURE_NO_WARNINGS)
  69. # 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)
  70. add_definitions(/bigobj)
  71. # required by GTest and PrismGrammar::createIntegerVariable
  72. add_definitions(/D_VARIADIC_MAX=10)
  73. # Windows.h breaks GMM in gmm_except.h because of its macro definition for min and max
  74. add_definitions(/DNOMINMAX)
  75. else(CLANG)
  76. message(STATUS "StoRM (CudaPlugin) - Using Compiler Configuration: Clang (LLVM)")
  77. # As CLANG is not set as a variable, we need to set it in case we have not matched another compiler.
  78. set (CLANG ON)
  79. # Set standard flags for clang
  80. set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -funroll-loops -O3")
  81. if(UNIX AND NOT APPLE AND NOT USE_LIBCXX)
  82. set(CLANG_STDLIB libstdc++)
  83. message(STATUS "StoRM (CudaPlugin) - Linking against libstdc++")
  84. else()
  85. set(CLANG_STDLIB libc++)
  86. message(STATUS "StoRM (CudaPlugin) - Linking against libc++")
  87. # Set up some Xcode specific settings
  88. set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++11")
  89. set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
  90. endif()
  91. 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")
  92. set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
  93. endif()
  94. #############################################################
  95. ##
  96. ## CMake-generated Config File for StoRM
  97. ##
  98. #############################################################
  99. # Configure a header file to pass some of the CMake settings to the source code
  100. configure_file (
  101. "${PROJECT_SOURCE_DIR}/../../storm-config.h.in"
  102. "${PROJECT_BINARY_DIR}/include/storm-config.h"
  103. )
  104. # Add the binary dir include directory for storm-config.h
  105. include_directories("${PROJECT_BINARY_DIR}/include")
  106. # Add the main source directory for includes
  107. include_directories("${PROJECT_SOURCE_DIR}/../../src")
  108. #############################################################
  109. ##
  110. ## Source file aggregation and clustering
  111. ##
  112. #############################################################
  113. file(GLOB_RECURSE CUDAFORSTORM_HEADERS ${PROJECT_SOURCE_DIR}/src/*.h)
  114. file(GLOB_RECURSE CUDAFORSTORM_SOURCES ${PROJECT_SOURCE_DIR}/src/*.cpp)
  115. file(GLOB_RECURSE CUDAFORSTORM_CUDA_SOURCES "${PROJECT_SOURCE_DIR}/srcCuda/*.cu")
  116. file(GLOB_RECURSE CUDAFORSTORM_CUDA_HEADERS "${PROJECT_SOURCE_DIR}/srcCuda/*.h")
  117. # Additional include files like the storm-config.h
  118. file(GLOB_RECURSE CUDAFORSTORM_BUILD_HEADERS ${PROJECT_BINARY_DIR}/include/*.h)
  119. # Group the headers and sources
  120. source_group(main FILES ${CUDAFORSTORM_HEADERS} ${CUDAFORSTORM_SOURCES})
  121. source_group(cuda FILES ${CUDAFORSTORM_CUDA_SOURCES} ${CUDAFORSTORM_CUDA_HEADERS})
  122. # Add custom additional include or link directories
  123. if (ADDITIONAL_INCLUDE_DIRS)
  124. message(STATUS "StoRM (CudaPlugin) - Using additional include directories ${ADDITIONAL_INCLUDE_DIRS}")
  125. include_directories(${ADDITIONAL_INCLUDE_DIRS})
  126. endif(ADDITIONAL_INCLUDE_DIRS)
  127. if (ADDITIONAL_LINK_DIRS)
  128. message(STATUS "StoRM (CudaPlugin) - Using additional link directories ${ADDITIONAL_LINK_DIRS}")
  129. link_directories(${ADDITIONAL_LINK_DIRS})
  130. endif(ADDITIONAL_LINK_DIRS)
  131. #############################################################
  132. ##
  133. ## Pre executable-creation link_directories setup
  134. ##
  135. #############################################################
  136. ###############################################################################
  137. ## #
  138. ## Executable Creation #
  139. ## #
  140. ## All link_directories() calls MUST be made before this point #
  141. ## #
  142. ###############################################################################
  143. include (GenerateExportHeader)
  144. #add_library(cudaForStorm SHARED ${CUDAFORSTORM_HEADERS} ${CUDAFORSTORM_SOURCES})
  145. #GENERATE_EXPORT_HEADER( cudaForStorm
  146. # BASE_NAME cudaForStorm
  147. # EXPORT_MACRO_NAME cudaForStorm_EXPORT
  148. # EXPORT_FILE_NAME include/cudaForStorm_Export.h
  149. # STATIC_DEFINE cudaForStorm_BUILT_AS_STATIC
  150. #)
  151. #############################################################
  152. ##
  153. ## CUDA
  154. ##
  155. #############################################################
  156. #set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} --gpu-architecture sm_30)
  157. cuda_add_library(cudaForStorm SHARED
  158. ${CUDAFORSTORM_CUDA_SOURCES} ${CUDAFORSTORM_CUDA_HEADERS}
  159. OPTIONS -DSTUFF="" -arch=sm_30
  160. RELEASE -DNDEBUG
  161. DEBUG -g -DDEBUG
  162. )
  163. GENERATE_EXPORT_HEADER( cudaForStorm
  164. BASE_NAME cudaForStorm
  165. EXPORT_MACRO_NAME cudaForStorm_EXPORT
  166. EXPORT_FILE_NAME include/cudaForStorm_Export.h
  167. STATIC_DEFINE cudaForStorm_BUILT_AS_STATIC
  168. )
  169. #target_link_libraries(cudaLibrary ${CUDA_cusparse_LIBRARY})
  170. #ADD_DEPENDENCIES(cudaForStorm cudaLibrary)
  171. #target_link_libraries(cudaForStorm cudaLibrary)
  172. message(STATUS "StoRM (CudaPlugin) - Found CUDA SDK in Version ${CUDA_VERSION_STRING}, sparse lib is ${CUDA_cusparse_LIBRARY}")
  173. include_directories(${CUDA_INCLUDE_DIRS})
  174. #############################################################
  175. ##
  176. ## Threads
  177. ##
  178. #############################################################
  179. include_directories(${THREADS_INCLUDE_DIRS})
  180. target_link_libraries(cudaForStorm ${CMAKE_THREAD_LIBS_INIT})
  181. #############################################################
  182. ##
  183. ## Thrust
  184. ##
  185. #############################################################
  186. include_directories(${THRUST_INCLUDE_DIR})
  187. message(STATUS "StoRM (CudaPlugin) - Found Thrust Version ${THRUST_VERSION}")
  188. if (MSVC)
  189. # Add the DebugHelper DLL
  190. set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES} Dbghelp.lib")
  191. target_link_libraries(cudaForStorm "Dbghelp.lib")
  192. endif(MSVC)
  193. # Link against libc++abi if requested. May be needed to build on Linux systems using clang.
  194. if (LINK_LIBCXXABI)
  195. message (STATUS "StoRM (CudaPlugin) - Linking against libc++abi.")
  196. target_link_libraries(cudaForStorm "c++abi")
  197. endif(LINK_LIBCXXABI)
  198. # Install Directive
  199. install(TARGETS cudaForStorm DESTINATION "${STORM_LIB_INSTALL_DIR}/lib")
  200. install(FILES "${PROJECT_SOURCE_DIR}/srcCuda/cudaForStorm.h" "${PROJECT_BINARY_DIR}/include/cudaForStorm_Export.h" DESTINATION "${STORM_LIB_INSTALL_DIR}/include")