Documentation for add_compile_definitions() still differs from actual behavior
Since #18147 (closed), the documentation for
add_compile_definitions() command states this:
Adds preprocessor definitions to the compiler command line for targets in the current directory and below (whether added before or after this command is invoked).
This is not the case, though, for targets in subdirectories that have been added before the call to
The following minimal project demonstrates the behavior:
cmake_minimum_required(VERSION 3.17) project(Example) # BUG: The compiler commands for targets defined within this subdirectory do NOT have the -DSYMBOL_DEFINED_AT_TOPLEVEL flag add_subdirectory(foo) add_compile_definitions(SYMBOL_DEFINED_AT_TOPLEVEL) # OK: The compiler commands for targets defined within this subdirectory DO have the -DSYMBOL_DEFINED_AT_TOPLEVEL flag add_subdirectory(bar)
The same behavior occurs for all other functions that I have tested, including: