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

**URL:** https://discourse.cmake.org/t/i-dont-know-how-to-setup-different-configurations-defines-for-windows-resouce-compiler-library/4413
**Category:** Usage
**Tags:** os:windows
**Created:** [November 3, 2021, 1:47pm UTC](https://discourse.cmake.org/t/i-dont-know-how-to-setup-different-configurations-defines-for-windows-resouce-compiler-library/4413 "2021-11-03T13:47:10Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Stefan\_Koch](https://discourse.cmake.org/user_avatar/discourse.cmake.org/stefan_koch/32/1932_2.png) [@Stefan\_Koch](https://discourse.cmake.org/u/Stefan_Koch)
#### Post date: [November 3, 2021, 1:47pm UTC](https://discourse.cmake.org/t/i-dont-know-how-to-setup-different-configurations-defines-for-windows-resouce-compiler-library/4413/1 "2021-11-03T13:47:10Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [November 3, 2021, 4:05pm UTC](https://discourse.cmake.org/t/i-dont-know-how-to-setup-different-configurations-defines-for-windows-resouce-compiler-library/4413/2 "2021-11-03T16:05:35Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Stefan\_Koch](https://discourse.cmake.org/user_avatar/discourse.cmake.org/stefan_koch/32/1932_2.png) [@Stefan\_Koch](https://discourse.cmake.org/u/Stefan_Koch)
#### Post date: [November 3, 2021, 4:54pm UTC](https://discourse.cmake.org/t/i-dont-know-how-to-setup-different-configurations-defines-for-windows-resouce-compiler-library/4413/3 "2021-11-03T16:54:56Z")

</div>

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
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:

```auto
﻿#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

```

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [November 4, 2021, 11:05am UTC](https://discourse.cmake.org/t/i-dont-know-how-to-setup-different-configurations-defines-for-windows-resouce-compiler-library/4413/4 "2021-11-04T11:05:05Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Stefan\_Koch](https://discourse.cmake.org/user_avatar/discourse.cmake.org/stefan_koch/32/1932_2.png) [@Stefan\_Koch](https://discourse.cmake.org/u/Stefan_Koch)
#### Post date: [November 4, 2021, 2:11pm UTC](https://discourse.cmake.org/t/i-dont-know-how-to-setup-different-configurations-defines-for-windows-resouce-compiler-library/4413/5 "2021-11-04T14:11:50Z")

</div>

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.
