Developing in Eclipse on Win32

From MythTV Official Wiki
Jump to: navigation, search

Introduction

With the release of QT Eclipse integration and the move to QT 4.4, it is now possible to have a fully working environment on Eclipse on Windows.

Important Note:

There are a few issues that need working around

  1. CMD and SH - Eclipse issues all commands under CMD, not SH. Therefore some modification need to be made, mainly to the build process. I am trying to get these into svn, but until then they are manual steps
  2. Eclipse support for PRO - for unknown reason, Eclipse can't import the three mythtv projects. A few workarounds are in place

CMD and SH

QMAKE supports compilation under windows both in CMD and SH environments. Both environments match the win32 directive in pro files. To distinguish between CMD and SH, QMAKE checks if sh.exe is in the PATH. If it is found in the path, then QMAKE_SH is set to "path to sh.exe", otherwise it is left empty. The default gmake.conf (mkspecs\win32-g++\gmake.conf) uses this value to set some CMD or SH defaults, and sets the value MINGW_IN_SHELL if SH.exe is used. Some parts of the mythtv pro files need to also use this value to provide an alternative for CMD build.

Overview of the process(Draft)

  1. Install the required Software packages: Eclipse for Windows, Perl support for Eclipse, SVN Plugin for Eclipse and TrollTech's QT integration
  2. Setup Win32 Environment by running win32-packager.pl
  3. Creating Eclipse Project Files
  4. Create the Eclipse project files for mythtv, mythplugins and myththemes
  5. Edit the Eclipse Startup file
  6. Make some changes in mythtv\config.mak, and pro files to support CMD build as well as SH
  7. Start up Eclipse
  8. Tweak some Eclipse settings
  9. Start working :)

Install Software Packages

Install:

Qt Eclipse Integration for C++ 1.4.0- [1]
EPIC (Eclipse Perl Integration) 0.6.24 - [2]
Subclipse 1.2.4 - [3]

Setup Win32 Environment

Run win32-packager.pl and build a completed mythtv,plugins and themes. For this example, we'll assume it was installed in c:\mythtv If you are starting completely from scratch, all you need is to download and run win32-packager.bat. Also see Windows_Port

Creating Eclipse Project Files

The final objective is to get win32-packager.pl to create this by request. For now, this script generates the required Eclipse files: Eclipse_setup.pl To run it, open a CMD window and type

perl c:\temp\Eclipse_setup.pl (assumes c:\mythtv as the root directory)
perl c:\temp\Eclipse_setup.pl -p c:\temp (sets root directory to c:\temp)

You must have the environment variable QTDIR defined

Edit the Eclipse Startup file

Edit the QT Eclipse Startup file: C:\Program Files\Trolltech\Eclipse\start.bat so c:\msys\1.0\bin is not part of the path. For example:

set path=c:\mingw\bin;c:\perl\site\bin;c:\perl\bin;c:\windows\system32;c:\windows

Change config.mak and pro files to support CMD builds

The final objective is to get these changes into SVN by default. Until that happens, they are summarized below

mythtv\config.mak and myththemes\mythconfig.mak from:

PREFIX=/c/mythtv/build
LIBDIRNAME=lib
LIBDIR=/c/mythtv/build/lib

to:

PREFIX=/c/mythtv/build
LIBDIRNAME=lib
LIBDIR=/c/mythtv/build/lib
isEmpty(MINGW_IN_SHELL) {
 PREFIX=C:\mythtv\build
 MSYS=c:\msys\1.0
 LIBDIRNAME=lib
 LIBDIR=C:\mythtv\build\lib
}

Change mythtv\version.pro from:

SVNTREEDIR = $$system(pwd)

to

win32:isEmpty(MINGW_IN_SHELL){
	SVNTREEDIR = $$system($$MSYS\bin\pwd.exe) 
} else {
	SVNTREEDIR = $$system(pwd)
}

AND from:

version.commands = \"$$SVNTREEDIR/version.sh \
   $$SVNTREEDIR \
   $$SVNREPOPATH\"	

to:

win32:isEmpty(MINGW_IN_SHELL) {
version.commands = c:\msys\1.0\bin\sh.exe -C \"$$SVNTREEDIR/version.sh \
   $$SVNTREEDIR \
   $$SVNREPOPATH\"	
} else {
version.commands = \"$$SVNTREEDIR/version.sh \
   $$SVNTREEDIR \
   $$SVNREPOPATH\"
}

Change mythtv\themes\themes.pro and myththemes\myththemes.pro from:

QMAKE_COPY_DIR = sh ./cpsvndir

to:

win32:isEmpty(MINGW_IN_SHELL){
	QMAKE_COPY_DIR = xcopy  /E /I /Y 
} else {
	QMAKE_COPY_DIR = sh ./cpsvndir
}

Start up Eclipse

  1. Startup Eclipse: Start -> Programs -> Qt Eclipse Integration v1.4.0 -> Start Eclipse with MinGW
  2. Define c:\mythtv as your default workspace
  3. In Eclipse, select Window -> Preferences. Select the QT Section. Press the Add button and define a new QT version:

Name: QT 4.4.0 Bin Path: <QTDIR>\bin Include Path: <QTDIR>\include Note that if you define more that one QT version, you will have to edit the Project Properties to indicate which one to use. If you only define one version, it will be picked up automatically

  1. Select Open WorkBench
  2. Select Project and unselect Build automatically
  3. Select File -> Import. Select General section and select "Existing Projects into Workspace"
  4. Press Next and select Browse
  5. The c:\mythtv directory should be selected. Press OK
  6. All three projects should appear, select all three
  7. When the "Add Files to QT Project dialog" appears, hit Cancel for each

Eclipse Hints

To add specific builds, for example programs\mythfrontend:

  1. Select the programs\mythfrontend directory in the Project Explorer window
  2. Right-click and select Make Targets -> Create
  3. Enter mythfrontend as the name
  4. Leave Make Target blank
  5. Verify that Build Command is mingw32-make
  6. Uncheck Run all project builders

To add a clean build for programs\mythfrontend, repeat the process above and:

  1. Enter "clean" for the Make Target

By default .pro files are opened with the Pro Editor. To open a pro file in text, right-click it and select Open with Text Editor. It will be remembered for next time

To Update the source to latest HEAD:

  1. Select Project -> Clean
  2. Select the project in the Project Explorer, right-click and select "Replace with Latest from Repository"
  3. Answer no to the following files: .project, .cproject, .metadata, .settings and .externaltoolbuilders
  4. Answer no to config.mak, version.pro if you have made the above changes (and they are not in SVN)

Caveats

For some reason, the lines for version.cpp is created twice. This causes some make warnings.

Eclipse doesn't like the empty "config" directory. Comment out "SUBDIRS += config" in myth.pro to solve it.