1
# GSettings.cmake, CMake macros written for Marlin, feel free to re-use them.
3
option (GSETTINGS_LOCALINSTALL "Install GSettings Schemas locally instead of to the GLib prefix" ON)
5
option (GSETTINGS_COMPILE "Compile GSettings Schemas after installation" ${GSETTINGS_LOCALINSTALL})
7
if(GSETTINGS_LOCALINSTALL)
8
message(STATUS "GSettings schemas will be installed locally.")
12
message(STATUS "GSettings shemas will be compiled.")
15
macro(add_schema SCHEMA_NAME)
17
set(PKG_CONFIG_EXECUTABLE pkg-config)
18
# Have an option to not install the schema into where GLib is
19
if (GSETTINGS_LOCALINSTALL)
20
SET (GSETTINGS_DIR "${CMAKE_INSTALL_PREFIX}/share/glib-2.0/schemas/")
21
else (GSETTINGS_LOCALINSTALL)
22
execute_process (COMMAND ${PKG_CONFIG_EXECUTABLE} glib-2.0 --variable prefix OUTPUT_VARIABLE _glib_prefix OUTPUT_STRIP_TRAILING_WHITESPACE)
23
SET (GSETTINGS_DIR "${_glib_prefix}/share/glib-2.0/schemas/")
24
endif (GSETTINGS_LOCALINSTALL)
26
# Run the validator and error if it fails
27
execute_process (COMMAND ${PKG_CONFIG_EXECUTABLE} gio-2.0 --variable glib_compile_schemas OUTPUT_VARIABLE _glib_comple_schemas OUTPUT_STRIP_TRAILING_WHITESPACE)
28
execute_process (COMMAND ${_glib_comple_schemas} --dry-run --schema-file=${CMAKE_CURRENT_SOURCE_DIR}/${SCHEMA_NAME} ERROR_VARIABLE _schemas_invalid OUTPUT_STRIP_TRAILING_WHITESPACE)
31
message (SEND_ERROR "Schema validation error: ${_schemas_invalid}")
32
endif (_schemas_invalid)
34
# Actually install and recomple schemas
35
message (STATUS "GSettings schemas will be installed into ${GSETTINGS_DIR}")
36
install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/${SCHEMA_NAME} DESTINATION ${GSETTINGS_DIR} OPTIONAL)
38
if (GSETTINGS_COMPILE)
39
install (CODE "message (STATUS \"Compiling GSettings schemas\")")
40
install (CODE "execute_process (COMMAND ${_glib_comple_schemas} ${GSETTINGS_DIR})")