Skip to content

target_compile_definitions: Overriding definitions from usage requirements

when submodule define a macro which named "TAG" and with a value( target_compile_definitions(lib1 PUBLIC TAG=a)), then some target link this submodule,and define a macro with the same name. but at last, the macro declared in build.ninja in alphabetical order. That means, the upper module cannot override the value of the macro.

add_library(subModule STATIC ${SOURCE_FILES})
target_compile_definitions(subModule PUBLIC TAG=a) # I need PUBLIC

add_library(upperModule STATIC ${OTHER_SOURCE_FILES})
target_link_libraries(upperModule PRIVATE subModule)

# 1. upper module can override the value
target_compile_definitions(upperModule PUBLIC TAG=z) # because z>a 
# the result in build.ninja:   -DTAG=a -DTAG=z

# 2. upper module cannot override the value
target_compile_definitions(upperModule PUBLIC TAG=Z) # because Z<z 
# the result in build.ninja:   -DTAG=Z -DTAG=a
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information