Yeah, you’ll need to inject variable settings into the install step somehow. I have written a set of set() calls to a file then added an inclusion of that file via install(CODE) to work around this before.
src dir: /tmp/test/extern/foo
this src dir: /tmp/test/extern/foo
that src dir: /tmp/test/build/extern/foo-prefix/src/foo-build
why is this? The first 2 commands know about my source dir but the last one does not. It looks like source dir is equal to binary dir in the last command.
Note that you may not want (and/or need) to pass directory paths in to the install script. If you’re doing it because you need to reference, say, the location of a build file, you may be able to reference it via a generator expression like $<TARGET_FILE:output_target>, $<TARGET_OBJECTS:object_target>, or $<TARGET_PROPERTY:imported_target,LOCATION>1 — and another bonus, those can be used inside [[]] blocks. Unlike variable references, generator expressions are always expanded.
Notes
With that last one, unless the target was imported in the current scope you might have to resort to passing in a variable: