VS: Add VS_WINRT_COMPONENT property to enable CompileAsWinRT

Deprecate VS_WINRT_EXTENSIONS and document VS_WINRT_COMPONENT as for VS
generators only.  Also define _WINRT_DLL in SHARED libraries in order to
get a .lib produced.

Inspired-by: Paul Annetts <paul@lightunobscured.com>
This commit is contained in:
Gilles Khouzam 2014-08-11 14:21:16 -04:00 committed by Brad King
parent 401269e43b
commit cb1aceed8c
6 changed files with 50 additions and 4 deletions

View File

@ -235,6 +235,7 @@ Properties on Targets
/prop_tgt/VS_SCC_LOCALPATH
/prop_tgt/VS_SCC_PROJECTNAME
/prop_tgt/VS_SCC_PROVIDER
/prop_tgt/VS_WINRT_COMPONENT
/prop_tgt/VS_WINRT_EXTENSIONS
/prop_tgt/VS_WINRT_REFERENCES
/prop_tgt/WIN32_EXECUTABLE

View File

@ -0,0 +1,14 @@
VS_WINRT_COMPONENT
------------------
Mark a target as a Windows Runtime component for the Visual Studio generator.
Compile the target with ``C++/CX`` language extensions for Windows Runtime.
For ``SHARED`` and ``MODULE`` libraries, this also defines the
``_WINRT_DLL`` preprocessor macro.
.. note::
Behavior is not defined for targets with source files that compile as
any language other than ``CXX``.
Currently this is implemented only by Visual Studio generators.
Support may be added to other generators in the future.

View File

@ -1,6 +1,5 @@
VS_WINRT_EXTENSIONS
-------------------
Visual Studio project C++/CX language extensions for Windows Runtime
Can be set to enable C++/CX language extensions.
Deprecated. Use :prop_tgt:`VS_WINRT_COMPONENT` instead.
This property was an experimental partial implementation of that one.

View File

@ -591,6 +591,7 @@ void cmVisualStudio10TargetGenerator
if((this->Target->GetType() <= cmTarget::OBJECT_LIBRARY &&
this->ClOptions[config]->UsingUnicode()) ||
this->Target->GetPropertyAsBool("VS_WINRT_COMPONENT") ||
this->Target->GetPropertyAsBool("VS_WINRT_EXTENSIONS"))
{
this->WriteString("<CharacterSet>Unicode</CharacterSet>\n", 2);
@ -611,7 +612,8 @@ void cmVisualStudio10TargetGenerator
pts += "</PlatformToolset>\n";
this->WriteString(pts.c_str(), 2);
}
if(this->Target->GetPropertyAsBool("VS_WINRT_EXTENSIONS"))
if(this->Target->GetPropertyAsBool("VS_WINRT_COMPONENT") ||
this->Target->GetPropertyAsBool("VS_WINRT_EXTENSIONS"))
{
this->WriteString("<WindowsAppContainer>true"
"</WindowsAppContainer>\n", 2);
@ -1604,6 +1606,29 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions(
clOptions.AddDefine(exportMacro);
}
if (this->MSTools)
{
// If we have the VS_WINRT_COMPONENT set then force Compile as WinRT.
if (this->Target->GetPropertyAsBool("VS_WINRT_COMPONENT"))
{
clOptions.AddFlag("CompileAsWinRT", "true");
// For WinRT components, add the _WINRT_DLL define to produce a lib
if (this->Target->GetType() == cmTarget::SHARED_LIBRARY ||
this->Target->GetType() == cmTarget::MODULE_LIBRARY )
{
clOptions.AddDefine("_WINRT_DLL");
}
}
else if (this->GlobalGenerator->TargetsWindowsStore() ||
this->GlobalGenerator->TargetsWindowsPhone())
{
if (!clOptions.IsWinRt())
{
clOptions.AddFlag("CompileAsWinRT", "false");
}
}
}
this->ClOptions[configName] = pOptions.release();
return true;
}

View File

@ -106,6 +106,12 @@ bool cmVisualStudioGeneratorOptions::IsDebug() const
return this->FlagMap.find("DebugInformationFormat") != this->FlagMap.end();
}
//----------------------------------------------------------------------------
bool cmVisualStudioGeneratorOptions::IsWinRt() const
{
return this->FlagMap.find("CompileAsWinRT") != this->FlagMap.end();
}
//----------------------------------------------------------------------------
bool cmVisualStudioGeneratorOptions::UsingUnicode() const
{

View File

@ -52,6 +52,7 @@ public:
bool UsingSBCS() const;
bool IsDebug() const;
bool IsWinRt() const;
// Write options to output.
void OutputPreprocessorDefinitions(std::ostream& fout,
const char* prefix,