Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for precompiled header #73

Closed
GoogleCodeExporter opened this issue Mar 15, 2015 · 16 comments
Closed

Support for precompiled header #73

GoogleCodeExporter opened this issue Mar 15, 2015 · 16 comments

Comments

@GoogleCodeExporter
Copy link

GCC has in nature the capability to create precompiled header to speed up the 
compilation process. It would be very useful to have it in vs-android.

Functionality:
The user should have an option in the project preferences to enter path to 
header file the precompiled header should be created from. If set, all sources 
will automatically include (through -include switch) this header file, which 
causes GCC to automatically use precompiled header.

There is few things that must be taken into account:
- precompiled header must be compiled first, before all sources
- each target platform must create different precompiled header
- extend dependencies between files in that, all sources which use precompiled 
header, should depends on this header file

Otherwise, excellent project, keep up the good work :-)

Original issue reported on code.google.com by milos0...@gmail.com on 15 Mar 2012 at 5:47

@GoogleCodeExporter
Copy link
Author

I think we really need the precompile header features ~~ Thanks for the author 
good job !!!! I wish to use this feature by vs-android ! thanks !

Original comment by easygame...@126.com on 17 Mar 2012 at 3:32

@GoogleCodeExporter
Copy link
Author

Original comment by gavin.dj.pugh on 20 Mar 2012 at 8:33

  • Changed state: Accepted

@GoogleCodeExporter
Copy link
Author

Original comment by gavin.dj.pugh on 26 Mar 2012 at 7:29

  • Added labels: Type-Enhancement
  • Removed labels: Type-Defect

@GoogleCodeExporter
Copy link
Author

Here's my hacky way to get Precompiled Headers to work:

http://qscribble.blogspot.ca/2012/05/precompiled-headers-in-vs-android.html

Original comment by qwertie...@gmail.com on 17 May 2012 at 11:14

@GoogleCodeExporter
Copy link
Author

Really I will try to use the method from qwertie ~~~

Original comment by easygame...@126.com on 22 May 2012 at 5:10

@GoogleCodeExporter
Copy link
Author

I really expect for this pre-compile features, right now I just use RudeBuilder 
to speed up the compile speed, But it's not stable :(

Original comment by easygame...@126.com on 7 Dec 2012 at 3:57

@GoogleCodeExporter
Copy link
Author

Still waiting .... really except for it .... want Priority -> high :P 
Thanks

Original comment by easygame...@126.com on 17 Jul 2013 at 7:42

@GoogleCodeExporter
Copy link
Author

I am surprised that it is still not there. The workaround for this does not 
work, in the way that the pre comp file is never created. 

Original comment by krishna....@gmail.com on 4 Sep 2013 at 1:47

@GoogleCodeExporter
Copy link
Author

Richard Forster has been kind enough to work on PCH recently.

I didn't have time to integrate it into v0.96, but I'll leave it here in case 
anyone is interested before a next version is published.

His comments:

<pre>
 Basically, there's 2 parts: 

1) Add a new file type to android_gcc_compile.xml - CompileAsCppHeader (and one 
for C PCHs). This is used as a flag to mark up .h files that should be used as 
PCHs. 
2) Update Microsoft.Cpp.Android.targets to redirect the output and have a 
separate GCCCompile stage for for files tagged as CompileAsCppHeader (I didn't 
do the C version yet). 

The only user side change is changing the file type of the PCH.
</pre>

Original comment by gavin.dj.pugh on 4 Jan 2014 at 8:49

Attachments:

@GoogleCodeExporter
Copy link
Author

Someone correct me if I am wrong. Precompiled headers with g++ should be named 
<header file>.h.gch. For example, for a include file "all.h", the pre-compiled 
header would be named "all.h.gch" in the same folder as "all.h".

I propose the changes in attached files. Some changes are not related to this 
request (std=c++11 option and empty rtti as no-rtti for c files generates 
warnings)

Original comment by camil...@gmail.com on 4 Jan 2014 at 9:03

Attachments:

@GoogleCodeExporter
Copy link
Author

Thanks to Gavin for passing these changes on. I've done a followup post on my 
blog for more information 
http://dickyjim.wordpress.com/2014/01/07/adding-precompiled-headers-to-vs-androi
d/

GCC supports the storage of multiple PCH outputs in a directory with the 
expected output name so that GCC can select the first PCH output that matches 
the configuration of the .c/.cpp file being compiled. If you want to use PCHs 
across multiple configurations, it's really important to use the directory 
mechanism, rather than a single output. For more information, see the "If you 
need to precompile the same header file for different languages…" paragraph 
in the GCC documentation - 
http://gcc.gnu.org/onlinedocs/gcc/Precompiled-Headers.html

