Aggregating Build Information across the entire configure step

We have multiple different ways this arises, but one example is that we don’t use ctest. Instead, we have an in-house testing framework that serves a similar purpose. Our list files specify test executables via a custom function my_add_test_executable(<NAME> <PARAM1> <PARAM2> ...). We then have a top-level program which needs to be able to know about every test executable, as well as the parameters that each call to my_add_test_executable() was invoked with.

So we need to be able to keep track of this over the life of the configure step, and then at the end, output a single manifest / configuration file that contains information about each test executable and all of the parameters the function was called with.

Is there a good pattern / recipe for this kind of thing? I’ve considered using a global property, but this is cumbersome to parse because it’s a list of lists, and cmake doesn’t make dealing with multi-dimensional lists easy.

Is there an easier way?

I usually do this by making ad hoc associative properties. Something like:

set_property(GLOBAL APPEND
  PROPERTY my_test_harness_names "${test_name}")
  PROPERTY "my_test_harness_${test_name}_command" "${command_args}")
  PROPERTY "my_test_harness_${test_name}_workdir" "${working_directory}")

This avoids the “list of lists” problem at least.

How do you enumerate all of these properties though? Let’s say you have not just my_test_harness, but also my_second_test_harness and my_fancy_test_harness. I don’t know of a good way to enumerate all global properties in CMake, so you’d have to know in advance what all the different test harnesses were and then set properties as set_property(GLOBAL PROPERTY "${harness_name}_${test_name}_command") etc.

I guess you could keep a second global property which is a list of harness names. Does this sound idiomatic?

It sounds suitable to me. I’m not sure there’s an “idiomatic” answer to this right now (other than using part of the variable/property name to store associative data in some way).