~elementary-apps/poa-providers/fastmail

« back to all changes in this revision

Viewing changes to cmake/GSettings.cmake

  • Committer: Corentin Noël
  • Date: 2015-10-01 12:27:52 UTC
  • Revision ID: corentin@elementary.io-20151001122752-z2w3bw34jtig6qj7
Initial commit.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# GSettings.cmake, CMake macros written for Marlin, feel free to re-use them.
 
2
 
 
3
option (GSETTINGS_LOCALINSTALL "Install GSettings Schemas locally instead of to the GLib prefix" ON)
 
4
 
 
5
option (GSETTINGS_COMPILE "Compile GSettings Schemas after installation" ${GSETTINGS_LOCALINSTALL})
 
6
 
 
7
if(GSETTINGS_LOCALINSTALL)
 
8
    message(STATUS "GSettings schemas will be installed locally.")
 
9
endif()
 
10
 
 
11
if(GSETTINGS_COMPILE)
 
12
    message(STATUS "GSettings shemas will be compiled.")
 
13
endif()
 
14
 
 
15
macro(add_schema SCHEMA_NAME)
 
16
 
 
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)
 
25
 
 
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)
 
29
 
 
30
    if (_schemas_invalid)
 
31
      message (SEND_ERROR "Schema validation error: ${_schemas_invalid}")
 
32
    endif (_schemas_invalid)
 
33
 
 
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)
 
37
 
 
38
    if (GSETTINGS_COMPILE)
 
39
        install (CODE "message (STATUS \"Compiling GSettings schemas\")")
 
40
        install (CODE "execute_process (COMMAND ${_glib_comple_schemas} ${GSETTINGS_DIR})")
 
41
    endif ()
 
42
endmacro()