Build scripts

From CodeBlocks
Jump to: navigation, search

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(base)
    // enable debugging symbols
    // disable all optimizations

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).

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