Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Question on programatically adding an include to CDTprojects

Beth,

I am doing something similar, but the approach I took was to look for a specific option (e.g. -I or -l). This, at least, is Posix compatible.

You can find the option by using  IOption.getCommand()

HTH
--
Derek


Beth Tibbitts wrote:
Nick/Mikhail,
I did this for the PTP wizard that added MPI include paths (etc) to an MPI
project. (managed build)
Mikhail is right, you have to iterate (or otherwise find) the tool objects
then work with those.
In fact I don't think my solution is completely general yet - i had to know
*which* tools/options i was looking for (gcc specifically i think) in order
to change them.
This solution isn't final, the new project model will probably let us be
more complete, but I'd welcome comments on doing this more generally with
the current model.


Here's an excerpt of what I did...
IManagedBuildInfo info = null;
            try {
                  info = ManagedBuildManager.getBuildInfo(proj);//proj is
the IProject
            } catch (Exception e) {...}

            IManagedProject mProj = info.getManagedProject();
            if(traceOn)showOptions(mProj);

            // add the include path & linker values to all the
configurations
            IConfiguration[] configs = mProj.getConfigurations();

            for (int i = 0; i < configs.length; i++) {
                  IConfiguration cf = configs[i];
                  addIncludePath(cf, newIncludePath);
                  addLinkerOpt(cf,newLib,newLibSearchPath);
                  setBuildCommand(cf,mpiBuildCommand);// "mpicc" for
example
            }
            ManagedBuildManager.saveBuildInfo(proj, true);

and for example here is the addIncludePath...  as you can see it's specific
for c, and gnu c compiler; I want it to be more general.
I think my use of getToolFromInputExtension is probably more restrictive
than I want, but it's all I could find at the time.

      private void addIncludePath(IConfiguration cf, String newIncludePath)
{

            String ext = "c";
            ITool cfTool = cf.getToolFromInputExtension(ext);

            String optID = "gnu.c.compiler.option.include.paths";
            IOption option = cfTool.getOptionById(optID);

            String[] includePaths = null;
            try {
                  includePaths = option.getIncludePaths();
            } catch (BuildException e) {...}
            //add include path
            int len = includePaths.length;
            String newIncludePaths[] = new String[len + 1];
            System.arraycopy(includePaths, 0, newIncludePaths, 0, len);
            newIncludePaths[len] = newIncludePath;

            ManagedBuildManager.setOption(cf, cfTool, option,
newIncludePaths);

      }
// again here I'm looking specificially for gnu tools, which I don't want
to do... more general approaches welcome!

      private void addLinkerOpt(IConfiguration cf, String libName, String
libPath) {
            String ext = "o";
            ITool cfTool = cf.getToolFromInputExtension(ext);

            // add to -l (libraries)
            String optLibsID = "gnu.c.link.option.libs";
            IOption option = cfTool.getOptionById(optLibsID);
            addOptionValue(cf, cfTool, option, libName);

            //    add to       -L (library search path)
            String optPathsID="gnu.c.link.option.paths";
            option=cfTool.getOptionById(optPathsID);
            addOptionValue(cf, cfTool, option, libPath);
            }

      private void setBuildCommand(IConfiguration cf, String buildCmd) {
            ITool compiler = cf.getToolFromInputExtension("c");
            ITool linker=cf.getToolFromInputExtension("o");
            compiler.setToolCommand(buildCmd);
            linker.setToolCommand(buildCmd);
      }



...Beth

Beth Tibbitts  (859) 243-4981  (TL 545-4981)
High Productivity Tools / Parallel Tools  http://eclipse.org/ptp
IBM T.J.Watson Research Center
Mailing Address:  IBM Corp., 455 Park Place, Lexington, KY 40511


"Sennikovsky, Mikhail" <mikhail.sennikov To sky@xxxxxxxxx> "CDT General developers list." Sent by: <cdt-dev@xxxxxxxxxxx> cdt-dev-bounces@e cc clipse.org Subject RE: [cdt-dev] Question on 11/01/2006 04:54 programatically adding an include AM to CDTprojects Please respond to "CDT General developers list." <cdt-dev@eclipse. org>



Hi Nick,

This is a know issue. The path entries work in “one direction” with Managed
Build projects now, i.e. when you modify Managed Build options, the changes
are propagated to the path entries but not vice a versa. So include path
entries you add are not propagated to the Managed Build System (MBS)
currently. We are going to fix this with the New Project Model in 4.0.
As of now, you have to find and explicitly modify MBS tool options that
represent include paths in your tool-chain in order to add include paths
settings.
Let me know if you need more detail about how to do that programmatically.

Mikhail



From: cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx] On
Behalf Of Nick Sandonato
Sent: Tuesday, October 31, 2006 10:41 PM
To: cdt-dev@xxxxxxxxxxx
Subject: [cdt-dev] Question on programatically adding an include to
CDTprojects

Hello,

I've been stuck on this issue for a while now.  I'm attempting to add a
library and an include entry for a CDT-based project.  I do this in the
project creation wizard, after overriding performFinish() in a subclass of
NewManagedCCProjectWizard using what I've come across in a few instances
(just the includeEntry code for now):

IPathEntry[] entries = cProject.getRawPathEntries();
List<IPathEntry> newEntries = new
ArrayList<IPathEntry>(Arrays.asList(entries));
IIncludeEntry incEntry =
CoreModel.newIncludeEntry(newProject.getFullPath(), new
Path("C:\\gsroot\\include\\systemc"), new Path("./"), false);

newEntries.add(incEntry);

CoreModel.setRawPathEntries(cProject, (IPathEntry[]) newEntries.toArray(new
IPathEntry[newEntries.size()]), null);
CoreModel.validatePathEntry(cProject, incEntry, true, true);


When executing, this adds the include path to the C/C++ Project view under
the Includes container; however, attempting to compile will fail.  I've
noticed that this directory is not being added to the subdir.mk file.

Am I missing something blatently obvious?  Or is there another way I should
be going about this.

Thank you in advance,
Nick_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev


------------------------------------------------------------------------

_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev



Back to the top