CMake can't get the value of VCTargetsPath when generating for UWP - c++

I'm trying to use CMake to build a Universal Windows App, but I get the following build error (latest Visual Studio 2019 and Windows 10 SDK are installed):
› cmake -B. -H<my source dir> -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.
CMake Error at CMakeLists.txt:3 (project):
Failed to run MSBuild command:
C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/MSBuild.exe
to get the value of VCTargetsPath:
Microsoft (R) Build Engine version 16.5.1+4616136f8 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 5/16/2020 9:52:00 PM.
Project "C:\test\CMakeFiles\3.17.2\VCTargetsPath.vcxproj" on node 1 (default targets).
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(777,5): error : The OutputPath property is not set for project 'VCTargetsPath.vcxproj'. Please check to make sure that you have specified a valid combination of Configuration and Platform for this project. Configuration='Debug' Platform='x64'. You may be seeing this message because you are trying to build a project without a solution file, and have specified a non-default Configuration or Platform that doesn't exist for this project. [C:\test\CMakeFiles\3.17.2\VCTargetsPath.vcxproj]
Done Building Project "C:\test\CMakeFiles\3.17.2\VCTargetsPath.vcxproj" (default targets) -- FAILED.
Build FAILED.
"C:\test\CMakeFiles\3.17.2\VCTargetsPath.vcxproj" (default target) (1) ->
(_CheckForInvalidConfigurationAndPlatform target) ->
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(777,5): error : The OutputPath property is not set for project 'VCTargetsPath.vcxproj'. Please check to make sure that you have specified a valid combination of Configuration and Platform for this project. Configuration='Debug' Platform='x64'. You may be seeing this message because you are trying to build a project without a solution file, and have specified a non-default Configuration or Platform that doesn't exist for this project. [C:\test\CMakeFiles\3.17.2\VCTargetsPath.vcxproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.07
Exit code: 1
-- Configuring incomplete, errors occurred!
What does that mean? I've also tried to specify the exact Windows SDK version for CMAKE_SYSTEM_VERSION, but no luck.

I solved the problem. I did many things, therefore I cannot tell which one exactly solved the problem. But try the following.
From VisualStudio Installer app, click Modify and install C++ Universal Windows Platform support for v142 build tools (ARM64) individual component.

Related

Configuring CMake and Microsoft Visual Studio 2019 for Use with Intel Compilers

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)
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

Cannot build console application with Microsoft Visual Studio 2019

I just installed the community version of VS 2019. I selected to build a console application that it created for me ("hello world" program). The file created is called ConsoleApplication1.cpp. I went to the build menu, selected build, and get the following error:
1>------ Build started: Project: ConsoleApplication1, Configuration: Debug Win32 ------
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppBuild.targets(441,5): warning MSB8003: The WindowsSDKDir property is not defined. Some build tools may not be found.
1>ConsoleApplication1.cpp
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\yvals.h(12,10): fatal error C1083: Cannot open include file: 'crtdbg.h': No such file or directory
1>Done building project "ConsoleApplication1.vcxproj" -- FAILED.
I tried to follow directions listed elsewhere on stackexchange. When I select "Project -> Properties" the Windows SDK field is blank. A value I typed in from the other StackExchange message creates an error that that version of the SDK cannot be found. So I deleted the version of the SDK and made it blank again. I also tried using "10.0" Here is where I received the advice:
Visual Studio 2017 errors on standard headers
Perhaps I did not install all the needed components. I recently checked off: "Windows Universal CRT SDK" (as per the instructions), but the build still fails. The warning is interesting. I looked that up also but have not found a solution that works. My "Platform Toolset" is Visual Studio 2019 (v142).
What might still be missing to build a console application? Thank you. I am working on Windows 7.

VS2017 + ICC 19.0: Failed to run MSBuild command

