summaryrefslogtreecommitdiff
path: root/cmake/Modules/GlibCompileSchemas.cmake
blob: 1ffbd39dc0a74ef22c5a534a9e573e696951b51b (plain)
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
find_program(GLIB_COMPILE_SCHEMAS_BIN
  NAMES "glib-compile-schemas"
  REQUIRED
)

function(target_add_glib_schemas TARGET)
  set(SINGLE_VALUE_ARGS "SCHEMA_DIR")
  cmake_parse_arguments(
    PARSE_ARGV 1
    ""
    "${OPTIONS}"
    "${SINGLE_VALUE_ARGS}"
    "${MULTI_VALUE_ARGS}"
  )

  if(NOT TARGET "${TARGET}")
    message(FATAL_ERROR "Target '${TARGET}' does not exist")
  endif()

  if(NOT IS_ABSOLUTE "${_SCHEMA_DIR}")
    get_filename_component(_SCHEMA_DIR "${_SCHEMA_DIR}" REALPATH)
  endif()

  if(NOT IS_DIRECTORY "${_SCHEMA_DIR}")
    message(FATAL_ERROR "Directory '${_SCHEMA_DIR}' does not exists")
  endif()

  file(GLOB SCHAMA_FILES CONFIGURE_DEPENDS "${_SCHEMA_DIR}/*.gschema.xml")

  add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/glib-2.0/schemas/gschemas.compiled"
    WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
    COMMAND "${GLIB_COMPILE_SCHEMAS_BIN}"
    ARGS
    "--targetdir=${CMAKE_CURRENT_BINARY_DIR}/glib-2.0/schemas"
    "--strict"
    "${_SCHEMA_DIR}"
    VERBATIM
    COMMENT "Compiling gsettings schemas"
    DEPENDS
    ${SCHEMA_FILES}
  )

  add_custom_target("${TARGET}_schemas" DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/glib-2.0/schemas/gschemas.compiled")

  add_dependencies("${TARGET}" "${TARGET}_schemas")
endfunction()