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

Pascal Bach pascal.bach at siemens.com
Fri Sep 12 08:47:06 EDT 2014


- 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 |   40 ++++++++++++++++++++++++++++
 Source/cmGlobalVisualStudio10Generator.h   |    7 +++++
 Source/cmVisualStudio10TargetGenerator.cxx |   20 ++++++++++++--
 3 files changed, 65 insertions(+), 2 deletions(-)

diff --git a/Source/cmGlobalVisualStudio10Generator.cxx b/Source/cmGlobalVisualStudio10Generator.cxx
index e2d4645..e87a69f 100644
--- a/Source/cmGlobalVisualStudio10Generator.cxx
+++ b/Source/cmGlobalVisualStudio10Generator.cxx
@@ -179,6 +179,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 +209,38 @@ bool cmGlobalVisualStudio10Generator::InitializeWindowsStore(cmMakefile* mf)
 }
 
 //----------------------------------------------------------------------------
+bool cmGlobalVisualStudio10Generator::InitializeWindowsCE(cmMakefile* mf)
+  {
+  // 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());
+    }
+
+    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