How are circular generator expressions evaluated in CMake?

Viewed 34

Consider the following example:

cmake_minimum_required(VERSION 3.21)
project(test)

add_executable(foo foo.cpp)
target_compile_definitions(foo 
  PRIVATE "FOO$<TARGET_PROPERTY:bar,COMPILE_DEFINITIONS>")

add_executable(bar bar.cpp)
target_compile_definitions(bar 
  PRIVATE "BAR$<TARGET_PROPERTY:foo,COMPILE_DEFINITIONS>")

As you can see, the value of COMPILE_DEFINITIONS for foo depends on the value of COMPILE_DEFINITIONS for bar and vice-versa. You would expect the value for foo to diverge to an infinite string: FOOBARFOOBARFOOBAR....

Yet, this puts -DFOOBAR on foo.cpp's command line and -DBARFOO on bar.cpp's.

Why isn't this an error?

1 Answers
Related