Skip to content

How to convert source_set.add(when) into if statement? Doc is unclear #11140

Answered by dcbaker
hehaoqian asked this question in Q&A
Discussion options

You must be logged in to vote

Those values are resolved when source_set.apply() is called, but are stored as strings until that time.

The basic opration is something like this:

conf = configuration_data()
conf.set('FOO_TRUE', true)
conf.set('FOO_FALSE', false)

s = source_set()
s.add(when : 'FOO_TRUE', files: files('true.c'))
s.add(when : 'FOO_FALSE', files : files('false.c'))

sources = s.apply(conf).sources()
assert(sources == files('true.c')

So if you want to change that into a conditional inline, you need to have whichever configuration_data that will be passed to apply:

conf = configuration_data()
conf.set('FOO_TRUE', true)
conf.set('FOO_FALSE', false)

if conf.get('FOO_TRUE')
  ...
endif

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by hehaoqian
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants