Archived

This forum has been archived. Please start a new discussion on GitHub.

Output directories and include directories for slice2cpp

So, say I have a whole multi-level directory hierarchy of Ice files, some of which include one another. Something like this:

mod/sub1/Foo1.ice
module mod {
    module sub1 {
        interface Foo1 {
        };
    };
};

mod/sub2/Foo2.ice
#include <mod/sub1/Foo1.ice>

module mod {
    module sub2 {
        interface Foo2 {
        };
    };
};

If I do slice2cpp -I. mod/*/*.ice, I get a set of files, all in the target output directory. The #include statements make it sort of difficult to use them, though: in Foo1.cpp, it's got #include <Foo1.h>, with a similar statement in Foo2.cpp, but in Foo2.h there's #include <mod/sub1/Foo1.h>. So Foo1.h needs to be simultaneously in the same directory as Foo1.cpp and in a mod/sub1 subdirectory relative to Foo2.h.

Am I doing something wrong here? This seems to be overly complicated; it would be nice if the files got generated into a similar directory hierarchy as the Slice files. Or maybe I'm just seeing this all through my Java-programmer goggles and the true C++ way to do things is something else. :)

Thanks for any suggestions,

MEF

Comments

  • mes
    mes California
    Hi Mary Ellen,

    It can take a bit of trial & error to get the generated C++ code to your liking. The Slice translator does provide some options for customizing the generated #include statements, as described in section 6.15.1 of the manual.

    Your first step should be to decide how you want the generated files to be structured. For example, do you want the header files and source files all in the same directory? Or will you be relocating the header files to a separate "include" directory?

    As you've seen, the translator's default behavior for #include statements in header files is to mirror the the corresponding #include statements in the Slice files, so #include <mod/sub1/Foo1.ice> becomes #include <mod/sub1/Foo1.h>, reflecting the assumption that the header file will be located in a directory hierarchy similar to that of the Slice file. The manual describes how you can use -I options to influence this behavior.

    Let us know if you're still having trouble.

    Take care,
    - Mark
  • Have you tried the "--output-dir" option of slice2cpp? Maybe this could help, if you compile the ice file(s) by hand.

    If you put these preliminary steps into makefiles, you could "walk through" the slice file hierachy and compile the specifications in the respective directories directly.

    Take care,
    Andreas
  • mes
    mes California
    Just to be clear, you could run slice2cpp as follows:

    $ slice2cpp -I. -Imod/sub1 mod/*/*.ice

    Note that the first option (-I.) enables the compiler to locate the included file, whereas the only purpose of the second -I option is to customize the #include statements in the generated header files. As a result, the file Foo2.h should now contain #include <Foo1.h>.

    If you want to modify the #include statement in a generated source file, you can use the --include-dir option. You would only do that if you were going to move the generated header file out of the directory containing the generated source file.

    Naturally, whatever you do will have an impact on your application code, so you have to structure your source code, customize the generated #include statements, and specify the proper C++ compiler options so that everything builds properly.

    Hope that helps,
    - Mark