Skip to content

Inacurate error message if generator expression failed to evaluate due to lack of language information in context

I faced an odd error message while trying to write response files to overcome the Windows command line length limit. The error message was:

Evaluation file to be written multiple times with different content. 
This is generally caused by the content evaluating the configuration type, language, or location of object files:

   C:/tmp/foo.rsp

This error appears while trying to write a generator expression into a file using the command:

file(GENERATE OUTPUT "C:/tmp/foo.rsp" CONTENT $<TARGET_GENEX_EVAL:foo,$<TARGET_PROPERTY:foo,COMPILE_OPTIONS>>)

After some debugging, we found out that this error only happens if foo depends on the library bar from a Conan package.

In our case Conan defines compile options in the following way:

set(bar_COMPILE_OPTIONS_C_RELEASE "")
set(bar_COMPILE_OPTIONS_CXX_RELEASE "-Wno-unknown-attributes")
set(bar_COMPILE_OPTIONS_RELEASE
    "$<$<COMPILE_LANGUAGE:CXX>:${bar_COMPILE_OPTIONS_CXX_RELEASE}>"
    "$<$<COMPILE_LANGUAGE:C>:${bar_COMPILE_OPTIONS_C_RELEASE}>")
set_property(TARGET bar
            PROPERTY INTERFACE_COMPILE_OPTIONS
            $<$<CONFIG:Release>:${bar_COMPILE_OPTIONS_RELEASE}> APPEND)

It seems that CMake is unable to evaluate the generator expression because there is no language information in the evaluation context.

It would be better if CMake reported expression that evaluation failed due to lack of language info specifically.

Interestingly, CMake evaluates these nested generator expressions even without GENEX_EVAL/TARGET_GENEX_EVAL. Is this correct behaviour?

Tested with CMake 3.27 & 3.28.1.

BTW, it could be useful to have something like TARGET_LANG_GENEX_EVAL to provide a language context.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information