As recently the number of users of KDevelop4 has grown and apparently there are quite some “newbies” among them (which is good, new users always mean we easily see flaws in our GUI) I’ve decided to do a small howto on creating, building and running a simple CMake based KDevelop4 project.
First of all: I’m using a Qt4 CMake project using just QtCore, which is the closest you get currently to a simple C++ “hello world” project. We currently don’t have good support for QMake and no project templates for plain Makefiles.
You can create new projects via the Project -> New Project menu entry. Note: for this to work you need KDevelop to load all its plugins, as the menu entry and the underlying functionality is provided by a plugin. If you can’t see it, see my What to do when I don’t have New Project post. You should now see this dialog:
The image shows quite a couple of items in the tree, if you install only kdevplatform and kdevelop you’ll only have the C++ part and therein only the Qt subelements. The other entries are provided by kapptemplate, a program found in the kdesdk module. As I said before I’ll be taking the Qt4 CMake Core application, its under C++->Qt (cmake). After that I supply a project name and leave the default destination directory. This now looks like this:
I’ll skip the version-control page and just hit the Finish button. KDevelop now creates and loads the new project. I can now open the “Projects” toolview on the left and see the project. As this is a cmake project (and we suck and haven’t made this easier yet) you need to tell KDevelop a directory where you want to build the project. To do that open the projects configuration by right-clicking onto the entry in the “Projects” toolview and selecting the “Configure Project” context menu entry. You should now see the configuration dialog (I’ve selected the CMake page already):
With the little “+” button you can add a new builddirectory. This should either be a directory where you’ve previously run cmake for this project (which we haven’t done yet) or a non-existing or empty directory. I’ll be using a “build” subdirectory inside the project directory. Now hit the “Run” button and cmake should be run and its output should be printed in the list. The dialog now looks like this:
After clicking “Ok” KDevelop will read and parse the CMakeCache.txt file and show its contents. You can edit it here if you want to.
Now there are two ways of building the project, you can either again right-click the project entry in the tree and select the Install entry from the menu. Or you can use the buildset in the bottom of the Projects toolview. This allows you to build multiple projects (or files/targets/subdirectories) at once, you can simply add the selected entries from the tree by using the “+” toolbutton in the buildset widget. After that you can use one of the three toolbuttons to the left of the “+” button to build, install or clean. The entries in the Project menu to build, install and so on also use the buildset, so they only work when the buildset is not empty. KDevelop will show the output of running make in the bottom toolview. This is how KDevelop now looks after building the project (this project doesn’t support installation):
Now the last part: Running the created executable. Unfortunately this part is still changing a lot, so I’m not sure its working right now, but at least we can do the setup part. Again open the project configuration dialog by right-clicking onto the project entry in the treeview and selecting “Configure Project” from the menu. In the dialog open the “Run Settings” entry, in the run page click on the “+” button and give a name to the run configuration.
Select the “Executable” radiobutton and put the path to the executable (including the executable) into the lineedit. As my project resides in $HOME/testproject and the build directory is a subdirectory of that, the path here is $HOME/testproject/build/src/testproject. I’ve also set a working directory just to be sure this works (hopefully). The configuration can be seen here:
Now you should be able to select this run target under Run->Run Current Target, however it seems this part is currently not working. Lets assume it does, the last step is selecting the entry Run->Execute Program, which would print “Hello World!” into the bottom toolview.
I hope this helps those people trying to use KDevelop4 for the first time, if anybody has question: Just ask us on the mailinglist firstname.lastname@example.org (registration under http://www.kdevelop.org) or join us on freenode in #kdevelop.
This has come up a few times lately, so I’ll do some explanations of possible causes for KDevelop4 not having a “New Project” entry in the menu. This simply means that a plugin wasn’t loaded, in particular here it is the Application Wizard plugin which provides the functionality to create new projects from templates.
This can have a few possible reasons, which are somewhat related. First of all: If you installed kdevelop4 into a different directory than your KDE4.2, then you need to make sure to set KDEDIRS apropriately. Lets say I have packages for KDE4.2 beta2 from my distribution, which install into /usr. So I have /usr/lib/libkdecore.so.4.2.0 and /usr/share/kde4/services and so on. This means, KDE4.2 uses /usr as so-called prefix. I then compiled and installed both kdevplatform and kdevelop into my home directory, so its in $HOME/kde4. I have $HOME/kde4/lib/libkdevplatforminterfaces.so.1.0.0 and $HOME/kde4/share/kde4/services/kdevappwizard.desktop. So the prefix for kdevelop4 is $HOME/kde4. KDEDIRS is simply a list of such prefixes, so I set it to be “$HOME/kde4:/usr” via “export KDEDIRS=$HOME/kde4:/usr” in a bash.
I’ve done this in a terminal, so I can be sure the environment is properly setup. Now I let KDE4 update its internal system cache, which also knows about all installed .desktop files for plugins. This is not (always) done automatically after installing new .desktop files, so if you don’t see the plugins, run the following command: kbuildsycoca4.
After that you should start kdevelop from the same terminal and then you should see the New Project entry and be able to create projects. If you still have problems, make sure you’ve built kdevelop in Debug mode (pass -DCMAKE_BUILD_TYPE=Debug to cmake) and collect the output via kdevelop >output 2>&1. Then join us in #kdevelop on irc.freenode.org and let us know the contents of the file, this should give us some hints why it fails for you and we can help you fix it.