Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: johne53 on April 27, 2007, 03:10:39 pm

Title: SConstruct (Scons)
Post by: johne53 on April 27, 2007, 03:10:39 pm
I'm led to believe that C::B can be configured to work with Scons. Can anyone tell me how to set this up? Is it via a plugin or something?
Title: Re: SConstruct (Scons)
Post by: Game_Ender on April 29, 2007, 04:03:54 am
You have to set up Code::Blocks to call an external build tool instead of its own compiler system.
Title: Re: SConstruct (Scons)
Post by: johne53 on April 29, 2007, 08:42:00 am
One of the thigs that impressed me about the Windows version of Code::Blocks was that I could import an existing Visual C++ project which would instantly create a full project tree within C::B.

Is anything like that available for an existing Scons file - or even a Make file?
Title: Re: SConstruct (Scons)
Post by: TDragon on April 29, 2007, 04:04:08 pm
One of the thigs that impressed me about the Windows version of Code::Blocks was that I could import an existing Visual C++ project which would instantly create a full project tree within C::B.

Is anything like that available for an existing Scons file - or even a Make file?
No, not currently. Importing a Scons file is a possibility (though not yet implemented), but importing a Makefile is highly unlikely. Makefiles are so flexible and powerful that there is no standard way of defining them, so it would be very difficult to design a parser that could translate an appropriate C::B project from even a small fraction of Makefiles "in the wild".
Title: Re: SConstruct (Scons)
Post by: johne53 on April 29, 2007, 04:23:58 pm
Thanks TDragon - looks like I'll have to do it the hard way then...!  :)
Title: Re: SConstruct (Scons)
Post by: kolku on May 01, 2007, 02:39:13 pm
I had written up these instructions for use at my job... hope they are helpful.

Setting Up Code::Blocks  ¶

    * Startup Code::Blocks
    * If Code blocks ask you to associate itself with source files make your own decision.
    * Click Create a new project from the startup page/window.
    * In the resulting dialog select Empty Project
    * Hit Go
    * In the Folder to create project in: field enter your directory path to the trunk.
          o Example: Mine is c:\Code\trunk\
          o Make sure the final directory that the *.cbp file ends up in is where you top level SConstruct file is.
    * Hit Next
    * In the Compiler: pull-down select GNU GCC Compiler
          o This requires that MinGW is installed… look at the Install section above.
    * Select the Create "Release" configuration
    * Hit Finish
    * Goto Project ⇒ Properties…
    * Select This is a custom Makefile [checkbox]
    * Hit OK
    * Goto [Menu] Project ⇒ Build options… A dialog appears.
    * Select Release from the left pane.
    * From the second pull-down select "Make" commands
    * Delete the contents of the four lower fields
    * In the first field, Build project/target:, insert the following <path to scons.bat>\scons.bat -k -j 2
          o On my system <path to scons.bat> is c:\apps\coding\Python\ so the result is c:\apps\coding\Python\scons.bat -k -j 2
          o The default location of Python is something like c:\Python24
    * Skip the second field (i.e. leave this blank)
    * In the 3rd and 4th fields enter <path to scons.bat>\scons.bat -c

Populating a Code::Blocks Project ¶

    * Goto Project ⇒ Add files recursively…
    * Browse to your /trunk directory, select it and hit OK
    * Hit the Wildcard select button
    * Enter the following (or whatever makes sense for your project): *.cc;*.hh;*.cpp;*.h;*.c;*.S;*.y;*.yy;*.l;*.ll;*.txt;*.py;*.xml;*.base;*sconstruct;*sconscript
    * Alternative to Wildcard select: Just hit the Select All button
    * Hit OK
    * Hit Yes to clear previous selections.
    * Hit OK
    * Wait for a second or two while it parses everything

Building with Code::Blocks ¶

    * Find the blue button that looks sort of like a gear.
    * Click it :D

Clean your code with Code::Blocks ¶

    * Find the button that looks like it has two green arrows chasing each other.
    * Click it :D
