Automatically adding files/classes to targets

David nolden david.nolden.kdevelop at art-master.de
Thu Feb 5 18:09:36 UTC 2009


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.

Greetings, David





More information about the KDevelop-devel mailing list