'How to recursively expand cmake generator expressions?

I am using a cmake generator expression to read a target property

set_tests_properties(
    Java-wrapper
PROPERTIES
    ENVIRONMENT _JAVA_OPTIONS=-Djava.library.path=$<TARGET_PROPERTY:ktx-jni,LIBRARY_OUTPUT_DIRECTORY>
)

LIBRARY_OUTPUT_DIRECTORY is itself defined using a generator expression

set_target_properties(ktx-jni PROPERTIES
    LIBRARY_OUTPUT_DIRECTORY ${KTX_BUILD_DIR}/$<CONFIG>
)

During build LIBRARY_OUTPUT_DIRECTORY is expanded correctly and the built library appears in Debug or Release as expected. However in the environment seen by the test $<CONFIG> is not expanded.

Picked up _JAVA_OPTIONS: -Djava.library.path=/Users/mark/Projects/khronos/github/KTX-Software/build/macos/$<CONFIG>

If instead I use

ENVIRONMENT _JAVA_OPTIONS=-Djava.library.path=${KTX_BUILD_DIR}/$<CONFIG>

$<CONFIG> is expanded correctly and the test runs successfully.

How can I get cmake to recursively expand LIBRARY_OUTPUT_DIRECTORY?



Solution 1:[1]

I found the solution, use TARGET_GENEX_EVAL, as in the below.

    ENVIRONMENT _JAVA_OPTIONS=-Djava.library.path=$<TARGET_GENEX_EVAL:ktx-jni,$<TARGET_PROPERTY:ktx-jni,LIBRARY_OUTPUT_DIRECTORY>>

I missed it before because it is listed under String Transformations not Target Dependent Queries in the cmake documentation.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 msc