I have read the docs for executables, but I do not really understand when I should use imported executables or aliases.
This is the link that I was reading. But maybe I am missing the practical experience, or I am not good enough in english to understand it.
I hope you could explain it to me. I am trying to improve my CMake code and write a generator to give me a clean starting point for a project.
As I understood, imported executables could be used to make custom commands more readable, but how could that improve readability?
And as I understand alias could be used to give a shorter name to a target so your code could be more readable if many operations are performed on a target.
But I don’t understand when it makes sense to use these things and how to use them.
I could simply get some examples from google, but that would not explain why and when to use them.
And feel free to tell me, if my questions are stupid.
You can do
$<TARGET_FILE:SomePkg::Executable> in the command instead of providing a variable with the path (CMake will make this relocatable while a variable generally needs manual logic).
ALIAS targets are more useful to make the name of the target when exported available within the build as well. Basically, it lets you have one name for a target no matter where it is.
That is nice. Could someone point me to some usage example for that? I tried using it in a test, but was unable to get it working. Maybe some resources about generator expressions wold be good too, I might simply keep messing up the generator expressions.
Sounds usefull. I might still need an example at a later point, but I think i get it atm.
The other useful property of alias targets is that they’re not modifiable or installable – they’re basically const aliases. So it’s useful to always reference an alias when you’re linking to targets defined in one place from other places in your code, because you cannot accidentally change anything about the underlying target being aliased.