Difference between revisions of "Build scripts"

From Code::Blocks
(base is a keyword in squirrel, so we need a other name for the parameter)
 
Line 9: Line 9:
 
  // file: build_debug_symbols.script
 
  // file: build_debug_symbols.script
 
   
 
   
  function SetBuildOptions(base)
+
  function SetBuildOptions(cbase)
 
  {
 
  {
 
     // enable debugging symbols
 
     // enable debugging symbols
     base.AddCompilerOption(_T("-g"));
+
     cbase.AddCompilerOption(_T("-g"));
 
     // disable all optimizations
 
     // disable all optimizations
     base.AddCompilerOption(_T("-O0"));
+
     cbase.AddCompilerOption(_T("-O0"));
 
  }  
 
  }  
  
The "base" parameter in this function is a CompiletargetBase instance. SetBuildOptions(base) is called before the project/target is built. Each build script ''must define this function'', even if it is not needed (in which case you can leave it with an empty body).
+
The "cbase" parameter in this function is a CompiletargetBase instance. SetBuildOptions(cbase) is called before the project/target is built. Each build script ''must define this function'', even if it is not needed (in which case you can leave it with an empty body).
  
 
This specific script enables the generation of debugging symbols for the build target it is attached to. You could similarly have other build scripts for different configuration sets like optimizations, architecture, C++ options, C++ standards, etc.
 
This specific script enables the generation of debugging symbols for the build target it is attached to. You could similarly have other build scripts for different configuration sets like optimizations, architecture, C++ options, C++ standards, etc.

Latest revision as of 07:34, 18 January 2022


Build scripts can help configuring build options and reusing these configurations.

What you need to do is create as many build scripts are needed and attach them to projects or build targets.

Let's see an example build script for the GNU GCC compiler:

// file: build_debug_symbols.script

function SetBuildOptions(cbase)
{
    // enable debugging symbols
    cbase.AddCompilerOption(_T("-g"));
    // disable all optimizations
    cbase.AddCompilerOption(_T("-O0"));
} 

The "cbase" parameter in this function is a CompiletargetBase instance. SetBuildOptions(cbase) is called before the project/target is built. Each build script must define this function, even if it is not needed (in which case you can leave it with an empty body).

This specific script enables the generation of debugging symbols for the build target it is attached to. You could similarly have other build scripts for different configuration sets like optimizations, architecture, C++ options, C++ standards, etc.

Great. Now you have created your own set of build scripts. How do you attach them to project/targets? Simple: "Project->Properties->Scripts". Select the project or target to attach a script to and click "Add". If you want to detach a script, click "Remove". You can also change the order scripts are ran with the two little arrows on the right side. Finally, you can press "Validate all scripts" to make sure that the attached build scripts are valid.

If you choose to go the build scripts way for your project, please don't use the project build options dialog (unless maybe for global project settings). If you do, things may not work as expected and you will unrightfully blame Code::Blocks for this ;).

Well, that's all there is to it!

NOTE: I 've been told that this is like MS Visual Studio's "properties". I wouldn't know since I don't use it myself. But maybe this similarity (if it really exists) helps you grasp the concept better.


See also