I don't know how to setup different configurations (defines) for Windows resouce compiler library.

I have a (Windows visual studio) resource dll (containing just rc files) that I want to build with two different configurations with different preprocessor flags. I have not been able to figure out how to set the flags differently for the two different configurations.

Here is the code I have

set(rc_files dg3500.rc mn3500.rc st3500.rc)

function(add_3500_dll name defines)
    add_library(${name} SHARED dg3500.rc mn3500.rc st3500.rc)
endfunction(add_3500_dll name defines)


add_3500_dll(3500 "MIC_3500")
add_3500_dll(confrim "MIC_3500;MIC_CONFIRM;MIC_PHYSI_ONLY")

I’m not sure what to add to set the defines inside the add_3500_dll function.

I have tried to set(CMAKE_RC_FLAGS “${defines}”), but this only remembers the last set (as expected).

I tried to use the set_target_properties(), but I was not able to find the property that would have an effect.

I thought about tracking down how the macros are expanded, but I did not have any idea of how to get started.

You can use target_compile_definitions(${name} PRIVATE $<$<CONFIG:Debug>:debug_only_definition>), though it seems you’re talking about build configs, not build types, so target_compile_definitions(${name} PRIVATE ${defines}) is probably sufficient.

I had tried this, but that does not appear to work. I made a simple example project of just the two files below. The reason I believe the defines are not sent the resource compiler are:

  1. When it is run, I get an error on the “#error Undefined flavor” line indicating that MIC_3500 is not defined.
  2. When I open the vcmfc.sln project in visual studio and look at the properties for the 3500 (and confirm) library, the command line for the Resouce command line is:
    /D “WIN32” /D “_DEBUG” /D “CMAKE_INTDIR=\“Debug\”” /D “_3500_EXPORTS” /l 0x0409 /nologo /fo"3500.dir\Debug%(Filename).res"
    Which does not include the defines.

CMakeLists.txt:

cmake_minimum_required(VERSION 3.14)
project(vcmfc VERSION 0.1.0)

function(add_3500_dll name defines)
add_library(${name} SHARED versiondll.rc)
target_compile_definitions(${name} PRIVATE ${defines})
endfunction(add_3500_dll name defines)

add_3500_dll(3500 "MIC_3500")
add_3500_dll(confrim "MIC_3500;MIC_CONFIRM;MIC_PHYSI_ONLY")

versiondll.rc:

#include "afxres.h"

#define MIC_COMPANY_NAME "Micromeritics Instrument Corporation"
#define MIC_TRADEMARK "Micromeritics ® is a registered trademark of Micromeritics Instrument Corporation."
#define MIC_COPYRIGHT "Copyright © Micromeritics Instrument Corp. 2020"
#define MIC_FILE_VERSION "6.0.0.0"
#define MIC_PRODUCT_VERSION "Version 6.00"
#define MIC_MAJOR 6
#define MIC_MINOR 0
#define MIC_BUILD 0
#define MIC_REVISION 0
#define MIC_APPICON "3flex.ico"

#if defined(MIC_3500) && defined(MIC_CONFIRM)
#define MIC_PRODUCT_NAME "Confirm for Flex"
#define MIC_FILE_NAME "3500"
#elif defined(MIC_3500)
#define MIC_PRODUCT_NAME "Flex"
#define MIC_FILE_NAME "3500"
#else
#error Undefined flavor.
#endif

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32

VS_VERSION_INFO VERSIONINFO
FILEVERSION MIC_MAJOR,MIC_MINOR,MIC_BUILD,MIC_REVISION
PRODUCTVERSION MIC_MAJOR,MIC_MINOR,MIC_BUILD,MIC_REVISION
FILEFLAGSMASK 0x17L
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x2L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", MIC_COMPANY_NAME
VALUE "FileDescription", MIC_PRODUCT_NAME " English Resource DLL"
VALUE "FileVersion", MIC_FILE_VERSION
VALUE "InternalName", MIC_PRODUCT_NAME " ENU"
VALUE "LegalCopyright", MIC_COPYRIGHT
VALUE "LegalTrademarks", MIC_TRADEMARK
VALUE "OriginalFilename", MIC_FILE_NAME "ENU.dll"
VALUE "ProductName", MIC_PRODUCT_NAME
VALUE "ProductVersion", MIC_PRODUCT_VERSION
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END

#endif // English (U.S.) resources

What happens if you add a “dummy” C source file to the target? Does it get those /D flags?

Yes, when I add a dummy c++ file, the defines are part of the compile command. The command line for the c/c++ from the solution is: /GS /analyze- /W3 /Zc:wchar_t /Zi /Gm- /Od /Ob0 /Fd"3500.dir\Debug\vc140.pdb" /Zc:inline /fp:precise /D “_WINDLL” /D “_MBCS” /D “WIN32” /D “_WINDOWS” /D “MIC_3500” /D “CMAKE_INTDIR=“Debug”” /D “_3500_EXPORTS” /errorReport:prompt /WX- /Zc:forScope /RTC1 /GR /Gd /Oy- /MDd /Fa"3500.dir\Debug" /EHsc /nologo /Fo"3500.dir\Debug" /Fp"3500.dir\Debug\3500.pch"

The command line for the rc file now also includes the required defines. The command line from the visual studio solution is: /D “WIN32” /D “_DEBUG” /D “_WINDOWS” /D “MIC_3500” /D “CMAKE_INTDIR=\“Debug\”” /D “_3500_EXPORTS” /l 0x0409 /nologo /fo"3500.dir\Debug\versiondll.res"

I verified (back and forth) adding and removing the test.cpp from the add_library() command adds and removes the target_compile_definitions() from the resource compiler command.

While it does not sound like that should be the expected behaviour, it does get me what I need to move forward.

Thank you.