Difference between quote and non-quote variable

In Cmake tutorial, solution for TODO 10:

target_include_directories(Tutorial PUBLIC
                           "${PROJECT_BINARY_DIR}"
                           ${EXTRA_INCLUDES}
                           )

I wonder what is difference between "${PROJECT_BINARY_DIR}" and ${PROJECT_BINARY_DIR}?
Why are we using quote on the PROJECT_BINARY_DIR but not in EXTRA_INCLUDES?
I see both work. Which is recommendation for using variable?

My rule is “always quote unless it’s expanding into an argument list”. So PROJECT_BINARY_DIR is always a single argument, but EXTRA_INCLUDES can be a list of directories. If this were quoted, the entire list would be treated as a single include path (embedded ;s and all).

1 Like