diff options
author | Charles Kerr <charles.kerr@canonical.com> | 2013-03-22 16:57:58 -0500 |
---|---|---|
committer | Charles Kerr <charles.kerr@canonical.com> | 2013-03-22 16:57:58 -0500 |
commit | c8ce514661476c027c2bd8b9f8c000810e105e67 (patch) | |
tree | 3aa2f790bffe827d2fa9fe14a21a27b3c95a554b /cmake/GSettings.cmake | |
parent | 2d7bf142998a28e1970c61bf63d6435eb4d4ac1e (diff) | |
download | ayatana-indicator-session-c8ce514661476c027c2bd8b9f8c000810e105e67.tar.gz ayatana-indicator-session-c8ce514661476c027c2bd8b9f8c000810e105e67.tar.bz2 ayatana-indicator-session-c8ce514661476c027c2bd8b9f8c000810e105e67.zip |
add top-level cmake files to the repo
Diffstat (limited to 'cmake/GSettings.cmake')
-rw-r--r-- | cmake/GSettings.cmake | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/cmake/GSettings.cmake b/cmake/GSettings.cmake new file mode 100644 index 0000000..5902baa --- /dev/null +++ b/cmake/GSettings.cmake @@ -0,0 +1,108 @@ +# GSettings.cmake +# Originally based on CMake macros written for Marlin +# Updated by Yorba for newer versions of GLib. +# +# NOTE: This module does an in-place compilation of GSettings; the +# resulting gschemas.compiled file will end up in the same +# source folder as the original schema(s). + +option(GSETTINGS_COMPILE "Compile GSettings schemas. Can be disabled for packaging reasons." ON) +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) + +if (GSETTINGS_COMPILE) + message(STATUS "GSettings schemas will be compiled.") +endif () + +if (GSETTINGS_COMPILE_IN_PLACE) + message(STATUS "GSettings schemas will be compiled in-place.") +endif () + +macro(add_schemas GSETTINGS_TARGET SCHEMA_DIRECTORY) + set(PKG_CONFIG_EXECUTABLE pkg-config) + + # Locate all schema files. + file(GLOB all_schema_files + "${SCHEMA_DIRECTORY}/*.gschema.xml" + ) + + # Find the GLib path for schema installation + execute_process( + COMMAND + ${PKG_CONFIG_EXECUTABLE} + glib-2.0 + --variable prefix + OUTPUT_VARIABLE + _glib_prefix + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + + set(GSETTINGS_DIR "${_glib_prefix}/share/glib-2.0/schemas/" CACHE INTERNAL "") + + # Fetch path for schema compiler from pkg-config + execute_process( + COMMAND + ${PKG_CONFIG_EXECUTABLE} + gio-2.0 + --variable + glib_compile_schemas + OUTPUT_VARIABLE + _glib_compile_schemas + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + + set(glib_schema_compiler ${_glib_compile_schemas} CACHE INTERNAL "") + + if (GSETTINGS_COMPILE_IN_PLACE) + set(COMPILE_IN_PLACE_DIR ${CMAKE_BINARY_DIR}/gsettings) + add_custom_command( + TARGET + ${GSETTINGS_TARGET} + COMMAND + ${CMAKE_COMMAND} -E make_directory "${COMPILE_IN_PLACE_DIR}" + ) + + # Copy all schemas to the build folder. + foreach(schema_file ${all_schema_files}) + add_custom_command( + TARGET + ${GSETTINGS_TARGET} + COMMAND + ${CMAKE_COMMAND} -E copy "${schema_file}" "${COMPILE_IN_PLACE_DIR}" + COMMENT "Copying schema ${schema_file} to ${COMPILE_IN_PLACE_DIR}" + ) + endforeach() + + # Compile schema in-place. + add_custom_command( + TARGET + ${GSETTINGS_TARGET} + COMMAND + ${glib_schema_compiler} ${COMPILE_IN_PLACE_DIR} + COMMENT "Compiling schemas in folder: ${COMPILE_IN_PLACE_DIR}" + ) + endif () + + # Install and recompile schemas + message(STATUS "GSettings schemas will be installed into ${GSETTINGS_DIR}") + + install( + FILES + ${all_schema_files} + DESTINATION + ${GSETTINGS_DIR} + OPTIONAL + ) + + if (GSETTINGS_COMPILE) + install( + CODE + "message (STATUS \"Compiling GSettings schemas\")" + ) + + install( + CODE + "execute_process (COMMAND ${glib_schema_compiler} ${GSETTINGS_DIR})" + ) + endif () +endmacro(add_schemas) + |