Dev:Doc/IDE Configuration/Linux CMake QtCreator

提供: wiki
移動先: 案内検索

Optimized IDE Setup on Linux

Some of the steps in this guide are not immediately obvious even for experienced linux users/developers so I have written up this document for others who are interested in developing blender on linux.


Qtc blender 25.png


Who Is This For?

Linux developers who want to setup an efficient build environment.

There are a number of aspects that help to achieve this:

  • Using a minimal CMake configuration.
  • QtCreator has a fast C/C++ source code indexer (much faster than eclipse/netbeans/kdevelop)
  • Avoid executing the install target (no copying files on rebuild), instead reference the files in-place to run blender.

Starting out

This document assumes you have built blender using the Linux/CMake Quickstart.

  • blender source in ~/blender-git/blender
  • blender build in ~/blender-git/build

This was tested on Ubuntu but should work on any recent Linux distribution.

Installing QtCreator

QtCreator is an IDE which can be used for general C/C++ development, not just QT Applications, it has an editor, debugger, auto-completion as well as git and cmake integration.

Download and install from QT's site: http://www.qt.io/download-open-source/#section-6

Click 'View All Downloads', then scroll down to the Qt Creator standalone packages and download the most current package for your system.

Configure QtCreator

Launch QtCreator.

Before loading a blender project make some minor changes to QtCreators defaults.

Open the Options dialog Tools -> Options

Build and Run

  • Always build project before deploying it (disable)


For instructions on configuring QtCreator for blenders style

see: http://wiki.blender.org/index.php/Dev:Doc/CodeStyle/Configuration#QtCreator

Making a new QtCreator Project

Create the Project

Note, for now its recommended to use the custom project file generator included with blender until QtCreator's has support for reading CMakes defines & includes!

Using Blenders Custom Project File Generator

From your cmake dir run blenders project file generator. You may want to make some short cut to this - a shell script, bash alias or QtCreator external command all work fine.

cd ~/blender-git/build
python3 ../blender/build_files/cmake/cmake_qtcreator_project.py

From QtCreator go to File -> Open and select ~/blender-git/build/blender.creator

Blender3D FreeTip.png
Custom Project Names
If you want to use a custom name for the QtCreator project, you can use the --name or -n argument when calling the cmake_qtcreator_project.py script. This is useful if you want to manage multiple projects for multiple builds. The files created by this will then be called accordingly, e.g. some_name.creator instead of blender.creator


Configuring the Project

Now you should see the blender project open, start by pressing the build button(CtrlB), this should be very quick since blender has been built before.

To run blender you'll need to point to the blender executable: Projects (side toolbar) -> Run Settings (Tab), then see the "Executable" field, browse for the executable.

QtCreator stores its build directory in ~/blender-git/blender/blender.creator.user, if you have some configuration problem and wish to start over be sure to remove this file first.

Using QtCreators CMake Project Support (deprecated for now)

+ QtCreators CMake Project Support (deprecated)

  • File -> Open File or Project, Select ~/blender-git/blender/CMakeLists.txt

This invokes the CMake Wizard

  • Build Location change the build directory to ~/blender-git/build and press Next
  • Run CMake, Press the "Run CMake" button, then finish.
    note: this will use the configuration selected when first building blender from the command line.
Configuring the Project

Now you should see the blender project open, start by pressing the build button, this should be very quick since blender has been built before.

To run blender you need to select the binary, on the left hand side there is a "Projects" section, Select Run Settings, Change the run configuration from makesdna to blender and press "Make blender Active".

QtCreator stores its build directory in ~/blender-git/blender/CMakeLists.txt.user, if you have some configuration problem and wish to start over be sure to remove this file first.


To re-open the project after re-starting QtCreator, select this project from File -> Recent Projects

Debugging

In ~/blender-git/build/CMakeCache.txt, change CMAKE_BUILD_TYPE from Release to Debug. This will create a debug executable instead the next time you build Blender.

QtCreator requires an independent debugger program be installed on your system (e.g. GDB). If your distro does not automatically ship with one, you may need to manually install and set it up with QtCreator (see here for details).

The video bellow 'Navigate Code / Tips' has a part on how to debug using QtCreator.

Using QtCreator for Python

This section is optional and unnecessary if you are only interested in editing the C/C++ code.

The project generator also creates a project for python code. Go to File » Open and select ~/blender-git/build/blender.creator QtCreator supports having multiple projects open.

Git Integration

While there is reasonably good git integration in QtCreator, if you're comfortable using the git command line, then you can keep doing so.

  • Blender can be updated from git within QtCreator
    Tools -> Git -> Remote Repository -> Pull"
  • QtCreator's git blame integration is quite good, so you can see who last edited each line of a source-file.

QtCreator Videos

Here are the crep and prep tools mentioned in the videos.

Trouble Shooting

Ubuntu / Ptrace Error

On ubuntu there is a reported error running a debug binary within QtCreator.

Ptrace is 'process trance'. By using ptrace one process can control another, enabling the controller to inspect and manipulate the internal state of its target. Potentially a security problem, which is why this is switched on. There are therefore two solutions, open ptrace up permanently or temporarily.

Temporary solution is:

echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope

After reboot the ptrace will be active again so you may want to add this to a script file and run when using Qt Creator.

Permanent solution is:

1: Set 'ptrace_scope' to 0 in /etc/sysctl.d/10-ptrace.conf 2: Restart the service using sudo sysctl -p

Build button disabled in QtCreator

If the build button is disabled in QtCreator, it probably means there are no kits defined. Go to Tools -> Options then Build & Run -> Kits to add a kit for Desktop QT with GCC.

See also

Comparison QtCreator/KDevelop4 by Xat