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:
When it is run, I get an error on the “#error Undefined flavor” line indicating that MIC_3500 is not defined.
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")
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.