Title: Re: SConstruct (Scons)
Post by: johne53 on July 27, 2007, 01:00:38 pm
Hi Kolku - I'm really sorry but somehow I didn't notice this reply from you. Your instructions sound really interesting though. Just out of interest, do you find any discrepancies when building single individual source files? I haven't tried your instructions yet but I did try compiling some of this project's source files from within C::B. Even though I was using the same compiler, I couldn't get the relevant object files to be anything like the size that they are when compiled via Scons. This kinda put me off going too much further....  :(

I tried messing around with compiler options and preprocessor directives- but my resultant object files were often half (or even twice) the size of the Scons equivalent. Did you find that problem too - and if so, is there a way around it?
Title: Re: SConstruct (Scons)
Post by: Mad Scientist on July 27, 2007, 04:31:11 pm
Quote
johne53:Even though I was using the same compiler, I couldn't get the relevant object files to be anything like the size that they are when compiled via Scons.
Could Code::Blocks be including some of the include files with the single file compile maybe? (check to see if the exe is the same or larger to check)

Also what I found makes it easy is to use a really short makefile the plus side being you can keep the setup the same for codeblocks you just need to select the makefile and have scons in your PATH environment variable.

Code
All:
scons -ks -j 3
Release:
scons build=release -ks -j 3
Debug:
scons build=debug -ks -j 3
Profile:
scons build=profile -ks -j 3
clean:
scons --clean -k
For a quick make tut for this short file:
The labels( eg "All:, "Release:" etc etc ) are the build targets and the tabbed( not spaced ) lines are the commands executed for each target. Note the build=____ is handled by the scons script itself not some function of scons. Also the -s option means only script comments and errors are output.
Title: Re: SConstruct (Scons)
Post by: johne53 on July 27, 2007, 08:38:08 pm
Could Code::Blocks be including some of the include files with the single file compile maybe? (check to see if the exe is the same or larger to check

Good suggestion. In this case the target is a shared object (i.e. dynamic library) and no - they're not the same size. The one built with Scons is slightly bigger than mine.

I used nm to print out the contents of each version. They were almost identical - except that the Scons build had these additional lines at the beginning:-

Code
00007beb t .L39
00007c01 t .L40
00007c1f t .L41
00007c35 t .L42
00007c6a t .L43
00007c9f t .L44
00007d3d t .L50
00007d74 t .L51
00007d9f t .L52
00007dd6 t .L53
00007e09 t .L54
00007e3c t .L55
0000e1a8 d DW.ref.__gxx_personality_v0

I don't know if that means anything to anyone but it doesn't mean much to me. The actual SConscript file for this project is quite small and looks like this:-

Code
# -*- python -*-

import os
import os.path
import glob

soundtouch_files = Split("""
AAFilter.cpp
FIFOSampleBuffer.cpp
FIRFilter.cpp
RateTransposer.cpp
SoundTouch.cpp
TDStretch.cpp
mmx_gcc.cpp
cpu_detect_x86_gcc.cpp
""")

Import('env install_prefix')
st = env.Copy()
st.Append(CCFLAGS="-DHAVE_CONFIG_H -D_REENTRANT -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE")

libst = st.SharedLibrary('soundtouch', soundtouch_files)

Default(libst)

env.Alias('install', env.Install(os.path.join(install_prefix, env['LIBDIR'], 'ardour2'), libst))

env.Alias('tarball', env.Distribute (env['DISTTREE'],
[ 'SConscript'] + soundtouch_files + glob.glob('*.h')))

I'm not sure what the various import lines do - but I'm guessing that they're probably responsible for the extra code.
Title: Re: SConstruct (Scons)
Post by: johne53 on July 28, 2007, 07:48:41 am
This morning I had a flash of inspiration.... I realised that it's possible for nm to produce a more detailed output - including the size of each entry in the lib or shared object. Here's a small section, firstly from my compiled target:-

Code
// My target !
00008736 000003d9 T soundtouch::SoundTouch::putSamples(float const*, unsigned int)
000084e0 00000169 T soundtouch::SoundTouch::setSetting(unsigned int, unsigned int)
00008e5e 0000014f T soundtouch::SoundTouch::setChannels(unsigned int)
00008356 0000000a T soundtouch::SoundTouch::getVersionId()

and now, the same section from the target built by Scons:-

Code
Scons target !
00007fa0 00000421 T soundtouch::SoundTouch::putSamples(float const*, unsigned int)
00007ce4 0000019d T soundtouch::SoundTouch::setSetting(unsigned int, unsigned int)
000087d8 00000152 T soundtouch::SoundTouch::setChannels(unsigned int)
00007b22 0000000a T soundtouch::SoundTouch::getVersionId()

The second column is (I believe) the number of bytes taken up by each function. Note that for all the functions that accept ints, the Scons version is always a bit larger than mine. I'm only guessing here - but is there a chance that this is down to 'int' sizes? Maybe my version's producing 16-bit ints whereas the Scons build is producing 32-bit (or maybe mine's producing 32-bit and Scons uses 64-bit, although that's unlikely). Another possibility is that mine's being compiled to use char-based strings whereas the Scons version maybe used Unicode strings.

Are there any settings within C:B to vary things like this? It's only a gut feeling but it feels very likely to me..!
Title: Re: SConstruct (Scons)
Post by: Mad Scientist on July 28, 2007, 04:00:22 pm
Ok from what I have seen I am going to guess you are using code blocks as your IDE and the msvc++ compiler that is shipped with your version of msvc++, as long as you only have one compiler installed though it wont make much difference.
I doubt it is different in terms of 16 bit or 32 bit as long as you are using the same compiler( scons will default to msvc unless told other wise or if it is not installed ) and havnt defined 16 bit. So I did notice though that you didn't define any build flags with scons except for some extra defines and that could be what is adding to the size as code blocks has some default flags set unless you change them. Example line( add after your first append ):
Code
st.Append( CCFLAGS = '-Ox' )
Title: Re: SConstruct (Scons)
Post by: johne53 on July 28, 2007, 06:41:37 pm
Thanks for the info. Actually, this is a Linux project and I'm using gcc compiler. Strictly speaking I think I should be using g++ compiler but C::B doesn't offer that as an option. If I specify gcc, will C::B use g++ compiler where appropriate? If not, that could be another reason for the differences.
Title: Re: SConstruct (Scons)
Post by: killerbot on July 28, 2007, 07:17:06 pm
gcc will use g++ where appropriate I think
Title: Re: SConstruct (Scons)
Post by: johne53 on July 28, 2007, 08:03:04 pm
I've had a good look at C::B but I can't see anything obvious for changing the target between 16 bit and 32 bit. I'm assuming that gcc defaults to 32 bit but it would be nice to know if there are any compiler flags for selecting between 16 bit, 32 bit or even 64 bit compilation.
Title: Re: SConstruct (Scons)
Post by: Auria on July 28, 2007, 10:08:51 pm
Strictly speaking I think I should be using g++ compiler but C::B doesn't offer that as an option. If I specify gcc, will C::B use g++ compiler where appropriate? If not, that could be another reason for the differences.

AFAIK the trick is more or less that GCC can have 2 meanings:

Gnu Compiler Collection
Gnu C Compiler

In the compiler dialog, GCC means the former, when you build a C program from terminal, GCC means the latter ;)
Title: Re: SConstruct (Scons)
Post by: Mad Scientist on July 29, 2007, 02:31:49 am
Quote
Actually, this is a Linux project and I'm using gcc compiler.
O ok cool, then you could use the options "-Wall -O3 -pipe" ( warnings all treated as errors, level 3 opts, and pipe data instead of files ) instead of the "-0x". Also note though that scons will default to the msvc compiler if it is installed and in the PATH env var.

As to 16 bit 32 bit and 64 bit builds, I don't know about msvc but with gcc I haven't seen it as an option. I believe it would be considered a cross-compile if you are on a 32 bit computer just as mingw32 is a cross compile on Linux. So you would need to get a compiler built for 16 bit, probably would be a define in the build but I dont know how it is done.
Title: Re: SConstruct (Scons)
Post by: johne53 on July 30, 2007, 05:33:45 pm
Today I decided to cheat and read the manual..!! I discovered that for my particular platform (x86) the g++ compiler can accept the optional parameters -m32 and -m64. So I'm assuming that in the absence of these it might default to 16-bit compilation. There's also an option called -mcmodel (which stands for "code model") but exactly what that is, doesn't seem to be explained anywhere.

If I wanted to experiment, how would I go about passing these parameters to the compiler from within Code::Blocks?
Title: Re: SConstruct (Scons)
Post by: oBFusCATed on July 31, 2007, 03:01:43 pm
So I'm assuming that in the absence of these it might default to 16-bit compilation.
You are totally wrong :)

