What are generator expressions?
CMake is building the solution in three stages: configuration, generation, and running the build tool. Generally, all the required data is available during the configuration stage. However, occasionally, we encounter a situation similar to the "chicken and the egg" paradox. Take an example from Chapter 5, Working with Targets, section Using a custom command as a target hook – where a target needs to know the path of a binary artifact of another target. Unfortunately, this information becomes available only after all the list files are parsed and the configuration stage is complete.
So how do we tackle such a problem? One solution could be to create a placeholder for the information and delay its evaluation until the next stage – the generation stage.
This is precisely what generator expressions (also referred to as 'genexes') do. They are built around target properties such as LINK_LIBRARIES
, INCLUDE_DIRECTORIES
, COMPILE_DEFINITIONS...