Search code examples
codeblockswxwidgets

Does Code::Blocks have a #define for its own version?


I created a new project for wxWidgets in Code::Blocks and noticed that in the generated "about" window a "define" is used to show the wxWidgets version (wxVERSION_STRING).

I would like to show more information in the about window, including the version of C::B

Does C::B have a define to show its version?

One way to show the version of C::B from the linux command line:

codeblocks --script="nothing" 2>/dev/null | gawk -F'Code::Blocks ' '{ print $2 }' | gawk -F'- wx' '{ print $1 }'

The --script="nothing" option prevents C::B to start another instance.


Solution

  • It looks like the Code::Blocks IDE doesn't provide the string constant you wanted, however it's easy to define this constant manually as a macro, and the IDE will automatically add this macro to all files it compiles.

    BTW, if to run the codeblocks executable from the command line it'll output its version - however, I couldn't find this string in the Code::Blocks binary or configuration files - probably it's obfuscated.

    hekto@ubuntu:~$ codeblocks
    Starting Code::Blocks Release 20.03  rev 11997 2020-04-18, 19:47:24 - wx3.0.4 - gcc 9.3.0 (Linux, unicode) - 64 bit
    

    In order to define a macro CB_VERSION with value, equal to this string, you can open the Global compiler settings window, choose the #defines pane and enter this macro manually:

    GlobalCompilerSettings

    Please note the "\\\" string in the beginning and the \\\"" string at the end of the macro value - without them the C++ preprocessor won't be able to pass the value of this macro into the C++ source code. So, the program below, compiled and linked inside the IDE, will output the value of the CB_VERSION macro.

    #include <iostream>
    
    int main()
    {
      const char* ver = CB_VERSION;
      std::cout << ver << std::endl;
    }
    

    UPDATE. Another way to get information about your current Code::Blocks IDE is to look at the XML file ~/.config/codeblocks/default.conf. This file contains a comment, which describes how and when the product has been built:

    <!-- application info:
     svn_revision:  11997
     build_date:    2020-04-18, 19:47:24
     compiler_version:  gcc 9.3.0
     Linux Unicode
    -->
    

    Also the XML node VERSION in this file stores the official product version and release number:

    <VERSION>
        <str>
            <![CDATA[20.03-r11997]]>
        </str>
    </VERSION>
    

    However, in order to extract these pieces of information you need to write some script and call it before the compilation - it's not easy. So, defining a macro with version information still looks better.