The default value depends on the architecture the compiler was build for(x86 -> 32bits, amd64/x86_64 -> 64bits).

I think linux can't be built for a 16bit architecture. :)

To be sure what is happening try to make scons and C::B print the commands they are executing (eg: gcc .... ).
For scons I don't know how to do it, but for C::B there is options in options->compiler & debugger -> other -> full compiler output ( I'm not 100% sure that the menus are named that, no C::B in front of me).

Title: Re: SConstruct (Scons)
Post by: johne53 on August 04, 2007, 06:09:25 pm
This is slowly driving me nuts..! Here's the command that gets sent to g++ (by Scons) for compiling one of the relevant source files:-

Code
g++ -o libs/sigc++2/sigc++/connection.os -c -g -DARCH_X86 -msse -mfpmath=sse -DUSE_XMMINTRIN
-DBUILD_SSE_OPTIMIZATIONS -Wall -DHAVE_LIBLO -DENABLE_NLS -Woverloaded-virtual -fPIC -Ilibs/sigc++2 libs/sigc++2/sigc++/connection.cc

As you can see, this is to compile the Debug version of connection.cc. There's only one copy of connection.cc on my sysem. I opened up a terminal window and typed that exact same command (except with a different name for the target file). Then I compared the size of my 'manual' compile with the Scons compile. Both object files were absolutely the same size. Next I entered all those parameters into my C::B project, being very careful to ensure that all the preprocessor directives were the same and all the include folders were in the same order.

