genex: $<HOST_LINK:..> and $<DEVICE_LINK:...> cannot be used in the context of try_compile/try_run
Generator expressions $<HOST_LINK:..>
and $<DEVICE_LINK:...>
cannot be used in the context of try_compile()/try_run()
.
The following snippet:
cmake_minimum_required(VERSION 3.18...3.20)
project (test LANGUAGES C)
add_library(demo INTERFACE IMPORTED)
set_property(TARGET demo PROPERTY INTERFACE_LINK_OPTIONS "$<HOST_LINK:>")
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.c" "int main() { return 0; }\n")
set(CMAKE_TRY_COMPILE_TARGET_TYPE EXECUTABLE)
try_compile(result "${CMAKE_CURRENT_BINARY_DIR}/tc" "${CMAKE_CURRENT_BINARY_DIR}/main.c"
LINK_LIBRARIES demo)
raises the following error:
CMake Error:
Error evaluating generator expression:
$<HOST_LINK:>
$<HOST_LINK:...> may only be used with binary targets to specify link
options.