How to use the Intel C++ Compiler with CMake in Visual Studio

148 Views Asked by At

Visual Studio provides an "Open Folder" workflow for CMake. So far I've been using the default MSVC compiler but I wanted to switch to using the Intel C++ Compiler. To do this, I found this post in the Intel forum. However, I'm using Visual Studio 2022. Furthermore, my Intel C++ compiler is installed under C:\Program Files (x86)\Intel\oneAPI. I assume the updated instructions would now be:

  1. Create a vs2022.cmd (where though?) with the following contents:

call "C:\Program Files (x86)\Intel\oneAPI\compiler\2024.0\bin" (I don't have `ipsxe-comp-vars.bat` in my installation...) intel64 vs2022
start "VS2022" /B "C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\IDE\devenv.exe"
  1. Run the vs2022.cmd file via double-click (in which context?)
  2. In Visual Studio, edit your CMakeSettings.json config file, add the following (for Release configuration):

{
  "name": "x64-IntelEnv-Release",
  "description": "Start visual studio from Intel C++ compiler environment cmd window",
  "generator": "Ninja",
  "configurationType": "Release",
  "buildRoot": "${workspaceRoot}\\..\\cmake-build\\${name}",
  "installRoot": "${workspaceRoot}\\..\\cmake-install\\${name}",
  "cmakeCommandArgs": "",
  "buildCommandArgs": "-v",
  "ctestCommandArgs": "",
  "inheritEnvironments": [ "msvc_x64_x64" ],
  "variables": [
    {
      "name": "CMAKE_CXX_COMPILER",
      "value": "icl.exe",
      "type": "FILEPATH"
    },
    {
      "name": "CMAKE_C_COMPILER",
      "value": "icl.exe",
      "type": "FILEPATH"
    }
  ]
}

  1. Select x64-IntelEnv-Release in the Configurations dropbox. Build.

However, the instructions don't seem to be very clear or applicable for my installations (especially the first step). How can I create a build configuration for the Intel Compiler correctly? Ideally, I also don't want to start Visual Studio in the context of the Intel environment command prompt:

0

There are 0 best solutions below