Skip to content

Commit fa603c3

Browse files
authored
[SYCL][DOC] Add short guideline on using CMake with DPC++ (#6668)
1 parent 0eeef2b commit fa603c3

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

sycl/doc/GetStartedGuide.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ and a wide range of compute accelerators such as GPU and FPGA.
2525
- [Run DPC++ E2E test suite](#run-dpc-e2e-test-suite)
2626
- [Run Khronos\* SYCL\* conformance test suite (optional)](#run-khronos-sycl-conformance-test-suite-optional)
2727
- [Run simple DPC++ application](#run-simple-dpc-application)
28+
- [Build DPC++ application with CMake](#build-dpc-application-with-cmake)
2829
- [Code the program for a specific GPU](#code-the-program-for-a-specific-gpu)
2930
- [Using the DPC++ toolchain on CUDA platforms](#using-the-dpc-toolchain-on-cuda-platforms)
3031
- [C++ standard](#c-standard)
@@ -709,6 +710,34 @@ device selectors (e.g. `sycl::cpu_selector`, `sycl::gpu_selector`,
709710
explained in following section [Code the program for a specific
710711
GPU](#code-the-program-for-a-specific-gpu).
711712
713+
### Build DPC++ application with CMake
714+
715+
DPC++ applications can be built with CMake by simply using DPC++ as the C++
716+
compiler and by adding the SYCL specific flags. For example assuming `clang++`
717+
is on the `PATH`, a minimal `CMakeLists.txt` file for the sample above would be:
718+
719+
```cmake
720+
cmake_minimum_required(VERSION 3.14)
721+
722+
# Modifying the compiler should be done before the project line
723+
set(CMAKE_CXX_COMPILER "clang++")
724+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsycl")
725+
726+
project(simple-sycl-app)
727+
728+
add_executable(simple-sycl-app simple-sycl-app.cpp)
729+
```
730+
731+
NOTE: compiling SYCL programs requires passing the SYCL flags to `clang++` for
732+
both the compilation and linking stages, so using `add_compile_options` to pass
733+
the SYCL flags is not enough on its own, they should also be passed to
734+
`add_link_options`, or more simply the SYCL flags can just be added to
735+
`CMAKE_CXX_FLAGS`.
736+
737+
NOTE: When linking a SYCL application, `clang++` will implicitly link it against
738+
`libsycl.so`, so there is no need to add `-lsycl` to `target_link_libraries` in
739+
the CMake.
740+
712741
### Code the program for a specific GPU
713742
714743
To specify OpenCL device SYCL provides the abstract `sycl::device_selector`

0 commit comments

Comments
 (0)