And yet, the C::B object file is a different size!?! In fact, all the object files come out at a different size. Mostly bigger though occasionally smaller.

I've even checked that I haven't inadvertantly got 2 versions of gcc/g++ on my system (which I haven't). So why on earth are the C::B modules not coming out at the right size?? Could C::B be re-ordering things? Or sending some additional parameters to the compiler that I don't know about?

Is there any way to view what C::B is sending to the compiler, so I can see if there's a difference?

[Edit...] Oops, oBFusCATed - I just noticed your last sentence. I'll try that now...!
Title: Re: SConstruct (Scons)
Post by: johne53 on August 04, 2007, 06:31:24 pm
Code
gcc -Wall -g -c -msse -mfpmath=sse -Woverloaded-virtual -fPIC -Ilibs/sigc++2 -DARCH_X86 -DUSE_XMMINTRIN -DBUILD_SSE_OPTIMIZATIONS -DHAVE_LIBLO -DENABLE_NLS
 -I/opt/gnome/lib/glib-2.0/include -I/media/SHAREDDATA/ardour2/libs/sigc++2 -I/media/SHAREDDATA/ardour2/libs/glibmm2 -I/opt/gnome/include/glib-2.0
-I/media/SHAREDDATA/ardour2/libs/pbd -I/usr/include/libxml2 -I/usr/include -I/media/SHAREDDATA/ardour2/libs
-c /media/SHAREDDATA/ardour2/libs/sigc++2/sigc++/connection.cc -o obj/Debug/sigc++/connection.o

Well, there's one difference immediately obvious.... it's using the wrong compiler!! C::B is compiling ".cc" files, using gcc, whereas Scons is using g++.

Any way to force C::B to use g++ ? It doesn't seem to appear in my list of compiler options.
Title: Re: SConstruct (Scons)
Post by: Ceniza on August 04, 2007, 08:19:19 pm
Suggesting to modify line 561 of cbproject.cpp would do it :wink:

Code
    if (ext.IsSameAs(FileFilters::C_EXT) || ext.IsSameAs(FileFilters::CC_EXT))
        f->compilerVar = _T("CC");

I haven't actually tried it, but I think that's the right place to fix it in Code::Blocks, and I do think it should be changed. .cc is supposed to be a C++ extension.

In the meanwhile, right click your source file in the Projects tab, click on Properties, go to Advanced and change "Compiler variable:" to "CPP".
Title: Re: SConstruct (Scons)
Post by: johne53 on August 04, 2007, 08:34:45 pm
Thanks for those suggestions. The second one won't be practical because there are literally thousands of files with the CC extension!! I might try the first one though. The only problem is that I don't have a file called cbproject.cpp. I do have its header file but not the source file. Is it possible that I just installed C::B in binary form? If so, I'll need to download the full source code.
Title: Re: SConstruct (Scons)
Post by: Biplab on August 04, 2007, 09:17:24 pm
Thanks for those suggestions. The second one won't be practical because there are literally thousands of files with the CC extension!! I might try the first one though. The only problem is that I don't have a file called cbproject.cpp. I do have its header file but not the source file. Is it possible that I just installed C::B in binary form? If so, I'll need to download the full source code.

Please wait for the next nightly. C::B will now handle it automatically. :)