I am trying to build a C++ project using Visual Studio 2017 on top of the ICC 19.0 compiler.
This is the command I try to execute:
cmake -G "Visual Studio 15 2017 Win64" -T "Intel C++ Compiler 19.0" ..
This is the error I always get:
CMake Error at CMakeLists.txt:17 (project):
Failed to run MSBuild command:
C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/MSBuild/15.0/Bin/MSBuild.exe
to get the value of VCTargetsPath:
Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 2019-12-24 15:19:24.
Project "C:\Users\user001\Desktop\myproject\build\CMakeFiles\3.16.2\VCTargetsPath.vcxproj" on node 1 (default targets).
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\VCTargets\Microsoft.Cpp.Redirect.14.props(47,3): error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.cpp.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk. [C:\Users\user001\Desktop\myproject\build\CMakeFiles\3.16.2\VCTargetsPath.vcxproj]
Done Building Project "C:\Users\user001\Desktop\myproject\build\CMakeFiles\3.16.2\VCTargetsPath.vcxproj" (default targets) -- FAILED.
Build FAILED.
"C:\Users\user001\Desktop\myproject\build\CMakeFiles\3.16.2\VCTargetsPath.vcxproj" (default target) (1) ->
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\VCTargets\Microsoft.Cpp.Redirect.14.props(47,3): error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.cpp.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk. [C:\Users\user001\Desktop\myproject\build\CMakeFiles\3.16.2\VCTargetsPath.vcxproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.08
Exit code: 1
-- Configuring incomplete, errors occurred!
I do have VS2017 build tools installed — and reinstalled several times, for that matter.
What am I doing wrong?
Why is it trying to use VS2015 build tools that I don`t even have?
[UPD:] The result is the same even when I execute this command from x64 Native Tools Command Prompt for VS2017.
Please check whether file "C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.cpp.props" is exist.
If the project is ported from VS2015, Please check VisualStudioVersion parameter in your project file (.csproj/.vbproj), such as "C:\Users\user001\Desktop\myproject\build\CMakeFiles\3.16.2\VCTargetsPath.vcxproj".
Visual Studio project compatibility and VisualStudioVersion
Okay, after much chagrin I found out what was happening.
The ICC 19.0 installer misrecognized the version of Visual Studio and installed MSVS 2015 extensions instead of 2017, which led CMake to believe it should use MSVS 2015 build tools which were simply not there.
Problem solved.
All it took to solve this was to choose «Modify» from the ICC installer menu and switch to the right extension set.

Cant compile for x64 even after installing Visual C++ 2008 Express and Windows SDK

I have Visual C++ 2008 Express Edition installed. From here I have installed the MICROSOFT WINDOWS SOFTWARE DEVELOPMENT KIT FOR WINDOWS 7 and .NET FRAMEWORK 4 for x64 bit compile.
Now I can see the option of x64 through IDE in configuration menu. But whenever I try to build with this Debug|x64 selected, all I get is:
========== Build: 0 succeeded or up-to-date, 0 failed, 1 skipped ==========
It never gets build and always fails.
I also don’t have amd64\vcvarsamd64.bat folder inside C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin
Even when trying to build from cmd through msbuild "[PROJECT_PATH].sln" /t:Clean,Build /p:Configuration=Debug;Platform=x64 I get this:
Microsoft (R) Build Engine Version 3.5.30729.5420
[Microsoft .NET Framework, Version 2.0.50727.5420]
Copyright (C) Microsoft Corporation 2007. All rights reserved.
Build started 11/4/2016 11:55:00 AM.
Project "[PROJECT_PATH].sln" on node 0 (Clean;Build target(s)).
Building solution configuration "Debug|x64".
vcbuild.exe : error VCBLD0004: Project '[PROJECT_PATH].vcproj' does not contain a configuration called 'Debug|x64'.
vcbuild.exe : error VCBLD0004: Project '[PROJECT_PATH].vcproj' does not contain a configuration called 'Debug|x64'.
vcbuild.exe : error VCBLD0004: Project '[PROJECT_PATH].vcproj' does not contain a configuration called 'Debug|x64'.
Done Building Project "[PROJECT_PATH].sln" (Clean;Build target(s)) -- FAILED.
Build FAILED.
Seems like tools aren’t installed but I have installed Windows SDK after selecting the compile tools, then why it isn’t?
Any idea what went wrong?
The Windows SDK does not include any C++ compiler, and VC++ 2008 Express edition is 32 bit only. You need to install a 64 bit compiler (more recent versions of VC++ Express are available in 64 bit flavor).

Building Visual Studio 2015 C++ project (v140) by MSBuild Failed - v140 cannot be found

I have Visual Studio 2013 and 2015 installed side by side. I have just upgraded the combined solution (C#, C++, C++/CLI) to 2015 and set Platform Toolset to v140.
The build from Visual Studio works fine, but it cannot be compiled from MSBuild. I use MSBuild 14 and MSBuild complains that is unable to find v140, but it is nonsense, because v140 is installed on the computer in "c:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140".
The advice about upgrading the solution cannot be done, because the solution is already upgraded and there is no such item in solution context menu.
If I switch Platform tools of the project to v120, it works.
Details:
c:\git\hewerMaster>"c:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" c:\git
\hewerMaster\Hewer.sln /property:Configuration=Debug /property:Platform=x86
Microsoft (R) Build Engine version 14.0.23107.0
Copyright (C) Microsoft Corporation. All rights reserved.
Building the projects in this solution one at a time. To enable parallel build,
please add the "/m" switch.
Build started 9/12/2015 4:00:25 PM.
Project "c:\git\hewerMaster\Hewer.sln" on node 1 (default targets).
ValidateSolutionConfiguration:
Building solution configuration "Debug|x86".
ValidateProjects:
The project "HewerDotNetWrapper" is not selected for building in solution con
figuration "Debug|x86".
The project "VisualHewer" is not selected for building in solution configurat
ion "Debug|x86".
The project "UnitTestWrapper" is not selected for building in solution config
uration "Debug|x86".
The project "ParamsFormatConverter" is not selected for building in solution
configuration "Debug|x86".
The project "UnitTestGenerator" is not selected for building in solution conf
iguration "Debug|x86".
The project "HewerUnitTestDotNet" is not selected for building in solution co
nfiguration "Debug|x86".
Project "c:\git\hewerMaster\Hewer.sln" (1) is building "c:\git\hewerMaster\Hewe
rRedirect\HewerRedirect.csproj" (2) on node 1 (default targets).
CoreCompile:
Skipping target "CoreCompile" because all output files are up-to-date with resp
ect to the input files.
_CopyAppConfigFile:
Skipping target "_CopyAppConfigFile" because all output files are up-to-date wi
th respect to the input files.
CopyFilesToOutputDirectory:
HewerRedirect -> c:\git\hewerMaster\anyCPU\Debug\pbrain-hewer.exe
Done Building Project "c:\git\hewerMaster\HewerRedirect\HewerRedirect.csproj" (
default targets).
Project "c:\git\hewerMaster\Hewer.sln" (1) is building "c:\git\hewerMaster\Hewe
r\Hewer.vcxproj" (3) on node 1 (default targets).
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Platform.t
argets(64,5): error MSB8020: The build tools for v140 (Platform Toolset = 'v140
') cannot be found. To build using the v140 build tools, please install v140 bu
ild tools. Alternatively, you may upgrade to the current Visual Studio tools b
y selecting the Project menu or right-click the solution, and then selecting "U
pgrade Solution...". [c:\git\hewerMaster\Hewer\Hewer.vcxproj]
Done Building Project "c:\git\hewerMaster\Hewer\Hewer.vcxproj" (default targets
) -- FAILED.
Done Building Project "c:\git\hewerMaster\Hewer.sln" (default targets) -- FAILE
D.
Build FAILED.
UPDATE:
There are some project being skipped form Debug X86. This is intentional.
The project have been originally created in VS2008, then upgraded to VS2013, then upgraded to VS2015.
There are two Visual Studios installed on this computer (2013 Community and 2015 Community). 2013 was installed first, 2015 later.
The registry settings looks like:
UPDATE2:
Minimal, Complete, and Verifiable example
I have created empty C++ Console Application in Visual Studio 2015:
https://dl.dropboxusercontent.com/u/53387801/ConsoleApplication_v140.zip
#include "stdafx.h"
int main()
{
return 0;
}
I can build it in Visual Studio, but I face the same issue in MSBuild:
c:\>"c:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild" "C:\temp\vs2015_simplest\C
onsoleApplication1\consoleApplication1.sln"
Microsoft (R) Build Engine version 14.0.23107.0
Copyright (C) Microsoft Corporation. All rights reserved.
Building the projects in this solution one at a time. To enable parallel build,
please add the "/m" switch.
Build started 9/16/2015 10:16:20 AM.
Project "C:\temp\vs2015_simplest\ConsoleApplication1\consoleApplication1.sln" o
n node 1 (default targets).
ValidateSolutionConfiguration:
Building solution configuration "Debug|x64".
Project "C:\temp\vs2015_simplest\ConsoleApplication1\consoleApplication1.sln" (
1) is building "C:\temp\vs2015_simplest\ConsoleApplication1\ConsoleApplication1
\ConsoleApplication1.vcxproj" (2) on node 1 (default targets).
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Platform.t
argets(64,5): error MSB8020: The build tools for v140 (Platform Toolset = 'v140
') cannot be found. To build using the v140 build tools, please install v140 bu
ild tools. Alternatively, you may upgrade to the current Visual Studio tools b
y selecting the Project menu or right-click the solution, and then selecting "U
pgrade Solution...". [C:\temp\vs2015_simplest\ConsoleApplication1\ConsoleApplic
ation1\ConsoleApplication1.vcxproj]
Done Building Project "C:\temp\vs2015_simplest\ConsoleApplication1\ConsoleAppli
cation1\ConsoleApplication1.vcxproj" (default targets) -- FAILED.
Done Building Project "C:\temp\vs2015_simplest\ConsoleApplication1\consoleAppli
cation1.sln" (default targets) -- FAILED.
Build FAILED.
"C:\temp\vs2015_simplest\ConsoleApplication1\consoleApplication1.sln" (default
target) (1) ->
"C:\temp\vs2015_simplest\ConsoleApplication1\ConsoleApplication1\ConsoleApplica
tion1.vcxproj" (default target) (2) ->
(PlatformPrepareForBuild target) ->
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Platform
.targets(64,5): error MSB8020: The build tools for v140 (Platform Toolset = 'v1
40') cannot be found. To build using the v140 build tools, please install v140
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
"Upgrade Solution...". [C:\temp\vs2015_simplest\ConsoleApplication1\ConsoleAppl
ication1\ConsoleApplication1.vcxproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.14
c:\>
SOLVED:
Environment variable VisualStudioVersion was set to 12.0 instead of 14.0 Changing the value to 14.0 solved the issue.
The simple console application started to work immediately after the Environment variable VisualStudioVersion changed and after windows logout, login.
The original project still couldn't be build after changing environment variable VisualStudioVersion. A retarget solution context menu appeared in Visual Studio 2015. So I retarget the solution. After retargeting the solution still couldn't be compiled (v140 not found). Finally I changed the platform toolset from v140 (not installed) to Visual Studio 2015 (v140). Now the solution can be compiled from Visual Studio and MSBuild as well.
Your problem is that you set the environment variable VisualStudioVersion to 12.0. This tells MSBuild to use the Visual Studio 2013 (V120) tools, which don't support the Visual Studio 2015 (V140) build tools. If you unset this environment variable, or pass the /p:VisualStudioVersion=14.0 option to MSBuild your project, should build. (Or at least get past this error).
You can find more information about the VisualStudioVersion variable in a MSDN blog entry titled Visual Studio project compatibility and VisualStudioVersion.
One solution is that you can simply change the platform toolset that is available in your system. Then it build fine.