FindTriSYCL.cmake (5111B)
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 20 cmake_minimum_required (VERSION 3.5) 21 22 # Check that a supported host compiler can be found 23 if(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() 31 elseif ("${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() 39 else() 40 message(WARNING 41 "host compiler - Not found! (triSYCL supports GCC and Clang)") 42 endif() 43 44 #triSYCL options 45 option(TRISYCL_OPENMP "triSYCL multi-threading with OpenMP" ON) 46 option(TRISYCL_OPENCL "triSYCL OpenCL interoperability mode" OFF) 47 option(TRISYCL_NO_ASYNC "triSYCL use synchronous kernel execution" OFF) 48 option(TRISYCL_DEBUG "triSCYL use debug mode" OFF) 49 option(TRISYCL_DEBUG_STRUCTORS "triSYCL trace of object lifetimes" OFF) 50 option(TRISYCL_TRACE_KERNEL "triSYCL trace of kernel execution" OFF) 51 52 mark_as_advanced(TRISYCL_OPENMP) 53 mark_as_advanced(TRISYCL_OPENCL) 54 mark_as_advanced(TRISYCL_NO_ASYNC) 55 mark_as_advanced(TRISYCL_DEBUG) 56 mark_as_advanced(TRISYCL_DEBUG_STRUCTORS) 57 mark_as_advanced(TRISYCL_TRACE_KERNEL) 58 59 #triSYCL definitions 60 set(CL_SYCL_LANGUAGE_VERSION 220 CACHE STRING 61 "Host language version to be used by trisYCL (default is: 220)") 62 set(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 65 set(CMAKE_CXX_STANDARD 17) 66 set(CXX_STANDARD_REQUIRED ON) 67 68 69 # Find OpenCL package 70 include(CMakeFindDependencyMacro) 71 if(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() 77 endif() 78 79 # Find OpenMP package 80 if(TRISYCL_OPENMP) 81 find_dependency(OpenMP REQUIRED) 82 endif() 83 84 # Find Boost 85 find_dependency(Boost 1.58 REQUIRED COMPONENTS chrono log) 86 87 # If debug or trace we need boost log 88 if(TRISYCL_DEBUG OR TRISYCL_DEBUG_STRUCTORS OR TRISYCL_TRACE_KERNEL) 89 set(LOG_NEEDED ON) 90 else() 91 set(LOG_NEEDED OFF) 92 endif() 93 94 find_dependency(Threads REQUIRED) 95 96 # Find triSYCL directory 97 if (TRISYCL_INCLUDES AND TRISYCL_LIBRARIES) 98 set(TRISYCL_FIND_QUIETLY TRUE) 99 endif () 100 101 find_path(TRISYCL_INCLUDE_DIR 102 NAMES sycl.hpp 103 PATHS $ENV{TRISYCLDIR} $ENV{TRISYCLDIR}/include ${INCLUDE_INSTALL_DIR} 104 PATH_SUFFIXES triSYCL 105 ) 106 107 include(FindPackageHandleStandardArgs) 108 find_package_handle_standard_args(TriSYCL DEFAULT_MSG 109 TRISYCL_INCLUDE_DIR) 110 111 if(NOT TRISYCL_INCLUDE_DIR) 112 message(FATAL_ERROR 113 "triSYCL include directory - Not found! (please set TRISYCL_INCLUDE_DIR") 114 else() 115 message(STATUS "triSYCL include directory - Found ${TRISYCL_INCLUDE_DIR}") 116 endif() 117 118 include(CMakeParseArguments) 119 ####################### 120 # add_sycl_to_target 121 ####################### 122 function(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 173 endfunction()