OTTD & Code::Blocks

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Post Reply
TadeuszD
Transport Coordinator
Transport Coordinator
Posts: 329
Joined: 07 Nov 2011 19:32
Location: PL

OTTD & Code::Blocks

Post by TadeuszD »

Has anyone tried to convert OTTD project to the Code::Blocks IDE? Is it possible at all?
Image
User avatar
adf88
Chief Executive
Chief Executive
Posts: 644
Joined: 14 Jan 2008 15:51
Location: PL

Re: OTTD & Code::Blocks

Post by adf88 »

I remember that I did it once, long time ago. It's not difficult. I was testing Code::Blocks but KDevelop beat it.

AFAIR steps are similar to these: http://wiki.openttd.org/KDevelop.

First you have to create a makefile: Then, in Code::Blocks, setup a "Makefile" project.
:] don't worry, be happy and checkout my patches
User avatar
HackaLittleBit
Director
Director
Posts: 550
Joined: 10 Dec 2008 16:08
Location: tile 0x0000

Re: OTTD & Code::Blocks

Post by HackaLittleBit »

Install Linux (Mint Cinnamon) and get it running with all updates etc.
From Software Manager
Install Openttd
install Meld (Graphical tool to diff and merge files)
Install TortoiseHG
Install Code Blocks
Install Xterm

Open TortoiseHG.
Click: File → Clone Repository
Source = http://hg.openttd.org/trunk.hg/
Destination = “Your development directory (no spaces in path)” e.g. LOCAL_REPOSITORY
Click: clone , and let it run.
Close TortoiseHG.

Open Code Blocks
Click: File → Import project → Ms Visual Studio Solution
Find them in LOCAL_REPOSITORY/projects and select openttd_vs90.sln.
(That one worked the best for me.)

Question: Do you want the imported projects to use the default compiler? YES

Question: Do you want to import all configurations (e.g. Debug/Release) from the imported projects? YES
(Maybe some little problems but not important)

Finishing touches:
You can see on your left side all the project files.
Right Click: on ‘openttd’ and select ‘Properties’.
In ‘Project settings’ Click on ‘This is custom Makefile’
The ‘Execution directory’ should be the same as LOCAL_REPOSITORY
If being asked ‘Keep this as a relative path?’ Click YES.
Click OK now!

Right Click: on ‘openttd’ and select ‘Properties’ again.
In ‘Build targets’ Click ‘Rename’ and change ‘Release win32’ to ‘Release’.
Click on ‘Debug win32’ and rename to ‘Debug’
Delete the options with x64.
Change ‘Output filename’, On the right side Click and select
LOCAL_REPOSITORY/bin/openttd
The result should look like this: ../bin/openttd
Click OK now!

Right Click: on ‘openttd’ and Click ‘Build options...’.
Click ‘Release’
Click 'Pre/post build steps'
Copy-paste this: sed -i 's/debug/release/g' $(PROJECTTOPDIR)Makefile.am in 'Pre-build steps'
Click ‘”Make” Commands’
Change ‘Build project/target:’ from ‘$make -f $makefile $target’ to ‘$make’
Change ‘Clean project/target:’ from ‘$make -f $makefile clean$target’ to ‘$make clean’
Change ‘Ask if rebuild is needed:’ from ‘$make -q -f $makefile $target’ to ‘$make -q -f $makefile
Click OK now!

Right Click: on ‘openttd’ and Click ‘Build options...’.
Click ‘Debug’
Click 'Pre/post build steps'
Copy-paste this: sed -i 's/release/debug/g' $(PROJECTTOPDIR)Makefile.am in 'Pre-build steps'
Click ‘”Make” Commands’
Change ‘Build project/target:’ from ‘$make -f $makefile $target’ to ‘$make’
Change ‘Clean project/target:’ from ‘$make -f $makefile clean$target’ to ‘$make clean’
Change ‘Ask if rebuild is needed:’ from ‘$make -q -f $makefile $target’ to ‘$make -q -f $makefile
Click OK now!

In the top bar of CodeBlock Click 'Tools' Select Configure tools
Click 'Add'
In 'Name:' write, Configure for Debug
In 'Executable: Select directory were 'configure' is located.
In 'Parameters:' write --enable-debug="1"
Select Launch tool hidden with standard output redirected
Click OK now!

Click 'Add'
In 'Name:' write, Configure for Release
In 'Executable: Select directory were 'configure' is located.
Select Launch tool hidden with standard output redirected
Click OK now!
Click OK now!

Now Click 'Tools' and Click both options to configure your system for Release and Debug.

Now Click 'File' -> 'Save Workspace as' and select a folder were you want to keep it.

Now Click 'File' -> 'Save all files'

Thats it You are ready to roll.

To hide the changed project files from TortoiseHg and git
Add: projects/*.cbp and projects/*.layout to the two files .hgignore and .gitignore that you
can find in LOCAL_REPOSITORY


I may have forgotten something, let me know.
Last edited by HackaLittleBit on 29 Dec 2016 21:54, edited 2 times in total.
TadeuszD
Transport Coordinator
Transport Coordinator
Posts: 329
Joined: 07 Nov 2011 19:32
Location: PL

Re: OTTD & Code::Blocks

Post by TadeuszD »

Thank You, HackaLittleBit, for very precise solution! I will try it! :D
Currently I'm using MinGW environment on Windows + Code::Block. Earlier I used MS VS Express 2012 on MS Windows for compile OpenTTD, but this tool generates a few problems (i.e. described in topic viewtopic.php?f=33&t=59372&start=14 ).
Image
User avatar
HackaLittleBit
Director
Director
Posts: 550
Joined: 10 Dec 2008 16:08
Location: tile 0x0000

Re: OTTD & Code::Blocks

Post by HackaLittleBit »

I will use this post to report minor updates and changes in my previous post.

In 'Executable:' write $(PROJECTTOPDIR)configure was changed to -> In 'Executable: Select directory were configure is located.
PROJECTTOPDIR did not work.
And I was not able to pass a flag to make the switch between release and debug less hackish.
User avatar
HackaLittleBit
Director
Director
Posts: 550
Joined: 10 Dec 2008 16:08
Location: tile 0x0000

Re: OTTD & Code::Blocks

Post by HackaLittleBit »

Here a small script to generate Code::Blocks project for OpenTTD(see attachment)
Place the bash script in the "projects" folder and execute it.
It will create a file called Openttd.workspace
If you click it it should open Code::Blocks with the project ready to run.
The rest of the files will be created in the folder codeblocks.

I was never able to get the debugger to work correctly so I abandoned Code::Blocks.
I tried Qt Creator and as adf88 suggested, KDevelop.

I stayed with KDevelop and am happy.

P-S. I am not able to edit above post anymore.
small change has to be done
single quotes(') should be double quotes(").
e.g. 's/debug/release/g' => "s/debug/release/g"
Attachments
generateCB.zip
(1.43 KiB) Downloaded 38 times
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: Google [Bot] and 14 guests