# Distributed under the OSI-approved BSD 3-Clause License. See accompanying # file Copyright.txt or https://cmake.org/licensing for details. #[=======================================================================[.rst: IntelDPCPPConfig ------- DPCPP Library to verify DPCPP/SYCL compatability of CMAKE_CXX_COMPILER and passes relevant compiler flags. Result Variables ^^^^^^^^^^^^^^^^ This will define the following variables: ``IntelDPCPP_FOUND`` True if the system has the DPCPP library. ``SYCL_LANGUAGE_VERSION`` The SYCL language spec version by Compiler. ``SYCL_INCLUDE_DIR`` Include directories needed to use SYCL. ``SYCL_IMPLEMENTATION_ID`` The SYCL compiler variant. ``SYCL_FLAGS`` SYCL specific flags for the compiler. Cache Variables ^^^^^^^^^^^^^^^ The following cache variables may also be set: ``SYCL_INCLUDE_DIR`` The directory containing ``sycl.hpp``. ``SYCL_LIBRARY_DIR`` The path to the SYCL library. ``SYCL_FLAGS`` SYCL specific flags for the compiler. ``SYCL_LANGUAGE_VERSION`` The SYCL language spec version by Compiler. .. note:: For now, user needs to set -DCMAKE_CXX_COMPILER or environment of CXX pointing to SYCL compatible compiler ( eg: icx, clang++, icpx) Note: do not set to DPCPP compiler. If set to a Compiler family that supports dpcpp ( eg: IntelLLVM) both DPCPP and SYCL features are enabled. And add this package to user's Cmake config file. .. code-block:: cmake find_package(IntelDPCPP REQUIRED) #]=======================================================================] include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) find_package(PkgConfig QUIET) if(PKG_CONFIG_FOUND) # TODO add dependency package module checks, if any endif() # TODO: can't use find_program to override the CMAKE_CXX_COMPILER as # Platform/ files are executed, potentially for a different compiler. # Safer approach is to make user to define CMAKE_CXX_COMPILER. string(COMPARE EQUAL "${CMAKE_CXX_COMPILER}" "" nocmplr) if(nocmplr) set(IntelDPCPP_FOUND False) set(SYCL_REASON_FAILURE "SYCL: CMAKE_CXX_COMPILER not set!!") set(IntelDPCPP_NOT_FOUND_MESSAGE "${SYCL_REASON_FAILURE}") endif() # Check for known compiler family that supports SYCL if( NOT "x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xClang" AND NOT "x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xIntelLLVM") set(IntelDPCPP_FOUND False) set(SYCL_REASON_FAILURE "Unsupported compiler family ${CMAKE_CXX_COMPILER_ID} and compiler ${CMAKE_CXX_COMPILER}!!") set(IntelDPCPP_NOT_FOUND_MESSAGE "${SYCL_REASON_FAILURE}") return() endif() # Assume that CXX Compiler supports SYCL and then test to verify. # Due to MPI wrappers, CMAKE_CXX_COMPILER is not the best guess. if("x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xIntelLLVM") set(SYCL_COMPILER_GUESS icpx) elseif("x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xClang") set(SYCL_COMPILER_GUESS clang++) else() set(SYCL_COMPILER_GUESS ${CMAKE_CXX_COMPILER}) endif() # find out the full path. find_program(SYCL_COMPILER ${SYCL_COMPILER_GUESS}) # Function to write a test case to verify SYCL features. function(SYCL_FEATURE_TEST_WRITE src) set(pp_if "#if") set(pp_endif "#endif") set(SYCL_TEST_CONTENT "") string(APPEND SYCL_TEST_CONTENT "#include \nusing namespace std;\n") string(APPEND SYCL_TEST_CONTENT "int main(){\n") # Feature tests goes here string(APPEND SYCL_TEST_CONTENT "${pp_if} defined(SYCL_LANGUAGE_VERSION)\n") string(APPEND SYCL_TEST_CONTENT "cout << \"SYCL_LANGUAGE_VERSION=\"<