CPM.cmake icon indicating copy to clipboard operation
CPM.cmake copied to clipboard

[Enhancement] SYSTEM include workaround for older cmake versions

Open poolfeast-420 opened this issue 1 year ago • 1 comments

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.

poolfeast-420 avatar Aug 24 '23 23:08 poolfeast-420

You can also do:

set_target_properties(${TARGET} PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES $<TARGET_PROPERTY:${TARGET},INTERFACE_INCLUDE_DIRECTORIES>)

patstew avatar Sep 04 '23 23:09 patstew