FindTriSYCL.cmake 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 STRING
  55. "Host language version to be used by trisYCL (default is: 220)")
  56. set(TRISYCL_CL_LANGUAGE_VERSION 220 CACHE STRING
  57. "Device language version to be used by trisYCL (default is: 220)")
  58. # triSYCL now requires c++17
  59. set(CMAKE_CXX_STANDARD 17)
  60. set(CXX_STANDARD_REQUIRED ON)
  61. # Find OpenCL package
  62. include(CMakeFindDependencyMacro)
  63. if(TRISYCL_OPENCL)
  64. find_dependency(OpenCL REQUIRED)
  65. if(UNIX)
  66. set(BOOST_COMPUTE_INCPATH /usr/include/compute CACHE PATH
  67. "Path to Boost.Compute headers (default is: /usr/include/compute)")
  68. endif()
  69. endif()
  70. # Find OpenMP package
  71. if(TRISYCL_OPENMP)
  72. find_dependency(OpenMP REQUIRED)
  73. endif()
  74. # Find Boost
  75. find_dependency(Boost 1.58 REQUIRED COMPONENTS chrono log)
  76. # If debug or trace we need boost log
  77. if(TRISYCL_DEBUG OR TRISYCL_DEBUG_STRUCTORS OR TRISYCL_TRACE_KERNEL)
  78. set(LOG_NEEDED ON)
  79. else()
  80. set(LOG_NEEDED OFF)
  81. endif()
  82. find_dependency(Threads REQUIRED)
  83. # Find triSYCL directory
  84. if (TRISYCL_INCLUDES AND TRISYCL_LIBRARIES)
  85. set(TRISYCL_FIND_QUIETLY TRUE)
  86. endif ()
  87. find_path(TRISYCL_INCLUDE_DIR
  88. NAMES sycl.hpp
  89. PATHS $ENV{TRISYCLDIR} $ENV{TRISYCLDIR}/include ${INCLUDE_INSTALL_DIR}
  90. PATH_SUFFIXES triSYCL
  91. )
  92. include(FindPackageHandleStandardArgs)
  93. find_package_handle_standard_args(TriSYCL DEFAULT_MSG
  94. TRISYCL_INCLUDE_DIR)
  95. if(NOT TRISYCL_INCLUDE_DIR)
  96. message(FATAL_ERROR
  97. "triSYCL include directory - Not found! (please set TRISYCL_INCLUDE_DIR")
  98. else()
  99. message(STATUS "triSYCL include directory - Found ${TRISYCL_INCLUDE_DIR}")
  100. endif()
  101. include(CMakeParseArguments)
  102. #######################
  103. # add_sycl_to_target
  104. #######################
  105. function(add_sycl_to_target)
  106. set(options)
  107. set(one_value_args
  108. TARGET
  109. )
  110. set(multi_value_args
  111. SOURCES
  112. )
  113. cmake_parse_arguments(ADD_SYCL_ARGS
  114. "${options}"
  115. "${one_value_args}"
  116. "${multi_value_args}"
  117. ${ARGN}
  118. )
  119. # Add include directories to the "#include <>" paths
  120. target_include_directories (${ADD_SYCL_ARGS_TARGET} PUBLIC
  121. ${TRISYCL_INCLUDE_DIR}
  122. ${Boost_INCLUDE_DIRS}
  123. $<$<BOOL:${TRISYCL_OPENCL}>:${OpenCL_INCLUDE_DIRS}>
  124. $<$<BOOL:${TRISYCL_OPENCL}>:${BOOST_COMPUTE_INCPATH}>)
  125. # Link dependencies
  126. target_link_libraries(${ADD_SYCL_ARGS_TARGET}
  127. $<$<BOOL:${TRISYCL_OPENCL}>:${OpenCL_LIBRARIES}>
  128. Threads::Threads
  129. $<$<BOOL:${LOG_NEEDED}>:Boost::log>
  130. Boost::chrono)
  131. # Compile definitions
  132. target_compile_definitions(${ADD_SYCL_ARGS_TARGET} PUBLIC
  133. EIGEN_SYCL_TRISYCL
  134. $<$<BOOL:${TRISYCL_NO_ASYNC}>:TRISYCL_NO_ASYNC>
  135. $<$<BOOL:${TRISYCL_OPENCL}>:TRISYCL_OPENCL>
  136. $<$<BOOL:${TRISYCL_DEBUG}>:TRISYCL_DEBUG>
  137. $<$<BOOL:${TRISYCL_DEBUG_STRUCTORS}>:TRISYCL_DEBUG_STRUCTORS>
  138. $<$<BOOL:${TRISYCL_TRACE_KERNEL}>:TRISYCL_TRACE_KERNEL>
  139. $<$<BOOL:${LOG_NEEDED}>:BOOST_LOG_DYN_LINK>)
  140. # C++ and OpenMP requirements
  141. target_compile_options(${ADD_SYCL_ARGS_TARGET} PUBLIC
  142. ${TRISYCL_COMPILE_OPTIONS}
  143. $<$<BOOL:${TRISYCL_OPENMP}>:${OpenMP_CXX_FLAGS}>)
  144. if(${TRISYCL_OPENMP} AND (NOT WIN32))
  145. # Does not support generator expressions
  146. set_target_properties(${ADD_SYCL_ARGS_TARGET}
  147. PROPERTIES
  148. LINK_FLAGS ${OpenMP_CXX_FLAGS})
  149. endif()
  150. endfunction()