[cmake-developers] [CMake 0013749]: Cannot target Windows 8 RT from CMake without workarounds.

Mantis Bug Tracker mantis at public.kitware.com
Tue Nov 27 18:49:09 EST 2012


The following issue has been SUBMITTED. 
====================================================================== 
http://public.kitware.com/Bug/view.php?id=13749 
====================================================================== 
Reported By:                jujjyl
Assigned To:                
====================================================================== 
Project:                    CMake
Issue ID:                   13749
Category:                   CMake
Reproducibility:            always
Severity:                   block
Priority:                   normal
Status:                     new
====================================================================== 
Date Submitted:             2012-11-27 18:49 EST
Last Modified:              2012-11-27 18:49 EST
====================================================================== 
Summary:                    Cannot target Windows 8 RT from CMake without
workarounds.
Description: 
I tried to make CMake generate .vcxproj files that would build into Windows 8 RT
application bundles. Not ARM, just on standard Win 8 RT, e.g. for Win 8 Store. 

I use the -G "Visual Studio 11" generator. 

The only support I found for this is to do

set_target_properties(project_name PROPERTIES VS_WINRT_EXTENSIONS TRUE)
add_definitions(-ZW)

(this was from
http://stackoverflow.com/questions/13228829/is-it-possible-to-create-winrt-project-with-cmake
, I do not need the xaml files, so only steps 1 & 2 applied for me)

These step were not enough. This is what I found missing:

1. The .vcxproj should have an element
"<AppContainerApplication>true</AppContainerApplication>" for the VC project
that is to be deployed into an Win8 RT app. This is missing in the generated
.vcxproj.

As a workaround, I use a sed script to add that line in an extra batch script
that is run after cmake finished. The line reads:

sed -r -i "s#</ProjectName>#</ProjectName>
<AppContainerApplication>true</AppContainerApplication>#g"
ProjectFileGeneratedByCMake.vcxproj

2. When targeting Win8 RT, it is required that the project contains an app
manifest ('Package.appxmanifest'), and a required set of logo images 'Logo.png',
'SmallLogo.png', 'SplashScreen.png' and 'StoreLogo.png'. Also (not 100% sure if
is required for development) there is a signing key file. 

I added these files manually to my source code folder. They need to be added
into the VC project, so that VC bundles the image files to the build, and knows
which manifest file to read. I tried to do this with the same way I add .cpp and
.h files:

file(GLOB sourceFiles *.cpp)
set(sourceFiles ${sourceFiles} ${Win8RTBuildRoot}/Assets/SmallLogo.png)
set(sourceFiles ${sourceFiles} ${Win8RTBuildRoot}/Assets/StoreLogo.png)
set(sourceFiles ${sourceFiles} ${Win8RTBuildRoot}/Assets/SplashScreen.png)
set(sourceFiles ${sourceFiles} ${Win8RTBuildRoot}/Assets/Logo.png)
set(sourceFiles ${sourceFiles}
${Win8RTBuildRoot}/gfxapi_application_TemporaryKey.pfx)
set(sourceFiles ${sourceFiles} ${Win8RTBuildRoot}/Package.appxmanifest)
add_executable(projectName WIN32 ${sourceFiles})

This works in the sense that the files appear in the project. But they are
defined wrong in .vcxproj, and VC gets confused and will say the files are
missing even though they are there. The .vcxproj file will read

<None Include="Assets\SmallLogo.png" />
<None Include="Assets\StoreLogo.png" />
<None Include="Assets\SplashScreen.png" />
<None Include="Assets\Logo.png" />
<None Include="application_TemporaryKey.pfx" />
<None Include="Package.appxmanifest" />

If the files are added manually, they will instead read

<Image Include="Assets\SmallLogo.png" />
<Image Include="Assets\StoreLogo.png" />
<Image Include="Assets\SplashScreen.png" />
<Image Include="Assets\Logo.png" />
<None Include="application_TemporaryKey.pfx" />
<AppxManifest Include="Package.appxmanifest" />

As a workaround, I added two sed scripts that replace 'None' with 'Image' for
.png files and with 'AppxManifest' for .appxmanifest files. Perhaps I did not
know of the proper way to add these to VC project, or the support is missing?
Perhaps CMake should always add image files as Image and .appxmanifest files as
AppxManifest, as there is probably no reason to have None for these. (what other
types might there be for which VC adds some other element than None, but cmake
does not?)

These workaround sed scripts read:

sed -r -i "s/None Include=\"(.*)\.png\"/Image Include=\"\1\.png\"/g"
ProjectFileGeneratedByCMake.vcxproj
sed -r -i "s/None Include=\"(.*)\.appxmanifest\"/AppxManifest
Include=\"\1\.appxmanifest\"/g" ProjectFileGeneratedByCMake.vcxproj

With these three sed workarounds, the solution and project files can now be
'Deploy'ed as Win8 RT apps and run in Metro UI.


Additional Information: 
Suggestions:

1. Add a new magic string WIN8RT to be recognized by add_executable, like

add_executable(projectName WIN8RT ${sourceFiles})

This would be used instead of the magic string 'WIN32' to signal that the
executable is to be a Win8 RT app.

When WIN8RT is specified, either
 a) omitting a .appxmanifest file from ${sourceFiles} is cmake generation error,
or
 b) if custom .appxmanifest is omitted, a default one is automatically generated
and used.

This is because when building as a win8 app, the build will fail if there is no
manifest. Also, the build will fail if the required logo images are not present,
so their addition should somehow be enforced as well.

2. Don't add image and appxmanifest items with the XML element <None> to the
vcxproj, but add them with <Image> and <AppxManifest>. 


If I did not find something and there is already an abstraction/mechanism to
these issues, please let me know!
====================================================================== 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2012-11-27 18:49 jujjyl         New Issue                                    
======================================================================




More information about the cmake-developers mailing list