Skip to content

Commit

Permalink
add several cmake improvements (Apress#85)
Browse files Browse the repository at this point in the history
- detect the SYCL compiler automatically, without a toolchain file
- use different SYCL compilers for Windows and Linux
- improve documentation
  • Loading branch information
bashbaug authored May 24, 2023
1 parent 5210f6a commit 6c5d378
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@

cmake_minimum_required(VERSION 3.10 FATAL_ERROR)

# Try to detect the right SYCL compiler if one is not explicitly specified:
if (NOT CMAKE_CXX_COMPILER)
if (WIN32)
set(CMAKE_CXX_COMPILER icx)
else()
find_program(HAS_ICPX "icpx" NO_CACHE)
if (HAS_ICPX)
set(CMAKE_CXX_COMPILER icpx)
else()
set(CMAKE_CXX_COMPILER clang++)
endif()
endif()
endif()

set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand Down
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ compilation errors due to evolution of the features and extensions.
### Prerequisites

1. An installed SYCL toolchain. See below for details on the tested DPC++ toolchain
1. CMake 3.10 or newer
1. CMake 3.10 or newer (Linux) or CMake 3.25 or newer (Windows)
1. Ninja or Make - to use the build steps described below

To build and use these examples, you will need an installed DPC++ toolchain. For one such toolchain, please visit:
Expand All @@ -43,11 +43,9 @@ Alternatively, much of the toolchain can be built directly from:

https://github.com/intel/llvm

Some of the Chapter 18 examples require an installation of oneDPL, which is available from:
Some of the samples require other dependencies. To disable samples requiring these dependencies use the CMake variables described below.

https://github.com/oneapi-src/oneDPL

### Setting up an environment in which to build the samples
### Setting Up an Environment to Build the Samples

Setup environment variables if using a oneAPI / DPC++ implementation:

Expand All @@ -68,11 +66,11 @@ source /path/to/inteloneapi/setvars.sh
> **Note**:
> CMake supports different [generators](https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html) to create build files for different build systems. Some popular generators are `Unix Makefiles` or `Ninja` when building from the command line, and `Visual Studio`-based generators when building from a Windows IDE. The examples below generate build files for `Unix Makefiles`, but feel free to substitute a different generator, if preferred.
1. Create build files using CMake, specifying the DPC++ toolchain. For example:
1. Create build files using CMake. For example:

```sh
mkdir build && cd build
cmake -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=../dpcpp_toolchain.cmake ..
cmake -G "Unix Makefiles" ..
```

2. Build with the generated build files:
Expand All @@ -87,6 +85,12 @@ source /path/to/inteloneapi/setvars.sh
make install -j8
```

If your SYCL compiler is not detected automatically, or to explicitly specify a different SYCL compiler, use the `CMAKE_CXX_COMPILER` variable. For example:

```sh
cmake -G "Unix Makefiles" -DCMAKE_CXX_COMPILER=/path/to/your/sycl/compiler ..
```

## CMake Variables:

The following CMake variables are supported. To specify one of these variables
Expand Down
5 changes: 0 additions & 5 deletions dpcpp_toolchain.cmake

This file was deleted.

0 comments on commit 6c5d378

Please sign in to comment.