Skip to content

Truly independent web browser

2.3 KB
Raw Blame
# Only the Compositor process links Skia. ladybird_check_skia_confinement() walks the link dependencies of the given
# targets, through the shared libraries that they load and the static libraries that they take in, and fails the
# configuration if any of them reaches Skia.

function(_ladybird_skia_link_path target chain output)
    get_property(visited GLOBAL PROPERTY _LADYBIRD_SKIA_CHECK_VISITED)
    if ("${target}" IN_LIST visited)
        return()
    endif()
    set_property(GLOBAL APPEND PROPERTY _LADYBIRD_SKIA_CHECK_VISITED "${target}")

    get_target_property(aliased_target "${target}" ALIASED_TARGET)
    if (aliased_target)
        set(target "${aliased_target}")
    endif()
    if ("${target}" STREQUAL "${SKIA_TARGET}")
        set("${output}" "${chain}" PARENT_SCOPE)
        return()
    endif()

    get_target_property(type "${target}" TYPE)
    set(dependencies "")
    if (NOT "${type}" STREQUAL "INTERFACE_LIBRARY")
        get_target_property(link_libraries "${target}" LINK_LIBRARIES)
        if (link_libraries)
            list(APPEND dependencies ${link_libraries})
        endif()
    endif()
    get_target_property(interface_link_libraries "${target}" INTERFACE_LINK_LIBRARIES)
    if (interface_link_libraries)
        list(APPEND dependencies ${interface_link_libraries})
    endif()

    foreach (dependency IN LISTS dependencies)
        # A static library passes its private dependencies on as $<LINK_ONLY:...>. Other generator expressions do not
        # name Skia.
        string(REGEX REPLACE "^\\$<LINK_ONLY:(.+)>$" "\\1" dependency "${dependency}")
        if (dependency MATCHES "^\\$<" OR NOT TARGET "${dependency}")
            continue()
        endif()
        _ladybird_skia_link_path("${dependency}" "${chain} -> ${dependency}" found_chain)
        if (found_chain)
            set("${output}" "${found_chain}" PARENT_SCOPE)
            return()
        endif()
    endforeach()
endfunction()

function(ladybird_check_skia_confinement)
    foreach (target IN LISTS ARGN)
        if (NOT TARGET "${target}")
            continue()
        endif()
        set_property(GLOBAL PROPERTY _LADYBIRD_SKIA_CHECK_VISITED "")
        _ladybird_skia_link_path("${target}" "${target}" chain)
        if (chain)
            message(FATAL_ERROR "Only the Compositor may link Skia, but ${target} reaches it: ${chain}")
        endif()
    endforeach()
endfunction()