Archived

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

Include syntax of generated files.

I am using #include "..." syntax in an ice input file and the generated code is changing it to #include <...>. This makes it hard to create -I paths to access the files. There is a subtle difference between the following:

#include <xyz.h>
#include "xyz.h"

and this difference is sometimes important. In my case I'm moving generated header files to a public include dir. Putting -I. on the include path will not work because -I. means the current directory of compilation process whereas "xyz.h" means current dir of the file in which the #include "xyz.h" is located. Note that '-I.' is not always even the current dir of the .cpp file being compiled.

Can the generated code preserve the quotes or angle brackets as they are in the input file? I suppose it may be hard to do because the preprocessor has already removed this information. Just thougt I'd ask before I make a workaround.

Comments

  • mes
    mes California
    Hi John,

    Section 4.4.3 of the Ice manual states the following:
    #include directives can appear only at the beginning of a Slice source file, that is, they must precede all other Slice definitions. In addition, only #include directives using the <>-syntax to specify a file name are permitted; use of the ""-syntax is not supported.
    So technically your Slice code is invalid, and only works because Ice currently uses a C preprocessor. It is possible in the future that Ice would eliminate the external preprocessor and only support what is described in the manual.

    The Ice source code also moves generated header files. With careful use of the -I and --include-dir options, it should be possible to achieve the desired result. Let us know if you're still having trouble.

    Take care,
    - Mark
  • Can the <> include path information?

    // -*- mode: idl -*-
    #ifndef NavUpdate_ice
    #define NavUpdate_ice

    #ifndef NavData_ice
    # include <cnav/NavData.ice> // << See here
    #endif

    module cnav
    {
    interface NavUpdate
    {
    nonmutating void update(NavData data);
    };
    };
    #endif /* NavUpdate_ice */


    The manual is ambiguous:

    • #include directives can appear only at the beginning of a Slice source file, that is, they must precede all other Slice definitions. In addition, only
    #include directives using the <>-syntax to specify a file name are permitted; use of the ""-syntax is not supported. For example:
    #include <File1.ice> // OK
    #include "File2.ice" // Not supported!

    Doesn't say no '/'. I tried it and it doesn't work.
  • mes
    mes California
    Can the <> include path information?
    Yes, that is legal. Furthermore, you can ensure that the generated code uses the same path information by using the -I and --include-dir options. Take a look at how the Ice Slice files work, in conjunction with Makefiles such as src/Ice/Makefile.

    - Mark
  • mes wrote:
    ...using the -I and --include-dir options.

    Ok now it works. Looks like the --include-dir puts its argument string into generated file between the <> before the file name. <arg/file.h>

    Eample: $ slice2cpp --include-dir CNAV ...
    Produces: include <CNAV/NavData.h>

    That works for me.

    The documenation (both --help and pdf manual) doesn't quite make this clear. Here's what command line help says.

    --include-dir DIR Use DIR as the header include directory in source files.