C++ #include with root relative path

C++ #include with root relative path

Postby hmb » Wed 6 Jan 2021 19:23

Hi,

I would like to know if there is an available option to generate cpp code where the path of the include preprocessor directive has no directory base.

Probably with an example I could clarify my question.

My project has the following structure:

Code: Select all
myproject/
  \__ inc/       (<== don't want to have this inc/ subdirectory on the path of each header file included)
 |    \__ ns/
 |        \__ A.h
 |        \__ B.h
  \__ src/
      \__ ns/
          \__ A.cpp
          \__ B.cpp

Where A and B are classes inside a ns namespace.


I want to have the following path in the include directive of the generated A.cpp file

A.cpp file
Code: Select all
...
#include "ns/A.h"
...



but I have

A.cpp file
Code: Select all
...
#include "inc/ns/A.h"
...

if a use the "with root relative path" option in the #include combobox option of the C++[1] tab of the Generation settings dialog

or

A.cpp file
Code: Select all
...
#include "../inc/ns/A.h"
...

if a use the "with relative path" option in the #include combobox option of the C++[1] tab of the Generation settings dialog.

Of course, the generation directories for the namespace for the headers/sources are inc/ns/ and src/ns/ respectively, in order to generate generate the code in the correct place.

Is it possible?

I know that if I generate both source and header files on the same directory I could have the desired effect, but I want to maintain separate directories for the header and source files.

Thanks in advance.

Regards,
--
Hernan
hmb
 
Posts: 2
Joined: Wed 6 Jan 2021 17:29

Re: C++ #include with root relative path

Postby Bruno Pagès » Wed 6 Jan 2021 19:43

Hi,

There is no option to manage automatically your 'exotic' case.

If you really want to have the includes as you expect you have to place all the required #include forms by hand in the definition of the artifacts through the tabs C++ source, and may be C++ header, at the place of ${includes} to avoid the automatic generation. Of course you can remove ${includes} in the artifact definitions through the generation settings to have that behavior by default.

Regards,

Bruno
ImageAuthor of Bouml
Bruno Pagès
 
Posts: 689
Joined: Mon 20 Feb 2012 09:23
Location: France

Re: C++ #include with root relative path

Postby hmb » Mon 11 Jan 2021 21:49

Thanks Bruno for your prompt reply.

It's not so exotic. In fact my question was just to avoid having the inc/ directory prefix on each included header. If I need to move the inc/ directory to new one (ie. include/, and of course without regenerating), I just need to change the -I compiler option rather than search&replace or run sed-like command on the headers/sources.
On other projects where I used to generate both headers and sources on the same directory, the generated code works like a charm, but IMHO, when you are dealing with code intended to generate libraries, it is easier to handle the headers on their own directory, separated from the source code. Then, just as a preference, I try to avoid having unnecessary information spread on the code, if I can handle it in one place, in this case, this common path.

I will take a workaround like you mention, or probably leave the 'inc/' directory prefix as it is generated.

"Merci" again, And have a nice year!
Kind Regards,
--
Hernan
hmb
 
Posts: 2
Joined: Wed 6 Jan 2021 17:29


Return to Examples - How to do / Exemples - Comment faire

Who is online

Users browsing this forum: No registered users and 1 guest