Get INSTALL_INTERFACE in `install(CODE)`.

I think I have found a bug, or at the very least a vexing behavior. Here’s my minimal example:

cmake_minimum_required(VERSION 3.16)
project(example)

add_library(example INTERFACE)
target_compile_definitions(example INTERFACE $<BUILD_INTERFACE:BUILD> $<INSTALL_INTERFACE:INSTALL>)

install(CODE [[
message(STATUS "$<TARGET_PROPERTY:example,INTERFACE_COMPILE_DEFINITIONS>")
]])

Build with:

$ cmake -S . -B build
...
-- Configuring done
-- Generating done
-- Build files have been written to: /home/alex/test/build
$ cmake --build build
$ cmake --install build --prefix install
-- Install configuration: ""
-- BUILD

As you can see, BUILD is printed rather than INSTALL. I would understand this for file(GENERATE), but for install(CODE), this is rather surprising, since it’s the install command I’m going through.

Is there any way to access the INSTALL_INTERFACE version of properties in a generator expression? If not, was this a deliberate design decision? I’d like to understand it, if so. Obviously to be changed at this point would require a policy.

This is because the install scripts are written during the build, so they get the build’s view of the properties. We’d probably need a genex to force the install’s view of the properties. Perhaps $<INSTALL:$<TARGET_PROPERTY:example,INTERFACE_COMPILE_DEFINITIONS>>?

Cc: @brad.king @craig.scott