Difference between revisions of "How to build VCMI (Linux)"

From VCMI Project Wiki
Jump to: navigation, search
(Configure external program configure)
(Setting up a development environment using Eclipse CDT)
Line 2: Line 2:
 
There is a guide for compiling and running VCMI located in the SVN trunk root directory: [https://vcmi.svn.sourceforge.net/svnroot/vcmi/trunk/README.linux README.linux]
 
There is a guide for compiling and running VCMI located in the SVN trunk root directory: [https://vcmi.svn.sourceforge.net/svnroot/vcmi/trunk/README.linux README.linux]
  
= Setting up a development environment using Eclipse CDT =
+
= Setting up a development environment using QtCreator =
In order to do that you should followed the guide above first.
 
  
== Installing Eclipse ==
+
QtCreator is the recommended IDE for VCMI development on linux distros. (It may be used on other operating systems as well) It has the following advantages compared to other IDEs:
If you have installed Eclipse already, then you can skip this section.
+
* Almost no manual configuration when used with CMake (Project configuration is read from CMake text files)
 +
* Fast parser/indexer, stable
 +
* Can use several compiler toolchains: GCC, Visual Studio, Clang
 +
* Doesn't pollute SVN with project files
  
<ol>
+
You can download QtCreator from here: http://qt-project.org/downloads#qt-creator
<li>Eclipse offers a wide range of supported programming languages. The classic package only supports Java. It can be extended to support languages like C++, PHP, JavaScript, ActionScript,... via the "Install new software..."-dialog within Eclipse. Therefore you have one programming environment this means one program which provides many languages. That's the way described here. As a starting point download Eclipse Classic first. It can be obtained from here [http://www.eclipse.org/downloads/ Eclipse downloads].</li>
 
<li>Unpack the downloaded package.
 
<pre>tar xzf eclipse.tar.gz</pre></li>
 
<li>Move it to the /opt directory which is used for additional mostly not-UNIX-like programs in matters of the directory structure.
 
<pre>sudo mv eclipse /opt</pre></li>
 
<li>Adjust file access rights.
 
<pre>cd /opt
 
sudo chown -R root:root eclipse
 
sudo chmod -R +r eclipse
 
sudo chmod +x `sudo find eclipse -type d`</pre></li>
 
<li>Make eclipse more accessible.<pre>sudo touch /usr/bin/eclipse
 
sudo chmod 755 /usr/bin/eclipse
 
sudoedit /usr/bin/eclipse</pre>Enter these few lines in the editor, save the file and close the editor.<pre>#!/bin/sh
 
export ECLIPSE_HOME="/opt/eclipse"
 
$ECLIPSE_HOME/eclipse $* </pre></li>
 
<li>If you're using GNOME as the window manager then you may do the following steps. It's default on Fedora. That way you can start eclipse via the actvities window or the programs tab.<pre>sudoedit /usr/share/applications/eclipse.desktop</pre>
 
Enter the following lines in the editor:
 
<pre>[Desktop Entry]
 
Encoding=UTF-8
 
Name=Eclipse
 
Comment=Eclipse IDE
 
Exec=eclipse
 
Icon=/opt/eclipse/icon.xpm
 
Terminal=false
 
Type=Application
 
Categories=GNOME;Application;Development;
 
StartupNotify=true </pre></li>
 
<li>Clean eclipse.<pre>/opt/eclipse/eclipse -clean</pre></li>
 
<li>Start eclipse. Adjust workspace directory to sth. like: ~/Eclipse</li>
 
<li>Go to: Help -> Install new software...</li>
 
<li>Click on Add... and enter the Location <i>http://download.eclipse.org/releases/indigo</i> and Name <i>Indigo</i>. Make sure that you adjust the Location and Name to the used eclipse version.</li>
 
<li>Type in <i>Work with</i> the name of the recently added repository. Then select the package Programming Languages -> C/C++ Development Tools and install it. This will install Eclipse CDT.</li>
 
</ol>
 
  
== Setup a VCMI project ==
+
== Configuration ==
 +
To open the project you have to click File -> Open file or project... -> Select /trunk/src/CMakeLists.txt
 +
For the first time and for every CMake project configuration change you have to execute CMake. This step can be done when opening the project for the first time or alternatively via the left bar -> Projects -> Build Settings -> Execute CMake. You have to specify CMake arguments and the build dir. CMake arguments can be the following:
 +
<pre>-DDISABLE_ERM=ON -DCMAKE_BUILD_TYPE=Debug</pre>
 +
The build dir should be set to sth. like /trunk/build for the debug build and /trunk/buildrel for the release build.
 +
For cleaning the build dir a command like "make clean" may be not enough. Better way is to delete the build dir, re-create it and re-execute CMake. Steps for cleaning can be configured in the Projects tab as well.
  
=== Create project ===
+
== Debugging ==
# File -> New Project... -> C/C++ -> C++ Project -> Next
+
There is a problem with QtCreator when debugging both vcmiclient and vcmiserver. If you debug the vcmiclient, start a game, attach the vcmiserver process to the gdb debugger(Debug > Start Debugging > Attach to Running External Application...) then breakpoints which are set for vcmiserver will be ignored. This looks like a bug, in any case it's not intuitively. Two workarounds are available luckily:
# Type in a project name e.g. vcmi_animRewrite for the branch animRewrite, vcmi_trunk for the trunk, vcmi_0_88 for the tag 0.88
 
# Choose Makefile project -> Empty project -> Toolchain -> Linux GCC -> Finish
 
# Right click on project -> Properties. This will open the project properties where you can configure the sources folder, include paths,...
 
  
Add the bolded include paths as you can see them in the picture.
+
1) Run vcmiclient (no debug mode), then attach server process to the debugger
  
[[File:Eclipse_Include_Path.jpg|350px]]
+
2) Open two instances of QtCreator and debug vcmiserver and vcmiclient separately(it works!)
 
 
You have to click on Link Folder... and then Link to folder in the filesystem. Select the /src folder and the /build folder of one SVN project. If you link the /build folder then you can execute make targets.
 
 
 
