xref: /aosp_15_r20/external/eigen/cmake/FindTriSYCL.cmake (revision bf2c37156dfe67e5dfebd6d394bad8b2ab5804d4)
1#.rst:
2# FindTriSYCL
3#---------------
4#
5# TODO : insert Copyright and licence
6
7#########################
8#  FindTriSYCL.cmake
9#########################
10#
11#  Tools for finding and building with TriSYCL.
12#
13#  User must define TRISYCL_INCLUDE_DIR pointing to the triSYCL
14#  include directory.
15#
16#  Latest version of this file can be found at:
17#    https://github.com/triSYCL/triSYCL
18
19# Requite CMake version 3.5 or higher
20cmake_minimum_required (VERSION 3.5)
21
22# Check that a supported host compiler can be found
23if(CMAKE_COMPILER_IS_GNUCXX)
24  # Require at least gcc 5.4
25  if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.4)
26    message(FATAL_ERROR
27      "host compiler - Not found! (gcc version must be at least 5.4)")
28  else()
29    message(STATUS "host compiler - gcc ${CMAKE_CXX_COMPILER_VERSION}")
30  endif()
31elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
32  # Require at least clang 3.9
33  if (${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 3.9)
34    message(FATAL_ERROR
35      "host compiler - Not found! (clang version must be at least 3.9)")
36  else()
37    message(STATUS "host compiler - clang ${CMAKE_CXX_COMPILER_VERSION}")
38  endif()
39else()
40  message(WARNING
41    "host compiler - Not found! (triSYCL supports GCC and Clang)")
42endif()
43
44#triSYCL options
45option(TRISYCL_OPENMP "triSYCL multi-threading with OpenMP" ON)
46option(TRISYCL_OPENCL "triSYCL OpenCL interoperability mode" OFF)
47option(TRISYCL_NO_ASYNC "triSYCL use synchronous kernel execution" OFF)
48option(TRISYCL_DEBUG "triSCYL use debug mode" OFF)
49option(TRISYCL_DEBUG_STRUCTORS "triSYCL trace of object lifetimes" OFF)
50option(TRISYCL_TRACE_KERNEL "triSYCL trace of kernel execution" OFF)
51
52mark_as_advanced(TRISYCL_OPENMP)
53mark_as_advanced(TRISYCL_OPENCL)
54mark_as_advanced(TRISYCL_NO_ASYNC)
55mark_as_advanced(TRISYCL_DEBUG)
56mark_as_advanced(TRISYCL_DEBUG_STRUCTORS)
57mark_as_advanced(TRISYCL_TRACE_KERNEL)
58
59#triSYCL definitions
60set(CL_SYCL_LANGUAGE_VERSION 220 CACHE STRING
61  "Host language version to be used by trisYCL (default is: 220)")
62set(TRISYCL_CL_LANGUAGE_VERSION 220 CACHE STRING
63  "Device language version to be used by trisYCL (default is: 220)")
64# triSYCL now requires c++17
65set(CMAKE_CXX_STANDARD 17)
66set(CXX_STANDARD_REQUIRED ON)
67
68
69# Find OpenCL package
70include(CMakeFindDependencyMacro)
71if(TRISYCL_OPENCL)
72  find_dependency(OpenCL REQUIRED)
73  if(UNIX)
74    set(BOOST_COMPUTE_INCPATH /usr/include/compute CACHE PATH
75      "Path to Boost.Compute headers (default is: /usr/include/compute)")
76  endif()
77endif()
78
79# Find OpenMP package
80if(TRISYCL_OPENMP)
81  find_dependency(OpenMP REQUIRED)
82endif()
83
84# Find Boost
85find_dependency(Boost 1.58 REQUIRED COMPONENTS chrono log)
86
87# If debug or trace we need boost log
88if(TRISYCL_DEBUG OR TRISYCL_DEBUG_STRUCTORS OR TRISYCL_TRACE_KERNEL)
89  set(LOG_NEEDED ON)
90else()
91  set(LOG_NEEDED OFF)
92endif()
93
94find_dependency(Threads REQUIRED)
95
96# Find triSYCL directory
97if (TRISYCL_INCLUDES AND TRISYCL_LIBRARIES)
98  set(TRISYCL_FIND_QUIETLY TRUE)
99endif ()
100
101find_path(TRISYCL_INCLUDE_DIR
102  NAMES sycl.hpp
103  PATHS $ENV{TRISYCLDIR} $ENV{TRISYCLDIR}/include ${INCLUDE_INSTALL_DIR}
104  PATH_SUFFIXES triSYCL
105)
106
107include(FindPackageHandleStandardArgs)
108find_package_handle_standard_args(TriSYCL DEFAULT_MSG
109                                  TRISYCL_INCLUDE_DIR)
110
111if(NOT TRISYCL_INCLUDE_DIR)
112  message(FATAL_ERROR
113    "triSYCL include directory - Not found! (please set TRISYCL_INCLUDE_DIR")
114else()
115  message(STATUS "triSYCL include directory - Found ${TRISYCL_INCLUDE_DIR}")
116endif()
117
118include(CMakeParseArguments)
119#######################
120#  add_sycl_to_target
121#######################
122function(add_sycl_to_target)
123  set(options)
124  set(one_value_args
125    TARGET
126  )
127  set(multi_value_args
128    SOURCES
129  )
130  cmake_parse_arguments(ADD_SYCL_ARGS
131    "${options}"
132    "${one_value_args}"
133    "${multi_value_args}"
134    ${ARGN}
135  )
136
137  # Add include directories to the "#include <>" paths
138  target_include_directories (${ADD_SYCL_ARGS_TARGET} PUBLIC
139    ${TRISYCL_INCLUDE_DIR}
140    ${Boost_INCLUDE_DIRS}
141    $<$<BOOL:${TRISYCL_OPENCL}>:${OpenCL_INCLUDE_DIRS}>
142    $<$<BOOL:${TRISYCL_OPENCL}>:${BOOST_COMPUTE_INCPATH}>)
143
144  # Link dependencies
145  target_link_libraries(${ADD_SYCL_ARGS_TARGET}
146    $<$<BOOL:${TRISYCL_OPENCL}>:${OpenCL_LIBRARIES}>
147    Threads::Threads
148    $<$<BOOL:${LOG_NEEDED}>:Boost::log>
149    Boost::chrono)
150
151  # Compile definitions
152  target_compile_definitions(${ADD_SYCL_ARGS_TARGET} PUBLIC
153    EIGEN_SYCL_TRISYCL
154    $<$<BOOL:${TRISYCL_NO_ASYNC}>:TRISYCL_NO_ASYNC>
155    $<$<BOOL:${TRISYCL_OPENCL}>:TRISYCL_OPENCL>
156    $<$<BOOL:${TRISYCL_DEBUG}>:TRISYCL_DEBUG>
157    $<$<BOOL:${TRISYCL_DEBUG_STRUCTORS}>:TRISYCL_DEBUG_STRUCTORS>
158    $<$<BOOL:${TRISYCL_TRACE_KERNEL}>:TRISYCL_TRACE_KERNEL>
159    $<$<BOOL:${LOG_NEEDED}>:BOOST_LOG_DYN_LINK>)
160
161  # C++ and OpenMP requirements
162  target_compile_options(${ADD_SYCL_ARGS_TARGET} PUBLIC
163    ${TRISYCL_COMPILE_OPTIONS}
164    $<$<BOOL:${TRISYCL_OPENMP}>:${OpenMP_CXX_FLAGS}>)
165
166  if(${TRISYCL_OPENMP} AND (NOT WIN32))
167    # Does not support generator expressions
168    set_target_properties(${ADD_SYCL_ARGS_TARGET}
169      PROPERTIES
170      LINK_FLAGS ${OpenMP_CXX_FLAGS})
171  endif()
172
173endfunction()
174