Search code examples
ccodeblocks

Compiling Options in Code Blocks


I want to to be able to enter the options in Code Blocks. Like I want to do gcc -P test.c. How should I go about doing this? Basically, I want Code Blocks to give a prompt box each time I compile so that I can enter the options in that box. Is that functionality available in Code Blocks?


Solution

  • The behaviour that you want in your updated answer is not available in Code::Blocks.

    However, you should be able to get this behaviour if you invest the time to write a plugin for that (should be under an hour, depening on your wxWidgets skill, the GUI bit to pop up the dialog will probably be the hardest thing).

    Either write a script plugin (this is allegedly the easiest and quickest way, though I've never done that, so cannot tell for sure) -- look at share/codeblocks/scripts/sample_plugin.script, and see if you can adapt that -- or write a proper plugin in C++.
    Edit: some sparse docs on script plugin.

    Look for example at src/plugins/autosave/autosave.[h|cpp] (which is one of the most primitive plugins) to learn how this is done. Something like this should work:

    • Derive a class from cbPlugin, implement all the pure virtuals as {} (don't need them)
    • Put a namespace { PluginRegistrant<YourClassName> reg(_T("Readable Plugin Name")); } into your source file
    • Register for EVT_COMMAND(cbEVT_COMPILER_STARTED...) inside your BEGIN_EVENT_TABLE/END_EVENT_TABLE block.
    • In your event handler, pop up the dialog, read out the textbox, and modify any settings you want. Either modify the compiler's settings, or use the pointer to the project contained in the the event, which lets you access project settings and targets with their own settings
    • You probably want to undo your changes, too. So do the same for cbEVT_COMPILER_FINISHED, restoring the original settings

    Alternatively, one could probably just call cbProject::ShowOptions() (after all, the event gives you a pointer to a cbProject, so why not just use that) when cbEVT_COMPILER_STARTED is received, that should bring up the builtin options dialog.