[[File:Eclipse_SourcePaths.jpg|350px]]
 
 
 
Add the bolded symbols as you can see them in the picture. This one is missing add this as well: __GXX_EXPERIMENTAL_CXX0X__
 
That symbols are for the Eclipse CDT parser only.
 
 
 
[[File:Eclipse_Symbols.jpg|350px]]
 
 
 
You'll recognize that there are some errors in some source files. That's because the Eclipse parser can't understand every C++ language feature especially c++11. This doesn't mean that they are real errors. BOOST_FOREACH errors are fixed with the appropriate macro stated above in the picture. The parser has problems with std::make_pair perhaps this will be fixed in a later release of CDT as this error message appears often. You may disable warnings and errors reporting completely, so you won't be slowed down by configuring Eclipse CDT many hours.
 
 
 
=== Configure external program configure ===
 
 
 
# Go to Run -> External Tools -> External Tools Configuration...
 
# Add new launch configuration(Program) -> Choose the configure script as the location via the Browser Workspace Button
 
# Working directory is the /build folder
 
# Arguments may the following : <code class="inline">--datadir=/usr/local/share/ --bindir=/usr/local/ --libdir=/usr/local/lib64/.</code> The /vcmi folder at the end of datadir and libdir is not missing. It will be added automatically by the configure script.
 
# Save configuration with Apply and Close.
 
 
 
That way you don't need to run the ./configure script via the terminal. It can be executed within eclipse.
 
 
 
=== Configure debug/run applications ===
 
 
 
Go to Run -> Debug/Run configurations...
 
 
 
Add new launch configuration(C++ application)
 
 
 
Choose vcmiclient via Search project...
 
 
 
Make sure that Use Workspace Settings is enabled
 
 
 
VCMI won't start/debug if you don't set a specific environment variable due to shared libraries loading. Go to tab Environment -> New... Name = LD_LIBRARY_PATH Value = e.g. /usr/local/lib64/games/vcmi(where your shared libraries are located)
 
 
 
Then go to Project -> Properties -> C/C++ Build -> Builder settings -> Change build location to sth. like project/build(where your makefiles are located). That way the project will be automatically built before launching/debugging.
 

Revision as of 17:06, 22 October 2012

Compiling VCMI

There is a guide for compiling and running VCMI located in the SVN trunk root directory: README.linux

Setting up a development environment using QtCreator

QtCreator is the recommended IDE for VCMI development on linux distros. (It may be used on other operating systems as well) It has the following advantages compared to other IDEs:

  • Almost no manual configuration when used with CMake (Project configuration is read from CMake text files)
  • Fast parser/indexer, stable
  • Can use several compiler toolchains: GCC, Visual Studio, Clang
  • Doesn't pollute SVN with project files

You can download QtCreator from here: http://qt-project.org/downloads#qt-creator

Configuration

To open the project you have to click File -> Open file or project... -> Select /trunk/src/CMakeLists.txt For the first time and for every CMake project configuration change you have to execute CMake. This step can be done when opening the project for the first time or alternatively via the left bar -> Projects -> Build Settings -> Execute CMake. You have to specify CMake arguments and the build dir. CMake arguments can be the following:

-DDISABLE_ERM=ON -DCMAKE_BUILD_TYPE=Debug

The build dir should be set to sth. like /trunk/build for the debug build and /trunk/buildrel for the release build. For cleaning the build dir a command like "make clean" may be not enough. Better way is to delete the build dir, re-create it and re-execute CMake. Steps for cleaning can be configured in the Projects tab as well.

Debugging

There is a problem with QtCreator when debugging both vcmiclient and vcmiserver. If you debug the vcmiclient, start a game, attach the vcmiserver process to the gdb debugger(Debug > Start Debugging > Attach to Running External Application...) then breakpoints which are set for vcmiserver will be ignored. This looks like a bug, in any case it's not intuitively. Two workarounds are available luckily:

1) Run vcmiclient (no debug mode), then attach server process to the debugger

2) Open two instances of QtCreator and debug vcmiserver and vcmiclient separately(it works!)