0

I tried to determine if CMake is an option to simplify the cross-platform development of a c++ library that I am working on. Linux is done. Now, I am trying to use CMake on windows. Setting up CMake using the Visual Studio Generators of CMake was also not an issue. I tested it also on a simple program "hello_world.cpp".

mkdir build
cd build
cmake ..
msbuild hello_world.sln

The problem arises when I try to configure CMake for Microsoft Visual Studio with Intel Compilers as explained by Intel. Following Intel for the simple program "hello_world.cpp", I did the following in the power-shell

mkdir build
cd build
cmd.exe "/K" '"C:\Program Files (x86)\Intel\oneAPI\setvars.bat" && powershell'
cmake -T "Intel(R) oneAPI DPC++ Compiler" -DCMAKE_CXX_COMPILER="dpcpp" ..

the output was

:: initializing oneAPI environment...
   Initializing Visual Studio command-line environment...
   Visual Studio version 16.11.19 environment configured.
   "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\"
   Visual Studio command-line environment initialized for: 'x64'
:  advisor -- latest
:  compiler -- latest
:  dal -- latest
:  debugger -- latest
:  dev-utilities -- latest
:  dnnl -- latest
:  dpcpp-ct -- latest
:  dpl -- latest
:  inspector -- latest
:  intelpython -- latest
:  ipp -- latest
:  ippcp -- latest
:  itac -- latest
:  mkl -- latest
:  mpi -- latest
:  tbb -- latest
:  vpl -- latest
:  vtune -- latest
:: oneAPI environment initialized ::
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows

-- Building for: Visual Studio 16 2019
CMake Error at CMakeLists.txt:1 (project):
  Failed to run MSBuild command:

    C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/MSBuild/Current/Bin/MSBuild.exe

  to get the value of VCTargetsPath:

    Microsoft (R) Build Engine version 16.11.2+f32259642 for .NET Framework
    Copyright (C) Microsoft Corporation. All rights reserved.

    Build started 21/09/2022 15:52:09.
    Project "C:\Users\RaphaelSchiedung\source\hello_world\build\CMakeFiles\3.24.2\VCTargetsPath.vcxproj" on node 1 (default targets).
    C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppBuild.targets(439,5): error MSB8020: The build tools for Intel(R) oneAPI DPC++ Compiler (Platform Toolset = 'Intel(R) oneAPI DPC++ Compiler') cannot be found. To build using the Intel(R) oneAPI DPC++ Compiler build tools, please install Intel(R) oneAPI DPC++ Compiler build tools.  Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Retarget solution". [C:\Users\RaphaelSchiedung\source\hello_world\build\CMakeFiles\3.24.2\VCTargetsPath.vcxproj]
    Done Building Project "C:\Users\RaphaelSchiedung\source\hello_world\build\CMakeFiles\3.24.2\VCTargetsPath.vcxproj" (default targets) -- FAILED.

    Build FAILED.

    "C:\Users\RaphaelSchiedung\source\hello_world\build\CMakeFiles\3.24.2\VCTargetsPath.vcxproj" (default target) (1) ->
    (PrepareForBuild target) ->
      C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppBuild.targets(439,5): error MSB8020: The build tools for Intel(R) oneAPI DPC++ Compiler (Platform Toolset = 'Intel(R) oneAPI DPC++ Compiler') cannot be found. To build using the Intel(R) oneAPI DPC++ Compiler build tools, please install Intel(R) oneAPI DPC++ Compiler build tools.  Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Retarget solution". [C:\Users\RaphaelSchiedung\source\hello_world\build\CMakeFiles\3.24.2\VCTargetsPath.vcxproj]

        0 Warning(s)
        1 Error(s)

    Time Elapsed 00:00:00.21


  Exit code: 1



-- Configuring incomplete, errors occurred!

The problem seems to be VCTargetsPath. Microsoft calls it a macro referencing %VSINSTALLDIR%MSBuild\Microsoft\VC<version>\ . At this point, google did not help much in answering my question on checking if VCTargetPah is set correctly. Where is it defined? Registry, System variable, or in some project files of VisualStudio? I did not quite understand this and I do not know much about windows programming.

Is it a bug? Is VCTagetsPath the problem at all? Can I do something about it? Any help on how to proceed would be appreciated.

hello_world.cpp:

#include<iostream>
int main(){std::cout << "Hello World\n"; return 0;}

CMakeLists.txt:

project(hello_world)
add_executable(hello_world hello_world.cpp)

window 11

Visual Studio 16 2019

CMake version 3.24.2

Intel(R) oneAPI DPC++/C++ Compiler 2022.1.0 (2022.1.0.20220316)

user2509663
  • 179
  • 2
  • 2
  • 10
  • 1
    This looks completely backwards. You invoke cmake to create the build directory and generate your solution for you, not the other way around. – sweenish Sep 21 '22 at 15:58
  • Well, this ist what I understood is purpose CMake. It generates Makefiles or solutions depending on the OS. If I would want to create Makefiles or solutions myself, as I do currently, for what purpose should I use CMake? – user2509663 Sep 21 '22 at 17:24

1 Answers1

2

Can you try this:

cmake -DCMAKE_CXX_COMPILER=icx ..

instead of this:

cmake -T "Intel(R) oneAPI DPC++ Compiler" -DCMAKE_CXX_COMPILER="dpcpp" ..

FYI I think you were looking at old documentation, this was the latest for 2022.1 I think.

https://www.intel.com/content/www/us/en/develop/documentation/oneapi-dpcpp-cpp-compiler-dev-guide-and-reference/top/compiler-setup/use-the-command-line/use-cmake-with-the-intel-oneapi-dpc-c-compiler.html

TonyM
  • 366
  • 1
  • 4
  • 1
    Thank you for your answer. The newer documentation was really helpful. Anyway, if I use cmake -DCMAKE_CXX_COMPILER=icx .. the icx compiler is not used by CMake. I don't understand why. Further, if I add find_package(IntelDPCPP REQUIRED) to the CMake file, I receive an error that the MSVC compiler family is not supported. Interestingly, if I use ninja cmake -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icx -GNinja the correct compiler is used by CMake. Using ninja is not the solution to the original problem but it may be an alternative. – user2509663 Sep 26 '22 at 13:59