# Using CMake with Data Parallel C++ (DPC++)

The following content is OS specific.

## Linux*

Using CMake with the Intel® oneAPI DPC++/C++ Compiler on Linux is supported. You may need to set your `CXX` or `CMAKE_CXX_COMPILER` string to `dpcpp`. For example:

    $ CXX=dpcpp cmake ../

-OR-

    $ cmake –DCMAKE_CXX_COMPILER=dpcpp ../

### Note

CMake and Ninja Generators are also supported.

## Windows*

Note the differences in behavior between build system generation targets when you use CMake to compile with the Intel oneAPI DPC++/C++ Compiler. The two supported generators are Microsoft Visual Studio* and CMake*/Ninja*.

- Microsoft Visual Studio Generators: The generators are supported, but you need to install plugins for Microsoft Visual Studio. Example:

      cmake -T "Intel® oneAPI DPC++ Compiler" -DCMAKE_CXX_COMPILER=dpcpp-cl ../

- CMake/Ninja Generators: The default behavior with CMake, when you use Ninja or CMake generators, does not automatically link DPC++ applications. CMake attempts to link with `lld-link`, which correctly links an application without errors (if you are explicitly linking to SYCL*), but the application does not run SYCL kernels correctly. To link and run without errors, you must use `dpcpp-cl`.

## Support

Intel is working to contribute support into CMake for the Intel oneAPI DPC++/C++ Compiler.

Use the following workarounds when directing CMake to use `dpcpp` as the linker. See the table below for specific built target considerations.

Target Type | Status | Note
--- | --- | ---
Executable | Workaround available | See the workaround section.
Library (Static) | Workaround available | See the workaround section. ### Note Pay special attention to `llvm-ar` and `llvm-ranlib` requirements.
Library (Shared) | Fails (some solutions are available, but are untested) | A mix of MVC and non-MVC flags causes issues due to incompatibilities.

## Workaround

The following workaround contains the CMake flags/directives that you need to be set before the `projects()` line.

    ```

    set(CMAKE_CXX_COMPILER "dpcpp-cl")
    include (Platform/Windows-Clang)
    set(CMAKE_LINKER "dpcpp-cl")
    set(CMAKE_AR "llvm-ar")
    set(CMAKE_RANLIB "llvm-ranlib")
    set(CMAKE_CXX_STANDARD 17)
    set(CMAKE_CXX_FLAGS "/EHsc")

    project(project-name CXX)

    ```

For static library targets, you need to add `llvm-ar` and `llvm-ranlib` to your `PATH`. `llvm-ar` is included with the Intel oneAPI DPC++/C++ Compiler, but `llvm-ranlib` is not. `llvm-ranlib` can be found in the Intel® Distribution for Python, which is part of the LLVM/Clang installation available through the Microsoft Visual Studio Package manager.

Parent topic: Using the Command Line