[cmake-developers] [PATCH] WINCE, VS: Make the Visual Studio 10+ generator Windows CE

Bach, Pascal pascal.bach at siemens.com
Mon Sep 15 09:51:50 EDT 2014


> Here please add this check:
> 
>   if(this->DefaultPlatformName != "Win32")
>     {
>     cmOStringStream e;
>     e << "CMAKE_SYSTEM_NAME is 'WindowsCE' but CMAKE_GENERATOR "
>       << "specifies a platform too: '" << this->GetName() << "'";
>     mf->IssueMessage(cmake::FATAL_ERROR, e.str());
>     return false;
>     }
> 
> This code should no longer be called multiple times so it is safe to
> check here now.

Done check is added.

> 
> > +  // To preserve the old behaviour just keep the DefaultPlatformToolset
> > +  // for unknown Windows CE versions, in the worst case the user has to
> set
> > +  // CMAKE_GENERATOR_TOOLSET manually. In that case warn the user.
> > +  std::string platformToolset = this->SelectWindowsCEToolset();
> > +  if (!platformToolset.empty())
> > +    {
> > +    this->DefaultPlatformToolset = platformToolset;
> > +    }
> > +  else
> > +    {
> > +    cmOStringStream e;
> > +    e << this->GetName() << " Windows CE version '" << this-
> >SystemVersion
> > +      << "' might require CMAKE_GENERATOR_TOOLSET to be set.";
> > +    mf->IssueMessage(cmake::WARNING, e.str());
> > +    }
> 
> I think this will always warn when CMAKE_SYSTEM_VERSION != 8.0
> even if the user has set a CMAKE_GENERATOR_TOOLSET.  Instead,
> cmGlobalVisualStudio10Generator::SetGeneratorToolset should
> implement the warning:

I'm not sure if it is always required for older versions. I just assume it is and print an error if not set.  
I think the user knows what toolset to use when compiling for WindowCE.

Here is the updated patch:

>From 1599834a97200511feede2c3a69b33bbf66560b6 Mon Sep 17 00:00:00 2001
From: Pascal Bach <pascal.bach at siemens.com>
Date: Mon, 15 Sep 2014 15:46:43 +0200
Subject: [PATCH] WINCE, VS: Make the Visual Studio 10+ generator Windows CE

- If Windows CE is targeted set the Subsystem and EntryPointSymbol accordingly
- For Windows CE 2013 (8.0) set the toolset to C800 by default
---
 Source/cmGlobalVisualStudio10Generator.cxx |   44 ++++++++++++++++++++++++++++
 Source/cmGlobalVisualStudio10Generator.h   |    7 +++++
 Source/cmVisualStudio10TargetGenerator.cxx |   20 +++++++++++--
 3 files changed, 69 insertions(+), 2 deletions(-)

diff --git a/Source/cmGlobalVisualStudio10Generator.cxx b/Source/cmGlobalVisualStudio10Generator.cxx
index e2d4645..5fef79c 100644
--- a/Source/cmGlobalVisualStudio10Generator.cxx
+++ b/Source/cmGlobalVisualStudio10Generator.cxx
@@ -152,6 +152,15 @@ bool
 cmGlobalVisualStudio10Generator::SetGeneratorToolset(std::string const& ts,
                                                      cmMakefile* mf)
 {
+if (this->SystemIsWindowsCE && ts.empty() && this->DefaultPlatformToolset.empty())
+  {
+  cmOStringStream e;
+  e << this->GetName() << " Windows CE version '" << this->SystemVersion 
+    << "' requires CMAKE_GENERATOR_TOOLSET to be set.";
+  mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+  return false;
+  }
+
   this->GeneratorToolset = ts;
   if(const char* toolset = this->GetPlatformToolset())
     {
@@ -179,6 +188,14 @@ bool cmGlobalVisualStudio10Generator::InitializeSystem(cmMakefile* mf)
       return false;
       }
     }
+  else if (this->SystemName == "WindowsCE")
+    {
+    this->SystemIsWindowsCE = true;
+    if (!this->InitializeWindowsCE(mf))
+      {
+      return false;
+      }
+    }
   return true;
 }
 
