File: FindGLibCompileResources.cmake

package info (click to toggle)
webkit2gtk 2.48.3-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 429,620 kB
  • sloc: cpp: 3,696,936; javascript: 194,444; ansic: 169,997; python: 46,499; asm: 19,276; ruby: 18,528; perl: 16,602; xml: 4,650; yacc: 2,360; sh: 2,098; java: 1,993; lex: 1,327; pascal: 366; makefile: 298
file content (70 lines) | stat: -rw-r--r-- 2,525 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
pkg_get_variable(GLIB2_PREFIX glib-2.0 prefix)
find_program(
    GLIB_COMPILE_RESOURCES_EXECUTABLE
    NAMES glib-compile-resources
    HINTS ${GLIB2_PREFIX}
    REQUIRED
)
execute_process(
    COMMAND ${GLIB_COMPILE_RESOURCES_EXECUTABLE} --version
    OUTPUT_VARIABLE glib_compile_resources_version
    OUTPUT_STRIP_TRAILING_WHITESPACE
)
message(STATUS "Found glib-compile-resources (required): "
    ${GLIB_COMPILE_RESOURCES_EXECUTABLE}
    " (${glib_compile_resources_version})"
)

set(glib_compile_resources_has_depfile_bug FALSE)
if ("${glib_compile_resources_version}" VERSION_LESS 2.77)
    set(glib_compile_resources_has_depfile_bug TRUE)
endif ()

function(GLIB_COMPILE_RESOURCES)
    set(zeroArgKeywords "")
    set(oneArgKeywords OUTPUT SOURCE_XML)
    set(manyArgsKeywords RESOURCE_DIRS)
    cmake_parse_arguments(
        PARSE_ARGV 0 ARG
        "${zeroArgKeywords}" "${oneArgKeywords}" "${manyArgsKeywords}"
    )

    set(resource_dir_args "")
    foreach (resource_dir IN LISTS ARG_RESOURCE_DIRS)
        list(APPEND resource_dir_args --sourcedir=${resource_dir})
    endforeach ()

    set(additional_cmd_line)
    if (${glib_compile_resources_has_depfile_bug})
        # Workaround for older versions of glib-compile-resources lacking this fix:
        # https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3460
        #
        # Affected versions produce broken depfiles that look like this:
        #   foo.xml: resource1 resource2
        # But depfiles should look like this:
        #   foo.c: foo.xml resource1 resource2
        set(additional_cmd_line &&
            ${PERL_EXECUTABLE} -pi ${CMAKE_SOURCE_DIR}/Tools/glib/fix-glib-resources-depfile.pl
            ${ARG_SOURCE_XML} ${ARG_OUTPUT} ${ARG_OUTPUT}.deps)
    endif ()

    get_filename_component(output_dir "${ARG_OUTPUT}" DIRECTORY)
    get_filename_component(output_dir "${output_dir}" ABSOLUTE)
    get_filename_component(ARG_OUTPUT "${ARG_OUTPUT}" ABSOLUTE)

    add_custom_command(
        OUTPUT  ${ARG_OUTPUT} ${ARG_OUTPUT}.deps
        DEPENDS ${ARG_SOURCE_XML}
        DEPFILE ${ARG_OUTPUT}.deps
        COMMAND ${CMAKE_COMMAND} -E make_directory "${output_dir}"
        COMMAND ${GLIB_COMPILE_RESOURCES_EXECUTABLE}
                --generate
                --target=${ARG_OUTPUT}
                --dependency-file=${ARG_OUTPUT}.deps
                ${resource_dir_args}
                ${ARG_SOURCE_XML}
                ${additional_cmd_line}
        WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
        VERBATIM
    )
endfunction()