Original comment by richjfor...@gmail.com on 7 Jan 2014 at 1:38

@GoogleCodeExporter
Copy link
Author

So it's a little more complex to support PCHs with all project types so I made 
a followup post: 
http://dickyjim.wordpress.com/2014/01/15/adding-precompiled-headers-to-vs-androi
d-part-2/

I'm now using this wherever I can and seeing some great reductions in build 
times.

Original comment by richjfor...@gmail.com on 15 Jan 2014 at 1:40

@GoogleCodeExporter
Copy link
Author

I end up with a "working solution". I wrote in quotes because when it is going 
to work, I found in Google that there is a crash (that is happenning to me 
whenever I activate the precompiled header) because the precompiled header 
exceeds 250 MB in Windows...

But this is:

in Props\android_gcc_compile.xml file I added

<StringProperty Name="PrecompiledHeaderDirectory" DisplayName="Precompiled 
Header Directory"  Category="Advanced" Visible="true" Switch="I">
  </StringProperty>


To create a configurable property for the final location of precompiled header. 
It is automatically added to the include files by the "I" Switch.





The precompiled header directory and precompilation is done by following 
additional target previously added to the changed original target (to avoid 
recompilation of pre-compiled header or compilation stage) : (file 
Microsoft.Cpp.Android.targets)


    <Target Name="BeforeClCompile">

    </Target>



  <Target Name="PreClCompile"
          Condition="'@(ClCompile)' != ''"
          DependsOnTargets="SelectClCompile">

     <ItemGroup>
      <ClCompile>
        <CompileAs                    Condition="('%(ClCompile.CompileAs)' == 'Default' and '%(ClCompile.Extension)' == '.c')">CompileAsC</CompileAs>
        <CompileAs                    Condition="('%(ClCompile.CompileAs)' == 'Default' and '%(ClCompile.Extension)' == '.s')">CompileAsAsm</CompileAs>
        <CompileAs                    Condition="('%(ClCompile.CompileAs)' == 'Default' and '%(ClCompile.Extension)' == '.asm')">CompileAsAsm</CompileAs>
        <CompileAs                    Condition="('%(ClCompile.CompileAs)' == 'Default' and ('%(ClCompile.Extension)' != '.c' and '%(ClCompile.Extension)' != '.s' and '%(ClCompile.Extension)' != '.asm'))">CompileAsCpp</CompileAs>
        <MinimalRebuildFromTracking   Condition="'$(BuildType)' != 'Build' or '$(ForceRebuild)' == 'true'">false</MinimalRebuildFromTracking>
        <Architecture                 Condition="'$(AndroidArch)' == 'armv5te'">armv5te</Architecture>
        <Architecture                 Condition="'$(AndroidArch)' == 'armv7-a'">armv7-a</Architecture>

        <CppStandard                  Condition="(('(%(ClCompile.CompileAs)' == 'CompileAsC') or ('%(ClCompile.CompileAs)' == 'CompileAsCHeader') or ('%(ClCompile.CompileAs)' == 'Default' and '%(ClCompile.Extension)' == '.c'))">Default</CppStandard>
        <Permissive                   Condition="(('(%(ClCompile.CompileAs)' == 'CompileAsC') or ('%(ClCompile.CompileAs)' == 'CompileAsCHeader') or ('%(ClCompile.CompileAs)' == 'Default' and '%(ClCompile.Extension)' == '.c'))">Default</Permissive>
        <ConversionNull               Condition="(('(%(ClCompile.CompileAs)' == 'CompileAsC') or ('%(ClCompile.CompileAs)' == 'CompileAsCHeader') or ('%(ClCompile.CompileAs)' == 'Default' and '%(ClCompile.Extension)' == '.c'))">Default</ConversionNull>

        <ObjectFileName Condition="('%(ClCompile.CompileAs)' == 'CompileAsCppHeader')">%(ClCompile.PreCompiledHeaderDirectory)%(FileName)%(Extension).gch</ObjectFileName>
        <ObjectFileName Condition="('%(ClCompile.CompileAs)' == 'CompileAsCHeader')">%(ClCompile.PreCompiledHeaderDirectory)%(FileName)%(Extension).gch</ObjectFileName>
      </ClCompile>
    </ItemGroup>

    <MakeDir Directories="%(ClCompile.PreCompiledHeaderDirectory)" />

    <Copy Condition="(('%(ClCompile.CompileAs)' == 'CompileAsCppHeader') or ('%(ClCompile.CompileAs)' == 'CompileAsCHeader'))" SourceFiles="%(Identity)" DestinationFolder="%(ClCompile.PreCompiledHeaderDirectory)" />

    <!-- Enable MinimalRebuildFromTracking for VS2012. VS2010 didn't require this for some reason. -->
    <ItemGroup Condition="$(VisualStudioVersion) != '10.0'">
      <ClCompile>
        <MinimalRebuildFromTracking   Condition="'%(ClCompile.MinimalRebuildFromTracking)' == '' and '$(BuildType)' == 'Build' and '$(ForceRebuild)' != 'true'">true</MinimalRebuildFromTracking>
      </ClCompile>
    </ItemGroup>

    <!-- Disable thumb switch for x86 builds -->
    <ItemGroup Condition="'$(PlatformShortName)' != 'arm'">
      <ClCompile>
        <ThumbMode>ignore</ThumbMode>
      </ClCompile>
    </ItemGroup>

    <GCCCompile Condition="(('%(ClCompile.ExcludedFromBuild)'!='true') and (('%(ClCompile.CompileAs)' == 'CompileAsCppHeader') or ('%(ClCompile.CompileAs)' == 'CompileAsCHeader')))"
        BuildingInIDE                      ="$(BuildingInsideVisualStudio)"
        Sources                            ="@(ClCompile)"

        TrackerLogDirectory                ="%(ClCompile.TrackerLogDirectory)"

        TLogReadFiles                      ="@(CLTLogReadFiles)"
        TLogWriteFiles                     ="@(CLTLogWriteFiles)"
        ToolExe                            ="$(CLToolExe)"
        ToolPath                           ="$(CLToolPath)"
        TrackFileAccess                    ="$(TrackFileAccess)"
        MinimalRebuildFromTracking         ="%(ClCompile.MinimalRebuildFromTracking)"

        AcceptableNonZeroExitCodes         ="%(ClCompile.AcceptableNonZeroExitCodes)"

        EchoCommandLines                   ="%(ClCompile.EchoCommandLines)"
        GCCToolPath                        ="$(GccCompiler)"
        PropertyXmlFile                    ="$(VCTargetsPath)\Platforms\Android\Props\android_gcc_compile.xml"
    >
    </GCCCompile>

  </Target>



  <!-- *******************************************************************************************
        CLCompile
       ******************************************************************************************* -->

  <Target Name="ClCompile"
          Condition="'@(ClCompile)' != ''"
          DependsOnTargets="SelectClCompile;PreClCompile">

    <ItemGroup>
      <ClCompile>
        <CompileAs                    Condition="('%(ClCompile.CompileAs)' == 'Default' and '%(ClCompile.Extension)' == '.c')">CompileAsC</CompileAs>
        <CompileAs                    Condition="('%(ClCompile.CompileAs)' == 'Default' and '%(ClCompile.Extension)' == '.s')">CompileAsAsm</CompileAs>
        <CompileAs                    Condition="('%(ClCompile.CompileAs)' == 'Default' and '%(ClCompile.Extension)' == '.asm')">CompileAsAsm</CompileAs>
        <CompileAs                    Condition="('%(ClCompile.CompileAs)' == 'Default' and ('%(ClCompile.Extension)' != '.c' and '%(ClCompile.Extension)' != '.s' and '%(ClCompile.Extension)' != '.asm'))">CompileAsCpp</CompileAs>
        <MinimalRebuildFromTracking   Condition="'$(BuildType)' != 'Build' or '$(ForceRebuild)' == 'true'">false</MinimalRebuildFromTracking>
        <Architecture                 Condition="'$(AndroidArch)' == 'armv5te'">armv5te</Architecture>
        <Architecture                 Condition="'$(AndroidArch)' == 'armv7-a'">armv7-a</Architecture>

        <CppStandard                  Condition="(('(%(ClCompile.CompileAs)' == 'CompileAsC') or ('%(ClCompile.CompileAs)' == 'CompileAsCHeader') or ('%(ClCompile.CompileAs)' == 'Default' and '%(ClCompile.Extension)' == '.c'))">Default</CppStandard>
        <Permissive                   Condition="(('(%(ClCompile.CompileAs)' == 'CompileAsC') or ('%(ClCompile.CompileAs)' == 'CompileAsCHeader') or ('%(ClCompile.CompileAs)' == 'Default' and '%(ClCompile.Extension)' == '.c'))">Default</Permissive>
        <ConversionNull               Condition="(('(%(ClCompile.CompileAs)' == 'CompileAsC') or ('%(ClCompile.CompileAs)' == 'CompileAsCHeader') or ('%(ClCompile.CompileAs)' == 'Default' and '%(ClCompile.Extension)' == '.c'))">Default</ConversionNull>

        <ObjectFileName Condition="('%(ClCompile.CompileAs)' == 'CompileAsCppHeader')">%(ClCompile.PreClCompiledHeaderDirectory)%(FileName)%(Extension).gch</ObjectFileName>
        <ObjectFileName Condition="('%(ClCompile.CompileAs)' == 'CompileAsCHeader')">%(ClCompile.PrecompiledHeaderDirectory)%(FileName)%(Extension).gch</ObjectFileName>
      </ClCompile>
    </ItemGroup>



    <!-- Enable MinimalRebuildFromTracking for VS2012. VS2010 didn't require this for some reason. -->
    <ItemGroup Condition="$(VisualStudioVersion) != '10.0'">
      <ClCompile>
        <MinimalRebuildFromTracking   Condition="'%(ClCompile.MinimalRebuildFromTracking)' == '' and '$(BuildType)' == 'Build' and '$(ForceRebuild)' != 'true'">true</MinimalRebuildFromTracking>
      </ClCompile>
    </ItemGroup>

    <!-- Disable thumb switch for x86 builds -->
    <ItemGroup Condition="'$(PlatformShortName)' != 'arm'">
      <ClCompile>
        <ThumbMode>ignore</ThumbMode>
      </ClCompile>
    </ItemGroup>

    <GCCCompile Condition="(('%(ClCompile.ExcludedFromBuild)'!='true') and !(('%(ClCompile.CompileAs)' == 'CompileAsCppHeader') or ('%(ClCompile.CompileAs)' == 'CompileAsCHeader')))"
        BuildingInIDE                      ="$(BuildingInsideVisualStudio)"
        Sources                            ="@(ClCompile)"

        TrackerLogDirectory                ="%(ClCompile.TrackerLogDirectory)"

        TLogReadFiles                      ="@(CLTLogReadFiles)"
        TLogWriteFiles                     ="@(CLTLogWriteFiles)"
        ToolExe                            ="$(CLToolExe)"
        ToolPath                           ="$(CLToolPath)"
        TrackFileAccess                    ="$(TrackFileAccess)"
        MinimalRebuildFromTracking         ="%(ClCompile.MinimalRebuildFromTracking)"

        AcceptableNonZeroExitCodes         ="%(ClCompile.AcceptableNonZeroExitCodes)"

        EchoCommandLines                   ="%(ClCompile.EchoCommandLines)"
        GCCToolPath                        ="$(GccCompiler)"
        PropertyXmlFile                    ="$(VCTargetsPath)\Platforms\Android\Props\android_gcc_compile.xml"
    >
    </GCCCompile>

  </Target>