@@ -201,6 +218,33 @@ bool cmGlobalVisualStudio10Generator::InitializeWindowsStore(cmMakefile* mf)
 }
 
 //----------------------------------------------------------------------------
+bool cmGlobalVisualStudio10Generator::InitializeWindowsCE(cmMakefile* mf)
+{
+  if (this->DefaultPlatformName != "Win32")
+    {
+    cmOStringStream e;
+    e << "CMAKE_SYSTEM_NAME is 'WindowsCE' but CMAKE_GENERATOR "
+      << "specifies a platform too: '" << this->GetName() << "'";
+    mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+    return false;
+    }
+
+  this->DefaultPlatformToolset = this->SelectWindowsCEToolset();
+
+  return true;
+}
+
+//----------------------------------------------------------------------------
+std::string cmGlobalVisualStudio10Generator::SelectWindowsCEToolset() const
+{
+  if (this->SystemVersion == "8.0")
+    {
+    return "CE800";
+    }
+  return "";
+}
+
+//----------------------------------------------------------------------------
 void cmGlobalVisualStudio10Generator::WriteSLNHeader(std::ostream& fout)
 {
   fout << "Microsoft Visual Studio Solution File, Format Version 11.00\n";
diff --git a/Source/cmGlobalVisualStudio10Generator.h b/Source/cmGlobalVisualStudio10Generator.h
index f1ff9a4..a80222f 100644
--- a/Source/cmGlobalVisualStudio10Generator.h
+++ b/Source/cmGlobalVisualStudio10Generator.h
@@ -76,6 +76,10 @@ public:
   bool TargetsWindowsStore() const
     { return this->SystemIsWindowsStore; }
 
+  /** Return true if building for WindowsCE */
+  bool TargetsWindowsCE() const
+    { return this->SystemIsWindowsCE; }
+
   /**
    * Where does this version of Visual Studio look for macros for the
    * current user? Returns the empty string if this version of Visual
@@ -107,8 +111,10 @@ protected:
   virtual bool InitializeSystem(cmMakefile* mf);
   virtual bool InitializeWindowsPhone(cmMakefile* mf);
   virtual bool InitializeWindowsStore(cmMakefile* mf);
+  virtual bool InitializeWindowsCE(cmMakefile* mf);
   virtual std::string SelectWindowsPhoneToolset() const { return ""; }
   virtual std::string SelectWindowsStoreToolset() const { return ""; }
+  virtual std::string SelectWindowsCEToolset() const;
 
   virtual const char* GetIDEVersion() { return "10.0"; }
 
@@ -120,6 +126,7 @@ protected:
   std::string SystemVersion;
   bool SystemIsWindowsPhone;
   bool SystemIsWindowsStore;
+  bool SystemIsWindowsCE;
   bool ExpressEdition;
 
   bool UseFolderProperty();
diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx
index c525b7c..681b8c7 100644
--- a/Source/cmVisualStudio10TargetGenerator.cxx
+++ b/Source/cmVisualStudio10TargetGenerator.cxx
@@ -2115,11 +2115,27 @@ cmVisualStudio10TargetGenerator::ComputeLinkOptions(std::string const& config)
 
     if ( this->Target->GetPropertyAsBool("WIN32_EXECUTABLE") )
       {
-      linkOptions.AddFlag("SubSystem", "Windows");
+      if (this->GlobalGenerator->TargetsWindowsCE())
+        {
+        linkOptions.AddFlag("SubSystem", "WindowsCE");
+        linkOptions.AddFlag("EntryPointSymbol", "WinMainCRTStartup");
+        }
+      else
+        { 
+        linkOptions.AddFlag("SubSystem", "Windows");
+        }
       }
     else
       {
-      linkOptions.AddFlag("SubSystem", "Console");
+      if (this->GlobalGenerator->TargetsWindowsCE())
+        {
+        linkOptions.AddFlag("SubSystem", "WindowsCE");
+        linkOptions.AddFlag("EntryPointSymbol", "mainACRTStartup");
+        }
+      else
+        {
+        linkOptions.AddFlag("SubSystem", "Console");
+        };
       }
 
     if(const char* stackVal =
-- 
1.7.10.4



 



More information about the cmake-developers mailing list