install(SCRIPT) always treats a genex file name as a relative path
In other parts of CMake, when we get a path and we have to decide whether to treat it as relative or absolute, we look at the start and if it begins with a generator expression, we typically assume/require that it is an absolute path. The behavior of install(SCRIPT)
is the opposite. Since CMake 3.14 (see !2688 (merged)), the file name can use generator expressions, but when the install()
command arguments are parsed, the file name is tested immediately without considering generator expressions using the following block of code:
} else if (doing_script) {
doing_script = false;
std::string script = arg;
if (!cmSystemTools::FileIsFullPath(script)) {
script =
cmStrCat(helper.Makefile->GetCurrentSourceDirectory(), '/', arg);
}
if (cmSystemTools::FileIsDirectory(script)) {
status.SetError("given a directory as value of SCRIPT argument.");
return false;
}
helper.Makefile->AddInstallGenerator(
cm::make_unique<cmInstallScriptGenerator>(
script, false, component, exclude_from_all, all_components,
helper.Makefile->GetBacktrace()));
I think this logic should have been updated as part of !2688 (merged), but we missed it in review. It's now many releases since then, so unfortunately we might need a policy to fix it. As it stands, using a genex for the script file name isn't really safe to use (as I just discovered!).