Author Topic: Sending defines to windres  (Read 7986 times)

Offline XayC

  • Multiple posting newcomer
  • *
  • Posts: 94
Sending defines to windres
« on: September 02, 2007, 05:21:45 pm »
Hello, is there any way to use the defines (set in "Compiler options" -> "#defines") also for the resource files?

Currently those values are correctly defined in every source file, but not in the resource files. Windres supports it (using -D) but seems that the default command line used to call it it's not, and i could not find any easy way to get the project defines (which are target dependent) as a command macro.

The reason is that i need to define specific resources based on the presence of the DEBUG define, which is defined in my project only for some targets.

Regards, XayC.

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Sending defines to windres
« Reply #1 on: September 03, 2007, 05:07:34 am »
This is not possible at the moment. But we'll be upgrading the compiler system in future and we'll add it then. :)
Be a part of the solution, not a part of the problem.

Offline jmason1182

  • Single posting newcomer
  • *
  • Posts: 7
Re: Sending defines to windres
« Reply #2 on: May 07, 2008, 11:24:22 pm »
Wow... that should be a priority.... you have the auto_version plugin which keeps up your version.h file... but now way to add any #ifndef type statements to test if you are debugging or not?

I use #ifdef __MY_DEBUG__ to determine if I'll use the version.h auto-updated by the plugin, or if I'll use a static static_version.h which has some debug info, warning messages, etc. Also, my resources are a little different. I just switched my project (going on... sadly... for 2 years so far) to a Code::Blocks project and I love it. It's just hard to keep track of what version/debug/release/etc. I am working on when I have to MANUALLY go add -D __MY_DEBUG__ to a CUSTOM command to EACH resource file just to get a define to the windres program.


So when is this gonna be fixed?

Offline JGM

  • Lives here!
  • ****
  • Posts: 518
  • Got to practice :)
Re: Sending defines to windres
« Reply #3 on: May 08, 2008, 07:08:43 am »
do I need to change something on the autoversioning plugin? I don't get it quite well :?

Offline jmason1182

  • Single posting newcomer
  • *
  • Posts: 7
Re: Sending defines to windres
« Reply #4 on: May 08, 2008, 02:41:20 pm »
do I need to change something on the autoversioning plugin? I don't get it quite well :?

I'm not sure what you mean.... the autoversioning plugin works great. I needed to setup an rc file so I could have version info for my executable so I did the following:

Code
///////////////////////////////////////////////////////////////////////
//
// Version
//

#ifdef __MY_DEBUG__
#include "static_version.h"
#define RC_COMMENTS_STRING "This executable is a debug release. Not intended for non-developmental use.\0"
#define RC_INTERNAL_NAME_STRING "my_debug\0"
#define RC_ORIGINAL_FILE_NAME_STRING "MY_debug.EXE\0"
#define RC_PRODUCT_NAME_STRING "MY_DEBUG\0"
#define RC_DESCRIPTION_STRING "DEBUG VERSION: My Program name\0"
#define RC_COMPANY_STRING "Debug Version: My Name Here\0"
#define RC_COPYRIGHT_STRING "Debug Copyright (C) 2008. All Rights Reserved.\0"
#else
#include "version.h"
#define RC_COMMENTS_STRING "For licensed-commercial use only. Unlicensed use is unlawful.\0"
#define RC_INTERNAL_NAME_STRING "MY\0"
#define RC_ORIGINAL_FILE_NAME_STRING "MY.EXE\0"
#define RC_PRODUCT_NAME_STRING "MY\0"
#define RC_DESCRIPTION_STRING "My Program Here\0"
#define RC_COMPANY_STRING "My Name Here\0"
#define RC_COPYRIGHT_STRING "Copyright (C) 2008. All Rights Reserved.\0"
#endif

VS_VERSION_INFO VERSIONINFO
 FILEVERSION RC_FILEVERSION
 PRODUCTVERSION RC_FILEVERSION
 FILEFLAGSMASK 0x3fL
#ifdef __MY_DEBUG__
 FILEFLAGS 0x1L
#else
 FILEFLAGS 0x0L
