Reputation: 179
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)
Upvotes: 0
Views: 1679
Reputation: 376
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.
Upvotes: 2