************** default value for Precompiled Header configuration  in file 
(vs-android.ToolDefaults.props) :
.
.
.

      <PrecompiledHeaderDirectory     Condition="'%(ClCompile.PrecompiledHeaderDirectory)' == ''">$(IntDir)gch/</PrecompiledHeaderDirectory>

    </ClCompile>


If IntDir is configured per Configuration, the GCH will be automatically 
included in the correct IntDir/gch/

It is possible to have more than one gch.

Original comment by camil...@gmail.com on 15 Jan 2014 at 6:20

@GoogleCodeExporter
Copy link
Author

Note for the previous post! I did not commented the Copy of the Header files 
together the GCH in the PreClCompile Target. This is needed because another 
hack is needed and would be good to do by design if multi targeting is 
desirable without entire recompilation. The "all.h" headers that turn into 
"all.h.gch" paired and copied together with the original "all.h" headers, 
should be placed in a *NOT* originally reachable directory by "Additional 
Include Directories in GCC", besides Win32 and x64 targets for Windows should 
be changed to add to "Additional Include Directories in VC" (now from VC++ and 
not GCC) with the new previously "unreachble" folder created to hold the 
"all.h" precompiling headers for GCC layout. A simple "framework/" folder 
created to hold the precompiling headers would do the work. And only adding 
this "framework" word to Additional Include Directories to VC targets as it is 
added automatically to GCC from the copied place where resides the PCH. This is 
was the only way that I found to work (crash in my case, because of the size of 
gch, and unfortunatenetaly I still cannot use the feature by now, very sluggish 
compilation...)

Original comment by camil...@gmail.com on 15 Jan 2014 at 6:34

@GoogleCodeExporter
Copy link
Author

Original comment by gavin.dj.pugh on 25 Feb 2014 at 6:31

  • Changed state: Started

@GoogleCodeExporter
Copy link
Author

Added proper support with the new v0.961 I've uploaded.

Original comment by gavin.dj.pugh on 25 Feb 2014 at 7:35

  • Changed state: Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant