Feature request: $<REMOVE_DUPLICATES:list> generator expression
Since generator expressions are not evaluated until generation time, their output cannot be processed with traditional CMake commands like string(), list(), foreach() etc. (Maybe that motivated constructs like $<JOIN:list,...>
.) One useful feature in this context would be the functionality of list(REMOVE_DUPLICATES ...)
. Here's an example of a use case:
In a complex project, an expression like this
-I$<JOIN:$<TARGET_PROPERTY:foo,INCLUDE_DIRECTORIES>,;-I>
frequently returns multiple items referencing the same directory. While such duplicates do not usually cause failures, e.g. when being passed to an external command, they certainly may cause performance degradation. In one of my applications, I get no less than 12 duplicates of the same directory form the above. This means that an external command given the above include path spec will scan the same include directory (containing close to 1600 files) 12 times in some cases.
What would help here would be a generator expression like $<REMOVE_DUPLICATES:list>
, which would do the exact same thing as list(REMOVE_DUPLICATES ...)
does with configure-time lists. The above expression would then become
-I$<JOIN:$<REMOVE_DUPLICATES:$<TARGET_PROPERTY:foo,INCLUDE_DIRECTORIES>>,;-I>
Could that be implemented?
Maybe this example illustrates a larger problem. While the traditional CMake language is well equipped to handle the configuration phase, it is not applicable to the generation phase. To make this second phase programmable, CMake is in essence being retrofitted with these generator expressions. They effectively represent a new language, which is more compact but unfortunately much harder to read, hard to debug, and much less feature-rich at the moment than the original language. In a way, it reminds me of Make functions like $(addprefix ..., ...)
which also may end up nested to several levels and become hard to read. I'm not sure how well this will scale and/or what to do about it except to keep adding missing functionality.