#endif
 FILEOS 0x4L
 FILETYPE 0x1L
 FILESUBTYPE 0x0L
BEGIN
    BLOCK "StringFileInfo"
    BEGIN
        BLOCK "040904b0"
        BEGIN
            VALUE "Comments", RC_COMMENTS_STRING
            VALUE "CompanyName", RC_COMPANY_STRING
            VALUE "FileDescription", RC_DESCRIPTION_STRING
            VALUE "FileVersion", RC_FILEVERSION_STRING
            VALUE "InternalName", RC_INTERNAL_NAME_STRING
            VALUE "LegalCopyright", RC_COPYRIGHT_STRING
            VALUE "OriginalFilename", RC_ORIGINAL_FILE_NAME_STRING
            VALUE "ProductName", RC_PRODUCT_NAME_STRING
            VALUE "ProductVersion", RC_FILEVERSION_STRING
        END
    END
    BLOCK "VarFileInfo"
    BEGIN
        VALUE "Translation", 0x409, 1200
    END
END


And then I have the version.h that is created by auto-version and use it for the RC_FILEVERSION_STRING when I'm not debugging. BUT when I AM debugging, I use a static-copy of version.h so that other dependencies in other parts of the program can easily recognize that we are debugging.

So no, the auto-versioning plugin is great. My problem is exactly how I'm using this. It depends on a "user-defined" symbol... __MY_DEBUG__ and currently code::blocks doesn't pass any compiler defines to windres... thus windres NEVER sees __MY_DEBUG__ as defined. So it always uses the version.h and not static_version.h.

This is why I need a way to pass options to windres from the IDE. Otherwise i have to figure out how to get a custom build command scripted to detect the target as either Debug or not Debug and then pass the option (-D __MY_DEBUG__) to windres or not.

Hope this helps give reasoning to why I need to be able to send options (defines especially) to the resource compiler. And again, no the auto-versioning plugin is (arguably) perfect.

Offline jmason1182

  • Single posting newcomer
  • *
  • Posts: 7
Re: Sending defines to windres
« Reply #5 on: May 08, 2008, 02:55:10 pm »
OK, here's a temporary workaround.

Luckily, I don't have to deal with .rc files too much as I'm a little... maybe old-school isn't the world.... perhaps anal is more like it.... I just use c++ and C for everything.... meaning I have a harder time testing and getting my resources worked out, but then my rc files stay simple. Just a few icons perhaps and of course, version info.

Thus, you'll have to open the properties of EACH rc file, go the the Advanced tab, and check "Use Custom Command to build this file:"

Then, in the command box, enter the following:
Code
$rescomp [[  if(GetProjectManager().GetActiveProject().GetActiveBuildTarget().Matches(_T("Debug"))) {print(_T("-D __MY_DEBUG__ -v --use-temp-file"));} ]]  -i $file -J rc -o $resource_output -O coff $res_includes

And of course, you will have to substitute the _T("Debug") with whatever your debugging target name is, AND the _T("-D __MY_DEBUG__") with the symbols that you want to define.
If you have more than one target to debug, then do it like this:
Code
$rescomp [[  if(GetProjectManager().GetActiveProject().GetActiveBuildTarget().Matches(_T("Debug")) || GetProjectManager().GetActiveProject().GetActiveBuildTarget().Matches(_T("Debug2"))) {print(_T("-D __MY_DEBUG__ -v --use-temp-file"));} ]]  -i $file -J rc -o $resource_output -O coff $res_includes

(I think the Logical OR works... || ?? Anyone? )

Anyway, with this I did NOT get it to work... until I went into the obj directory and manually looked at the resulting .res files. Then I found my versioninfo was right for one .rc file... but I didn't do the above trick on ALL my rc files. THUS, if I were you, I would just do it to ALL of them. Then it should work. (My_APP.rc has a #include VersionInfo.rc and so I just did the above trick for VersionInfo.rc. BUT, since I didn't do it for My_App.rc the executable still had wrong info in it. Thus, you need to just do this custom command for all .rc files and viola. You should have it.)