Reputation: 31
I am currently trying to set up a Visual Studio 2017 UWP Project with CMake. So I did what the Internet tought me and set up a basic project like this:
cmake_minimum_required(VERSION 3.0)
project(windowsClient
VERSION 1.0.0
LANGUAGES CXX
)
add_executable(windowsClient
src/App.xaml.cpp
src/MainPage.xaml.cpp
src/App.xaml.h
src/MainPage.xaml.h
src/MainPage.xaml
src/App.xaml
src/Package.appxmanifest
src/pch.h
src/pch.cpp
)
# This is needed because otherwise the App.xaml would be detected as "Page" by CMake
set_source_files_properties(
src/App.xaml
PROPERTIES
VS_XAML_TYPE ApplicationDefinition
)
# Here I set the target System to WindowsStore, which *should* enable UWP-support
set_target_properties(windowsClient
PROPERTIES
CMAKE_SYSTEM_NAME WindowsStore
CMAKE_SYSTEM_VERSION 10.0
)
But when I generate a Visual Studio 2017 Project for this, a WPF-Project is generated. This results in the Problem that the XAML-Files can not be edited in the Visual Editor because the XML contains unkown tags. Also VS doesn't correctly show the connection to the related .xaml.cpp and .xaml.h files. Compilation fails, with two major errors:
Here I found the tip to set the property VS_WINRT_COMPONENT TRUE
on my CMake-target. This kindof improves the situation, as the .xaml.cpp and .xaml.h files are now correctly displayed as children of it's .xaml definition, and it's tags seem to be known. Also the required /ZW
compiler flag for support of Microsofts C++/CX language extension is added. But compilation shows, that I am still not on the right track:
I analysed the situation and found out, that the .vcxproject-File generated by CMake misses these important lines in the Globals-Section:
<AppContainerApplication>true</AppContainerApplication>
<ApplicationType>Windows Store</ApplicationType>
<WindowsTargetPlatformVersion Condition=" '$(WindowsTargetPlatformVersion)' == '' ">10.0.16299.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformMinVersion>10.0.10586.0</WindowsTargetPlatformMinVersion>
<ApplicationTypeRevision>10.0</ApplicationTypeRevision>
When I add them manually, the project is correctly detected as UWP-Project (indicated by the text (Universal Windows)
behind the build target in the Project-Explorer. Also the .xaml.cpp and .xaml.h files are now correctly displayed as children of it's .xaml definition. Compilation still throws some errors, but this is clearly the right way to go.
Can you give me a hint what I am missing? Why isn't the VS-Project generated correctly by cmake, although I set the System name to "Windows Store"? What exactly does the VS_WINRT_COMPONENT
property do? I don't have enough knowledge of the Windows ecosystem to fully understand CMakes documentation of it, but I got the feeling that I actually don't need it and that I am missing to set some other Property.
Upvotes: 3
Views: 1304
Reputation: 386
I was can get tag (Universal Windows) on target of solution in MS VS only after these keys with cmake:
cmake . -DCMAKE_SYSTEM_NAME:String=WindowsStore -DCMAKE_SYSTEM_VERSION:String="10.0"
use properties in CMakeLists.txt didn't help
Upvotes: 0