Automatically adding files/classes to targets

Alexander Neundorf neundorf at kde.org
Mon Feb 16 20:40:45 UTC 2009


On Thursday 05 February 2009, David nolden wrote:
> Am Donnerstag 05 Februar 2009 18:58:59 schrieb Alexander Neundorf:
> > On Thursday 05 February 2009, David nolden wrote:
> > > We need to integrate the "new file" and "new class" wizards with the
> > > project- management, so code-completion etc. in the new file can work
> > > right away within the file, and less user-interaction is needed.
> > >
> > > Currently the work-flow for creating new files and adding them to
> > > targets is not confortable yet.
> > >
> > > @Aleix: I though you've worked on this, but didn't find anything in the
> > > UI. Or was it just the required use-building that you've implemented?
> > >
> > > I think ideally we should have something like a list of few related
> > > targets from a project, where you can add checkboxes to automatically
> > > add the file to the target, directly integrated in the new-class and
> > > new-file dialogs.
> >
> > How do you want to do this ?
> > Let's say the developer choses target "foo". The cmake file could look
> > like this:
> >
> >
> > set(blubSrcs blub1.c blub2.c)
> >
> > set(fooSrcs file1.cpp file2.cpp)
> >
> > if(SOME_OPTION)
> >    set(fooSrcs ${fooSrcs} use_feature1.cpp)
> > else(SOME_OPTION)
> >    set(fooSrcs ${fooSrcs} use_feature2.cpp)
> > endif(SOME_OPTION)
> >
> > list(APPEND fooSrcs util.cpp)
> >
> > add_executable(foo ${fooSrcs} ${libSrcs} main.cpp)
> >
> > add_executable(blub STATIC ${blubSrcs} main.c)
> >
> >
> > The developer has to decide where to add the new file, I don't see a way
> > how an algorithm could do this automatically.
>
> We can implement a simple algorithm that should work for 99% of all cases,
> for the other ones the user has to do it by hand.
>
> You've got to consider this: Due to duchain declaration- and use-building,
> we know exactly where the target is declared, we know exactly where fooSrcs
> is declared, and we know exactly where fooSrcs is used.
>
> So we can have this simple algorithm:
> - Go to declaration of foo.
> - Is a variable that contains a list of files used within the
> add_executable(..) call?
> -- yes: Go to the place where the variable is defined, and add the file
> into the set(..)
> -- no: Append the file directly into the add_executable(..) call.
>
> Your case is a bit more complicated than the average stuff, but even here
> it would work up to a limited degree.

Due to that "limited degree" I would not trust an automatic solution.
Could the code check whether it is really only a trivial cmake file (as in 
your algorithm) and then do it as you suggest, and if it is more advanced, 
tell the user to do it manually instead of potentially messing the advanced 
cmake logic up ?

If the file is more complicated (the example was at most medium), the 
developer has to understand what the logic does and then has to decide what 
to do with the new file, otherwise the build will break (in some cases on 
some platforms with some special configurations). I think the developer 
should be made aware of the fact that the cmake file is complicated (if this 
is the case), it should not be hidden from him.

Alex




More information about the KDevelop-devel mailing list