~unity8-desktop-session-team/indicator-session/indicator-session-using-upstart

« back to all changes in this revision

Viewing changes to cmake/GSettings.cmake

  • Committer: Charles Kerr
  • Date: 2013-03-22 21:57:58 UTC
  • mto: (384.2.29 ng)
  • mto: This revision was merged to the branch mainline in revision 399.
  • Revision ID: charles.kerr@canonical.com-20130322215758-abhq4bdmicot7saj
add top-level cmake files to the repo

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# GSettings.cmake
 
2
# Originally based on CMake macros written for Marlin
 
3
# Updated by Yorba for newer versions of GLib.
 
4
#
 
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).
 
8
 
 
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)
 
11
 
 
12
if (GSETTINGS_COMPILE)
 
13
    message(STATUS "GSettings schemas will be compiled.")
 
14
endif ()
 
15
 
 
16
if (GSETTINGS_COMPILE_IN_PLACE)
 
17
    message(STATUS "GSettings schemas will be compiled in-place.")
 
18
endif ()
 
19
 
 
20
macro(add_schemas GSETTINGS_TARGET SCHEMA_DIRECTORY)
 
21
    set(PKG_CONFIG_EXECUTABLE pkg-config)
 
22
    
 
23
    # Locate all schema files.
 
24
    file(GLOB all_schema_files
 
25
        "${SCHEMA_DIRECTORY}/*.gschema.xml"
 
26
    )
 
27
    
 
28
    # Find the GLib path for schema installation
 
29
    execute_process(
 
30
        COMMAND
 
31
            ${PKG_CONFIG_EXECUTABLE}
 
32
            glib-2.0
 
33
            --variable prefix
 
34
        OUTPUT_VARIABLE
 
35
            _glib_prefix
 
36
        OUTPUT_STRIP_TRAILING_WHITESPACE
 
37
    )
 
38
    
 
39
    set(GSETTINGS_DIR "${_glib_prefix}/share/glib-2.0/schemas/" CACHE INTERNAL "")
 
40
    
 
41
    # Fetch path for schema compiler from pkg-config
 
42
    execute_process(
 
43
        COMMAND
 
44
            ${PKG_CONFIG_EXECUTABLE}
 
45
            gio-2.0
 
46
            --variable
 
47
            glib_compile_schemas
 
48
        OUTPUT_VARIABLE
 
49
            _glib_compile_schemas
 
50
        OUTPUT_STRIP_TRAILING_WHITESPACE
 
51
    )
 
52
    
 
53
    set(glib_schema_compiler ${_glib_compile_schemas} CACHE INTERNAL "")
 
54
    
 
55
    if (GSETTINGS_COMPILE_IN_PLACE)
 
56
        set(COMPILE_IN_PLACE_DIR ${CMAKE_BINARY_DIR}/gsettings)
 
57
        add_custom_command(
 
58
            TARGET
 
59
                ${GSETTINGS_TARGET}
 
60
            COMMAND 
 
61
                ${CMAKE_COMMAND} -E make_directory "${COMPILE_IN_PLACE_DIR}"
 
62
        )
 
63
        
 
64
        # Copy all schemas to the build folder.
 
65
        foreach(schema_file ${all_schema_files})
 
66
            add_custom_command(
 
67
                TARGET
 
68
                    ${GSETTINGS_TARGET}
 
69
                COMMAND 
 
70
                    ${CMAKE_COMMAND} -E copy "${schema_file}" "${COMPILE_IN_PLACE_DIR}"
 
71
                COMMENT "Copying schema ${schema_file} to ${COMPILE_IN_PLACE_DIR}"
 
72
            )
 
73
        endforeach()
 
74
        
 
75
        # Compile schema in-place.
 
76
        add_custom_command(
 
77
            TARGET 
 
78
                ${GSETTINGS_TARGET}
 
79
            COMMAND
 
80
                ${glib_schema_compiler} ${COMPILE_IN_PLACE_DIR}
 
81
            COMMENT "Compiling schemas in folder: ${COMPILE_IN_PLACE_DIR}"
 
82
        )
 
83
    endif ()
 
84
        
 
85
    # Install and recompile schemas
 
86
    message(STATUS "GSettings schemas will be installed into ${GSETTINGS_DIR}")
 
87
    
 
88
    install(
 
89
        FILES
 
90
            ${all_schema_files}
 
91
        DESTINATION
 
92
            ${GSETTINGS_DIR}
 
93
        OPTIONAL
 
94
    )
 
95
    
 
96
    if (GSETTINGS_COMPILE)
 
97
        install(
 
98
            CODE
 
99
                "message (STATUS \"Compiling GSettings schemas\")"
 
100
        )
 
101
        
 
102
        install(
 
103
            CODE
 
104
                "execute_process (COMMAND ${glib_schema_compiler} ${GSETTINGS_DIR})"
 
105
        )
 
106
    endif ()
 
107
endmacro(add_schemas)
 
108