Skip to content

Commit

Permalink
Add precompiled header to inherited C++ code
Browse files Browse the repository at this point in the history
Adds a "precompiled_header" property to UserClass, fills in the value
from Project properties, and then uses a"precompiled_header" template
to generate the precompiled header (if the user supplied one).
  • Loading branch information
Randalphwa committed Jan 12, 2020
1 parent 964f29c commit 29eabd4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
6 changes: 6 additions & 0 deletions output/xml/default.cppcode
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,12 @@
<template name="event_handler_comment">
// Handlers for $basename events.
</template>
<template name="precompiled_header">
#ifnotnull $precompiled_header
@{
$precompiled_header
@}
</template>
<template name="header_include">@#include &quot;$gen_file.h&quot;</template>
<template name="source_include">@#include &quot;$file.h&quot;</template>
<template name="class_decl">
Expand Down
1 change: 1 addition & 0 deletions output/xml/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@
<property name="file" type="text"/>
<property name="gen_file" type="text"/>
<property name="type" type="text"/>
<property name="precompiled_header" type="text"/>
</objectinfo>

<objectinfo class="AUI" type="interface">
Expand Down
7 changes: 7 additions & 0 deletions src/codegen/cppcg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,13 @@ void CppCodeGenerator::GenerateInheritedClass( PObjectBase userClasses, PObjectB
m_header->Indent();

// Start source file
code = GetCode(userClasses, wxT("precompiled_header"));
if (!code.empty())
{
m_source->WriteLn(code);
m_source->WriteLn(wxEmptyString);
}

code = GetCode( userClasses, wxT("source_include") );
m_source->WriteLn( code );
m_source->WriteLn( wxEmptyString );
Expand Down
10 changes: 9 additions & 1 deletion src/rad/appdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2367,6 +2367,7 @@ void ApplicationData::GenerateCode( bool panelOnly, bool noDelayed )
NotifyCodeGeneration( panelOnly, !noDelayed );
}

// Properties in ../output/xml/default.xml and code templates in ../output/xml/default.cppcode
void ApplicationData::GenerateInheritedClass( PObjectBase form, wxString className, wxString path, wxString file )
{
try
Expand All @@ -2391,8 +2392,9 @@ void ApplicationData::GenerateInheritedClass( PObjectBase form, wxString classNa
PProperty fileProp = obj->GetProperty( wxT( "file" ) );
PProperty genfileProp = obj->GetProperty( wxT( "gen_file" ) );
PProperty typeProp = obj->GetProperty( wxT( "type" ) );
PProperty typePCH = obj->GetProperty(wxT("precompiled_header"));

if ( !( baseNameProp && nameProp && fileProp && typeProp && genfileProp ) )
if (!(baseNameProp && nameProp && fileProp && typeProp && genfileProp && typePCH))
{
wxLogWarning( wxT("Missing Property") );
return;
Expand Down Expand Up @@ -2426,6 +2428,12 @@ void ApplicationData::GenerateInheritedClass( PObjectBase form, wxString classNa
genfileProp->SetValue( genFile.GetFullPath() );
typeProp->SetValue( form->GetClassName() );

PProperty pPCH = project->GetProperty(wxT("precompiled_header"));
if (pPCH)
{
typePCH->SetValue(pPCH->GetValue());
}

// Determine if Microsoft BOM should be used
bool useMicrosoftBOM = false;
PProperty pUseMicrosoftBOM = project->GetProperty( _("use_microsoft_bom") );
Expand Down

0 comments on commit 29eabd4

Please sign in to comment.