Thanks Ceniza for the solution.
Title: Re: SConstruct (Scons)
Post by: johne53 on August 04, 2007, 11:09:26 pm
Thanks to you both.
Title: Re: SConstruct (Scons)
Post by: Ceniza on August 04, 2007, 11:37:43 pm
I see you committed that change. I didn't want to do it because Don Corleone wasn't around to ask him. After all, that plugin is one of his "babies" :wink:

Let's hope the Don agree with that change :)
Title: Re: SConstruct (Scons)
Post by: johne53 on August 08, 2007, 04:19:15 pm
To be sure what is happening try to make scons and C::B print the commands they are executing (eg: gcc .... ).
For scons I don't know how to do it, but for C::B there is options in options->compiler & debugger -> other -> full compiler output ( I'm not 100% sure that the menus are named that, no C::B in front of me).

I don't understand.... since I updated to the latest version (today) I seem to have lost the ability to select 'full compiler output'. I remember it being quite simple to find but I've now been searching for about half an hour and I can't find that setting any more. Can someone please remind me how to get to it?

[Edit...] It's okay, I found it - but to my dismay, C::B is still calling the gcc compiler for a ".cc" file! I'm running the build from 5th August, svn 4349. Will the change only happen for new projects or should it have worked for an existing project? I don't want to have to change that 'Advanced' setting for literally thousands of source files....
Title: Re: SConstruct (Scons)
Post by: Biplab on August 08, 2007, 05:11:35 pm
I see you committed that change. I didn't want to do it because Don Corleone wasn't around to ask him. After all, that plugin is one of his "babies" :wink:

Let's hope the Don agree with that change :)

I hope so. But gcc manual says .cc belongs to C++. So I don't see any harm with this change. ;)
Title: Re: SConstruct (Scons)
Post by: johne53 on August 09, 2007, 07:42:37 am
I see you committed that change. I didn't want to do it because Don Corleone wasn't around to ask him. After all, that plugin is one of his "babies" :wink:

Let's hope the Don agree with that change :)

From simple experimentation, I don't think that the change is working properly (although I guess that depends on how you define "properly").

As far as I can tell, if I add some new ".cc" files to a project, they'll now have their 'Compiler Variable' set to CPP (this can be found in the Advanced Settings dialog for each source file). This causes them to get compiled correctly, using the g++ compiler (although it could be argued that that's just a happy accident). However, pre-existing files still retain their old setting of CC - which, from the behaviour that I'm observing, is still being compiled using the wrong compiler. In effect, the compiler used for ".cc" files will depend on the age of the project - not on the ".cc" extension. Can anyone confirm/deny/comment on whether or not that was the expected behaviour?