Search code examples
adagnat

How to make GPR accept multiple sources in the same project having the same file name?


I set out to rewrite an OSS project in C piece by piece to Ada. First stop being to replace the build system with GPR. On doing so I stumbled upon a problem: it does not allow for multiple sources in the repository with the same name:

duplicate source file name "slp_debug.h"

The file exists in two different directories; one for implementation, and one for test (stub I reckon). This should be just fine since the preprocessor will deterministically choose the source relative the source including it, or according to the order of include directories. But GPR would appear not fond of that idea.

How to make GPR accept it?


Solution

  • I had a go with openslp-2.0.0 and managed to make one GPR that builds the library and another, which withs the first, to build the tests - no complaints about the duplicate file.

    Both project files are at the top level.

    As common for projects like openslp, the configure process generates a lengthy config.h, at the top level, with a shedload of #define HAVE_FOO 1’s.

    This is the 'common' project file - I think there may also be an executable in there (slptool), which might have to be a separate GPR since this one builds a library:

    project Openslp is
    
       for Languages use ("c");
    
       for Source_Dirs use ("common", "libslp", "libslpattr");
       for Excluded_Source_Files use
         (
          "slp_win32.c",       -- not on Darwin! or Linux, ofc
          "libslpattr_tiny.c"  -- I think this must be an alternate version
         );
    
       for Library_Name use "slp";
       for Library_Kind use "static";
       for Library_Dir use "lib";
    
       for Object_Dir use "obj-openslp";
       for Create_Missing_Dirs use "true";
    
       package Compiler is
          for Switches ("c") use
            (
             "-DDARWIN",
             "-DHAVE_CONFIG_H",
             "-I" & project'Project_Dir,  -- for config.h, created by configure
             "-I" & project'Project_Dir & "/common",
             "-I" & project'Project_Dir & "/libslp",
             "-I" & project'Project_Dir & "/libslpattr",
             "-DETCDIR=""" & project'Project_Dir & "/etc"""
            );
       end Compiler;
    
    end Openslp;
    

    and this is the 'test' one:

    with "openslp";
    project Openslp_Test is
    
       for Languages use ("c");
    
       for Source_Dirs use ("test/**");
       for Object_Dir use "obj-openslp_test";
    
       for Exec_Dir use "test/bin";
       for Main use ("SLPFindAttrs.c");  -- etc, etc
    
       for Create_Missing_Dirs use "true";
    
       package Compiler is
          for Switches ("c") use
            ("-I" & project'Project_Dir & "/test")  -- for the local slp_debug.h
            & Openslp.Compiler'Switches ("c");
       end Compiler;
    
    end Openslp_Test;