Stepan Salenikovich | fb7f295 | 2015-05-25 16:44:19 -0400 | [diff] [blame] | 1 | # CMake macros adapted from those written for Marlin, released under GPLv3: |
| 2 | # https://github.com/ammonkey/marlin/blob/master/cmake/GSettings.cmake |
| 3 | # |
Stepan Salenikovich | be87d2c | 2016-01-25 14:14:34 -0500 | [diff] [blame] | 4 | # Copyright (C) 2015-2016 Savoir-faire Linux Inc. |
Stepan Salenikovich | fb7f295 | 2015-05-25 16:44:19 -0400 | [diff] [blame] | 5 | # Author: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com> |
| 6 | # |
| 7 | # This program is free software; you can redistribute it and/or modify |
| 8 | # it under the terms of the GNU General Public License as published by |
| 9 | # the Free Software Foundation; either version 3 of the License, or |
| 10 | # (at your option) any later version. |
| 11 | # |
| 12 | # This program is distributed in the hope that it will be useful, |
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | # GNU General Public License for more details. |
| 16 | # |
| 17 | # You should have received a copy of the GNU General Public License |
| 18 | # along with this program; if not, write to the Free Software |
| 19 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | # |
Stepan Salenikovich | fb7f295 | 2015-05-25 16:44:19 -0400 | [diff] [blame] | 21 | |
| 22 | option (GSETTINGS_LOCALCOMPILE "Compile GSettings schemas locally during build to the location of the binary (no need to run 'make install')" ON) |
| 23 | |
| 24 | option (GSETTINGS_PREFIXINSTALL "Install GSettings Schemas relative to the location specified by the install prefix (instead of relative to where GLib is installed)" ON) |
| 25 | |
| 26 | option (GSETTINGS_COMPILE "Compile GSettings Schemas after installation" ${GSETTINGS_LOCALCOMPILE}) |
| 27 | |
| 28 | if (GSETTINGS_LOCALCOMPILE) |
| 29 | message(STATUS "GSettings schemas will be compiled to the build directory during the build.") |
| 30 | endif () |
| 31 | |
| 32 | if (GSETTINGS_PREFIXINSTALL) |
| 33 | message (STATUS "GSettings schemas will be installed relative to the cmake install prefix.") |
| 34 | else () |
| 35 | message (STATUS "GSettings schemas will be installed relative to the GLib install location.") |
| 36 | endif () |
| 37 | |
| 38 | if (GSETTINGS_COMPILE) |
| 39 | message (STATUS "GSettings shemas will be compiled after install.") |
| 40 | endif () |
| 41 | |
| 42 | macro (add_schema SCHEMA_NAME OUTPUT) |
| 43 | |
| 44 | set (PKG_CONFIG_EXECUTABLE pkg-config) |
| 45 | |
| 46 | if (GSETTINGS_PREFIXINSTALL) |
| 47 | set (GSETTINGS_DIR "${CMAKE_INSTALL_PREFIX}/share/glib-2.0/schemas/") |
| 48 | else (GSETTINGS_PREFIXINSTALL) |
| 49 | execute_process (COMMAND ${PKG_CONFIG_EXECUTABLE} glib-2.0 --variable prefix OUTPUT_VARIABLE _glib_prefix OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 50 | set (GSETTINGS_DIR "${_glib_prefix}/share/glib-2.0/schemas/") |
| 51 | endif (GSETTINGS_PREFIXINSTALL) |
| 52 | |
| 53 | # Validate the schema |
| 54 | execute_process (COMMAND ${PKG_CONFIG_EXECUTABLE} gio-2.0 --variable glib_compile_schemas OUTPUT_VARIABLE _glib_comple_schemas OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 55 | execute_process (COMMAND ${_glib_comple_schemas} --dry-run --schema-file=${CMAKE_CURRENT_SOURCE_DIR}/data/${SCHEMA_NAME} ERROR_VARIABLE _schemas_invalid OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 56 | |
| 57 | if (_schemas_invalid) |
| 58 | message (SEND_ERROR "Schema validation error: ${_schemas_invalid}") |
| 59 | endif (_schemas_invalid) |
| 60 | |
| 61 | if (GSETTINGS_LOCALCOMPILE) |
| 62 | # compile locally during build to not force the user to 'make install' |
| 63 | # when running from the build dir |
| 64 | add_custom_command( |
| 65 | OUTPUT "${PROJECT_BINARY_DIR}/gschemas.compiled" |
| 66 | WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/data" |
| 67 | COMMAND |
| 68 | "${_glib_comple_schemas}" |
| 69 | ARGS |
| 70 | "${PROJECT_SOURCE_DIR}/data" |
| 71 | "--targetdir=${PROJECT_BINARY_DIR}" |
| 72 | DEPENDS |
| 73 | "${PROJECT_SOURCE_DIR}/data/${SCHEMA_NAME}" |
| 74 | VERBATIM |
| 75 | ) |
| 76 | |
| 77 | set(${OUTPUT} "${PROJECT_BINARY_DIR}/gschemas.compiled") |
| 78 | endif (GSETTINGS_LOCALCOMPILE) |
| 79 | |
| 80 | # Actually install and recompile schemas |
| 81 | install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/${SCHEMA_NAME} DESTINATION ${GSETTINGS_DIR} OPTIONAL) |
| 82 | |
| 83 | if (GSETTINGS_COMPILE) |
| 84 | install (CODE "message (STATUS \"Compiling GSettings schemas\")") |
| 85 | install (CODE "execute_process (COMMAND ${_glib_comple_schemas} ${GSETTINGS_DIR})") |
| 86 | endif () |
| 87 | endmacro() |