For our build machines, I want to have conditional pre-processor defines in my project based on environment variables at the time of compilation. the environment string is "MY_CUSTOM_BUILD", and based on its value, I'd like to add defines.
My project file has something like:
_MY_CUSTOM_BUILD = $$(MY_CUSTOM_BUILD)
eval(_MY_CUSTOM_BUILD = $$"AAA") {
DEFINES+= MY_CUSTOM_BUILD_AAA
}
eval(_MY_CUSTOM_BUILD = $$"BBB") {
DEFINES+= MY_CUSTOM_BUILD_BBB
}
However, in the code, it seems that "MY_CUSTOM_BUILD_AAA" and "MY_CUSTOM_BUILD_BBB" are ALWAYS defined regardless of whether the environment string exists, or its value.
#ifdef MY_CUSTOM_BUILD_AAA
Blah(); <--- this code always compiles regardless.
#endif
#ifdef MY_CUSTOM_BUILD_BBB
Blah2(); <--- this code always compiles regardless.
#endif
Am I doing something wrong with the syntax?
So, yes. what I ended up doing was this:
contains(_MY_CUSTOM_BUILD, "AAA") {
DEFINES+= MY_CUSTOM_BUILD_AAA
}
instead of that:
eval(_MY_CUSTOM_BUILD = $$"AAA") {
DEFINES+= MY_CUSTOM_BUILD_AAA
}
and it worked.