2
# Originally based on CMake macros written for Marlin
3
# Updated by Yorba for newer versions of GLib.
5
# NOTE: This module does an in-place compilation of GSettings; the
6
# resulting gschemas.compiled file will end up in the same
7
# source folder as the original schema(s).
9
option(GSETTINGS_COMPILE "Compile GSettings schemas. Can be disabled for packaging reasons." ON)
10
option(GSETTINGS_COMPILE_IN_PLACE "Compile GSettings schemas in the build folder. This is used for running an appliction without installing the GSettings systemwide. The application will need to set GSETTINGS_SCHEMA_DIR" ON)
12
if (GSETTINGS_COMPILE)
13
message(STATUS "GSettings schemas will be compiled.")
16
if (GSETTINGS_COMPILE_IN_PLACE)
17
message(STATUS "GSettings schemas will be compiled in-place.")
20
macro(add_schemas GSETTINGS_TARGET SCHEMA_DIRECTORY)
21
set(PKG_CONFIG_EXECUTABLE pkg-config)
23
# Locate all schema files.
24
file(GLOB all_schema_files
25
"${SCHEMA_DIRECTORY}/*.gschema.xml"
28
# Find the GLib path for schema installation
31
${PKG_CONFIG_EXECUTABLE}
36
OUTPUT_STRIP_TRAILING_WHITESPACE
39
set(GSETTINGS_DIR "${_glib_prefix}/share/glib-2.0/schemas/" CACHE INTERNAL "")
41
# Fetch path for schema compiler from pkg-config
44
${PKG_CONFIG_EXECUTABLE}
50
OUTPUT_STRIP_TRAILING_WHITESPACE
53
set(glib_schema_compiler ${_glib_compile_schemas} CACHE INTERNAL "")
55
if (GSETTINGS_COMPILE_IN_PLACE)
56
set(COMPILE_IN_PLACE_DIR ${CMAKE_BINARY_DIR}/gsettings)
61
${CMAKE_COMMAND} -E make_directory "${COMPILE_IN_PLACE_DIR}"
64
# Copy all schemas to the build folder.
65
foreach(schema_file ${all_schema_files})
70
${CMAKE_COMMAND} -E copy "${schema_file}" "${COMPILE_IN_PLACE_DIR}"
71
COMMENT "Copying schema ${schema_file} to ${COMPILE_IN_PLACE_DIR}"
75
# Compile schema in-place.
80
${glib_schema_compiler} ${COMPILE_IN_PLACE_DIR}
81
COMMENT "Compiling schemas in folder: ${COMPILE_IN_PLACE_DIR}"
85
# Install and recompile schemas
86
message(STATUS "GSettings schemas will be installed into ${GSETTINGS_DIR}")
96
if (GSETTINGS_COMPILE)
99
"message (STATUS \"Compiling GSettings schemas\")"
104
"execute_process (COMMAND ${glib_schema_compiler} ${GSETTINGS_DIR})"
107
endmacro(add_schemas)