FindTriSYCL.cmake 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #.rst:
  2. # FindTriSYCL
  3. #---------------
  4. #
  5. # TODO : insert Copyright and licence
  6. #########################
  7. # FindTriSYCL.cmake
  8. #########################
  9. #
  10. # Tools for finding and building with TriSYCL.
  11. #
  12. # User must define TRISYCL_INCLUDE_DIR pointing to the triSYCL
  13. # include directory.
  14. #
  15. # Latest version of this file can be found at:
  16. # https://github.com/triSYCL/triSYCL
  17. # Requite CMake version 3.5 or higher
  18. cmake_minimum_required (VERSION 3.5)
  19. # Check that a supported host compiler can be found
  20. if(CMAKE_COMPILER_IS_GNUCXX)
  21. # Require at least gcc 5.4
  22. if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.4)
  23. message(FATAL_ERROR
  24. "host compiler - Not found! (gcc version must be at least 5.4)")
  25. else()
  26. message(STATUS "host compiler - gcc ${CMAKE_CXX_COMPILER_VERSION}")
  27. endif()
  28. elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  29. # Require at least clang 3.9
  30. if (${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 3.9)
  31. message(FATAL_ERROR
  32. "host compiler - Not found! (clang version must be at least 3.9)")
  33. else()
  34. message(STATUS "host compiler - clang ${CMAKE_CXX_COMPILER_VERSION}")
  35. endif()
  36. else()
  37. message(WARNING
  38. "host compiler - Not found! (triSYCL supports GCC and Clang)")
  39. endif()
  40. #triSYCL options
  41. option(TRISYCL_OPENMP "triSYCL multi-threading with OpenMP" ON)
  42. option(TRISYCL_OPENCL "triSYCL OpenCL interoperability mode" OFF)
  43. option(TRISYCL_NO_ASYNC "triSYCL use synchronous kernel execution" OFF)
  44. option(TRISYCL_DEBUG "triSCYL use debug mode" OFF)
  45. option(TRISYCL_DEBUG_STRUCTORS "triSYCL trace of object lifetimes" OFF)
  46. option(TRISYCL_TRACE_KERNEL "triSYCL trace of kernel execution" OFF)
  47. mark_as_advanced(TRISYCL_OPENMP)
  48. mark_as_advanced(TRISYCL_OPENCL)
  49. mark_as_advanced(TRISYCL_NO_ASYNC)
  50. mark_as_advanced(TRISYCL_DEBUG)
  51. mark_as_advanced(TRISYCL_DEBUG_STRUCTORS)
  52. mark_as_advanced(TRISYCL_TRACE_KERNEL)
  53. #triSYCL definitions
  54. set(CL_SYCL_LANGUAGE_VERSION 220 CACHE VERSION
  55. "Host language version to be used by trisYCL (default is: 220)")
  56. set(TRISYCL_CL_LANGUAGE_VERSION 220 CACHE VERSION
  57. "Device language version to be used by trisYCL (default is: 220)")
  58. #set(TRISYCL_COMPILE_OPTIONS "-std=c++1z -Wall -Wextra")
  59. set(CMAKE_CXX_STANDARD 14)
  60. set(CXX_STANDARD_REQUIRED ON)
  61. # Find OpenCL package
  62. if(TRISYCL_OPENCL)
  63. find_package(OpenCL REQUIRED)
  64. if(UNIX)
  65. set(BOOST_COMPUTE_INCPATH /usr/include/compute CACHE PATH
  66. "Path to Boost.Compute headers (default is: /usr/include/compute)")
  67. endif()
  68. endif()
  69. # Find OpenMP package
  70. if(TRISYCL_OPENMP)
  71. find_package(OpenMP REQUIRED)
  72. endif()
  73. # Find Boost
  74. find_package(Boost 1.58 REQUIRED COMPONENTS chrono log)
  75. # If debug or trace we need boost log
  76. if(TRISYCL_DEBUG OR TRISYCL_DEBUG_STRUCTORS OR TRISYCL_TRACE_KERNEL)
  77. set(LOG_NEEDED ON)
  78. else()
  79. set(LOG_NEEDED OFF)
  80. endif()
  81. find_package(Threads REQUIRED)
  82. # Find triSYCL directory
  83. if(NOT TRISYCL_INCLUDE_DIR)
  84. message(FATAL_ERROR
  85. "triSYCL include directory - Not found! (please set TRISYCL_INCLUDE_DIR")
  86. else()
  87. message(STATUS "triSYCL include directory - Found ${TRISYCL_INCLUDE_DIR}")
  88. endif()
  89. #######################
  90. # add_sycl_to_target
  91. #######################
  92. #
  93. # Sets the proper flags and includes for the target compilation.
  94. #
  95. # targetName : Name of the target to add a SYCL to.
  96. # sourceFile : Source file to be compiled for SYCL.
  97. # binaryDir : Intermediate directory to output the integration header.
  98. #
  99. function(add_sycl_to_target targetName sourceFile binaryDir)
  100. # Add include directories to the "#include <>" paths
  101. target_include_directories (${targetName} PUBLIC
  102. ${TRISYCL_INCLUDE_DIR}
  103. ${Boost_INCLUDE_DIRS}
  104. $<$<BOOL:${TRISYCL_OPENCL}>:${OpenCL_INCLUDE_DIRS}>
  105. $<$<BOOL:${TRISYCL_OPENCL}>:${BOOST_COMPUTE_INCPATH}>)
  106. # Link dependencies
  107. target_link_libraries(${targetName} PUBLIC
  108. $<$<BOOL:${TRISYCL_OPENCL}>:${OpenCL_LIBRARIES}>
  109. Threads::Threads
  110. $<$<BOOL:${LOG_NEEDED}>:Boost::log>
  111. Boost::chrono)
  112. # Compile definitions
  113. target_compile_definitions(${targetName} PUBLIC
  114. $<$<BOOL:${TRISYCL_NO_ASYNC}>:TRISYCL_NO_ASYNC>
  115. $<$<BOOL:${TRISYCL_OPENCL}>:TRISYCL_OPENCL>
  116. $<$<BOOL:${TRISYCL_DEBUG}>:TRISYCL_DEBUG>
  117. $<$<BOOL:${TRISYCL_DEBUG_STRUCTORS}>:TRISYCL_DEBUG_STRUCTORS>
  118. $<$<BOOL:${TRISYCL_TRACE_KERNEL}>:TRISYCL_TRACE_KERNEL>
  119. $<$<BOOL:${LOG_NEEDED}>:BOOST_LOG_DYN_LINK>)
  120. # C++ and OpenMP requirements
  121. target_compile_options(${targetName} PUBLIC
  122. ${TRISYCL_COMPILE_OPTIONS}
  123. $<$<BOOL:${TRISYCL_OPENMP}>:${OpenMP_CXX_FLAGS}>)
  124. if(${TRISYCL_OPENMP} AND (NOT WIN32))
  125. # Does not support generator expressions
  126. set_target_properties(${targetName}
  127. PROPERTIES
  128. LINK_FLAGS ${OpenMP_CXX_FLAGS})
  129. endif()
  130. endfunction()