Hello experts,
I'm working on a GN project(
https://git.trustedfirmware.org/hafnium/hafnium.git/), mostly a C project, and i'm trying to find out how i can do the following. I've tried using gn help and looking through the gn referece docs but could not really find the answer.
I have target, that is a template, that eventually compiles into an executable. The target has the 'deps' field which contain only source_set's containing C files. Each source_set has its own public_config that includes extra defines and flags as required by the source set. What i want to be able to do is to use the same source_sets and create two different target executables, that only differ in a few flags. For example, i want target1 to have -DFOO and target2 to not have -DFOO. If i add a config at the target level, it only applies while linking but not to all the source_set's that the target depends on, ie. all the C files in both target1 and target2 dont compile with -DFOO. I have an example with comments:
config("myconfig_a") {
defines = ["DEFINESFOR_A"]
}
config("myconfig_b") {
defines = ["DEFINESFOR_B"]
}
config("myconfig_target1") {
defines = ["FOO"]
}
source_set("src_a") {
public_configs = [":myconfig_a"]
sources = ["a.c"]
}
source_set("src_b") {
public_configs = [":myconfig_a"]
sources = ["a.c"]
}
template("my_target") {
executables(target_name) {
forward_variables_from(invoker, [cflags, cflags_c, defines,public_configs, sources])
}
}
my_target("target1") {
public_configs = [":myconfig_target1"]
# I want c files in src_a and src_b to also include myconfig_target1 defines
# THIS DOES NOT WORK AS I WANT IT TO
deps= [
":src_a",
":src_b"
]
}
my_target("target2") {
# I want c files in src_a and src_b to NOT include myconfig_target1 defines
# THIS WORKS AS EXPECTED
deps= [
":src_a",
":src_b"
]
}
Thanks
Raghu