CPM.cmake
CPM.cmake copied to clipboard
[Enhancement] SYSTEM include workaround for older cmake versions
Cmake versions older than 3.25 do not have the SYSTEM
target property.
Entries of INTERFACE_INCLUDE_DIRECTORIES are treated as system include directories when compiling consumers.
Its possible to move all INTERFACE_INCLUDE_DIRECTORIES
to INTERFACE_SYSTEM_INCLUDE_DIRECTORIES
manually with something like:
# Grab the public includes from a target
get_target_property(IID ${TARGET} INTERFACE_INCLUDE_DIRECTORIES)
# Set the targets public includes as its system includes
set_target_properties(${TARGET} PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${IID}")
Could CPM do this automatically based on the version?
From my understanding this could be transparent to users.
You can also do:
set_target_properties(${TARGET} PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES $<TARGET_PROPERTY:${TARGET},INTERFACE_INCLUDE_DIRECTORIES>)