[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    [PATCH] Extra #include options in kconfig_compiler
From:       David Jarvie <lists () astrojar ! org ! uk>
Date:       2007-10-05 20:19:49
Message-ID: 200710052119.49594.lists () astrojar ! org ! uk
[Download RAW message or body]

Attached is a patch to allow the specification of #include's in the source 
file generated by kconfig_compiler (as opposed to #include's in the header 
file which are currently catered for), by the addition of a 
SourceIncludeFiles keyword in the .kcfgc file. It seems sensible not to force 
the inclusion of unneeded #include statements in the generated header if they 
are only needed in the source. This will enable me to easily fix a circular 
#include chain in code I'm writing, which would need much more work to solve 
by other means. (The problem isn't because of lack of include guards, but due 
to classes needing each other to be defined.)

The patch also allows the specification of #include "xxx.h" instead of 
#include <xxx.h> by enclosing the name of the header file in double quotes. 
For example, in the .kcfgc file:

IncludeFiles=kglobal.h,\"myfile.h\"
SourceIncludeFiles=\"project.h\",kurl.h

This would result in the following includes in the generated header file:

#include <kglobal.h>
#include "myfile.h"

and in the generated source file:

#include "project.h"
#include <kurl.h>


In the .kcfg file:

<include>kglobalsettings.h</include>
<include>"timeperiod.h"</include>

would generate in the header file:

#include <kglobalsettings.h>
#include "timeperiod.h"


There should be no impact on existing code. Comments?

-- 
David Jarvie.
KAlarm author and maintainer.
http://www.astrojar.org.uk/kalarm

["config.diff" (text/x-diff)]

Index: README.dox
===================================================================
--- README.dox	(revision 714246)
+++ README.dox	(working copy)
@@ -19,7 +19,9 @@
 file ("<appname>rc").
 
 The \<include\> tags are optional and may contain C++ header files that
-are needed to compile the code needed to compute default values.
+are needed to compile the code needed to compute default values. To generate
+a #include "..." statement instead of #include <...>, enclose the header
+file name in double quotes (e.g. \<include\>"header.h"\</include\>).
 
 The remaining entries in the XML file are grouped by the tag \<group\> 
 which describes the corresponding group in the configuration file.
@@ -56,8 +58,9 @@
 or if it needs to be obtained from a function call, the \<default\> tag
 should contain the code="true" attribute. The contents of the \<default\>
 tag is then considered to be a C++ expression. Note that in this case you
-might have to add an \<include\> tag as described above so that the code
-which computes the default value can be compiled.
+might have to add an \<include\> tag as described above, or a
+SourceIncludeFiles entry in the .kcfgc file as described below, so that the
+code which computes the default value can be compiled.
 
 Additional code for computing default values can be provided outside any
 entry definition via the \<code\> tag. The contents of the \<code\> tag is
@@ -134,9 +137,19 @@
   <td><b>IncludeFiles</b></td>
   <td>comma separated list of strings</td>
   <td>-</td>
-  <td>Names of files to be included in the header of the generated class</td>
+  <td>Names of files to be included in the header of the generated class. Enclose a
+  file name in (escaped) double quotes to generate #include "..." instead of
+  #include <...>.</td>
 </tr>
 <tr>
+  <td><b>SourceIncludeFiles</b></td>
+  <td>comma separated list of strings</td>
+  <td>-</td>
+  <td>Names of files to be included in the source file of the generated class. Enclose
+  a file name in (escaped) double quotes to generate #include "..." instead of
+  #include <...>.</td>
+</tr>
+<tr>
   <td><b>Mutators</b></td>
   <td>true, false or a comma separated list of options</td>
   <td>-</td>
Index: kconfig_compiler.cpp
===================================================================
--- kconfig_compiler.cpp	(revision 714246)
+++ kconfig_compiler.cpp	(working copy)
@@ -1173,6 +1173,7 @@
   bool customAddons = codegenConfig.value("CustomAdditions", false).toBool();
   QString memberVariables = codegenConfig.value("MemberVariables").toString();
   QStringList headerIncludes = codegenConfig.value("IncludeFiles", QStringList()).toStringList();
+  QStringList sourceIncludes = codegenConfig.value("SourceIncludeFiles", QStringList()).toStringList();
   QStringList mutators = codegenConfig.value("Mutators", QStringList()).toStringList();
   bool allMutators = false;
   if ((mutators.count() == 1) && (mutators.at(0).toLower() == "true"))
@@ -1333,7 +1334,10 @@
   // Includes
   QStringList::ConstIterator it;
   for( it = headerIncludes.begin(); it != headerIncludes.end(); ++it ) {
-    h << "#include <" << *it << ">" << endl;
+    if ( (*it).startsWith('"') )
+      h << "#include " << *it << endl;
+    else
+      h << "#include <" << *it << ">" << endl;
   }
 
   if ( headerIncludes.count() > 0 ) h << endl;
@@ -1346,7 +1350,10 @@
 
   // Includes
   for( it = includes.begin(); it != includes.end(); ++it ) {
-    h << "#include <" << *it << ">" << endl;
+    if ( (*it).startsWith('"') )
+      h << "#include " << *it << endl;
+    else
+      h << "#include <" << *it << ">" << endl;
   }
 
   if ( !nameSpace.isEmpty() )
@@ -1687,6 +1694,15 @@
 
   cpp << "#include \"" << headerFileName << "\"" << endl << endl;
 
+  for( it = sourceIncludes.begin(); it != sourceIncludes.end(); ++it ) {
+    if ( (*it).startsWith('"') )
+      cpp << "#include " << *it << endl;
+    else
+      cpp << "#include <" << *it << ">" << endl;
+  }
+
+  if ( sourceIncludes.count() > 0 ) cpp << endl;
+
   if ( setUserTexts ) cpp << "#include <klocale.h>" << endl << endl;
 
   // Header required by singleton implementation


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic