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 | # |
| 4 | # Copyright (C) 2015 Savoir-Faire Linux Inc. |
| 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 | # |
| 21 | # Additional permission under GNU GPL version 3 section 7: |
| 22 | # |
| 23 | # If you modify this program, or any covered work, by linking or |
| 24 | # combining it with the OpenSSL project's OpenSSL library (or a |
| 25 | # modified version of that library), containing parts covered by the |
| 26 | # terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. |
| 27 | # grants you additional permission to convey the resulting work. |
| 28 | # Corresponding Source for a non-source form of such a combination |
| 29 | # shall include the source code for the parts of OpenSSL used as well |
| 30 | # as that of the covered work. |
| 31 | # |
| 32 | |
| 33 | option (GSETTINGS_LOCALCOMPILE "Compile GSettings schemas locally during build to the location of the binary (no need to run 'make install')" ON) |
| 34 | |
| 35 | option (GSETTINGS_PREFIXINSTALL "Install GSettings Schemas relative to the location specified by the install prefix (instead of relative to where GLib is installed)" ON) |
| 36 | |
| 37 | option (GSETTINGS_COMPILE "Compile GSettings Schemas after installation" ${GSETTINGS_LOCALCOMPILE}) |
| 38 | |
| 39 | if (GSETTINGS_LOCALCOMPILE) |
| 40 | message(STATUS "GSettings schemas will be compiled to the build directory during the build.") |
| 41 | endif () |
| 42 | |
| 43 | if (GSETTINGS_PREFIXINSTALL) |
| 44 | message (STATUS "GSettings schemas will be installed relative to the cmake install prefix.") |
| 45 | else () |
| 46 | message (STATUS "GSettings schemas will be installed relative to the GLib install location.") |
| 47 | endif () |
| 48 | |
| 49 | if (GSETTINGS_COMPILE) |
| 50 | message (STATUS "GSettings shemas will be compiled after install.") |
| 51 | endif () |
| 52 | |
| 53 | macro (add_schema SCHEMA_NAME OUTPUT) |
| 54 | |
| 55 | set (PKG_CONFIG_EXECUTABLE pkg-config) |
| 56 | |
| 57 | if (GSETTINGS_PREFIXINSTALL) |
| 58 | set (GSETTINGS_DIR "${CMAKE_INSTALL_PREFIX}/share/glib-2.0/schemas/") |
| 59 | else (GSETTINGS_PREFIXINSTALL) |
| 60 | execute_process (COMMAND ${PKG_CONFIG_EXECUTABLE} glib-2.0 --variable prefix OUTPUT_VARIABLE _glib_prefix OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 61 | set (GSETTINGS_DIR "${_glib_prefix}/share/glib-2.0/schemas/") |
| 62 | endif (GSETTINGS_PREFIXINSTALL) |
| 63 | |
| 64 | # Validate the schema |
| 65 | execute_process (COMMAND ${PKG_CONFIG_EXECUTABLE} gio-2.0 --variable glib_compile_schemas OUTPUT_VARIABLE _glib_comple_schemas OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 66 | 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) |
| 67 | |
| 68 | if (_schemas_invalid) |
| 69 | message (SEND_ERROR "Schema validation error: ${_schemas_invalid}") |
| 70 | endif (_schemas_invalid) |
| 71 | |
| 72 | if (GSETTINGS_LOCALCOMPILE) |
| 73 | # compile locally during build to not force the user to 'make install' |
| 74 | # when running from the build dir |
| 75 | add_custom_command( |
| 76 | OUTPUT "${PROJECT_BINARY_DIR}/gschemas.compiled" |
| 77 | WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/data" |
| 78 | COMMAND |
| 79 | "${_glib_comple_schemas}" |
| 80 | ARGS |
| 81 | "${PROJECT_SOURCE_DIR}/data" |
| 82 | "--targetdir=${PROJECT_BINARY_DIR}" |
| 83 | DEPENDS |
| 84 | "${PROJECT_SOURCE_DIR}/data/${SCHEMA_NAME}" |
| 85 | VERBATIM |
| 86 | ) |
| 87 | |
| 88 | set(${OUTPUT} "${PROJECT_BINARY_DIR}/gschemas.compiled") |
| 89 | endif (GSETTINGS_LOCALCOMPILE) |
| 90 | |
| 91 | # Actually install and recompile schemas |
| 92 | install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/${SCHEMA_NAME} DESTINATION ${GSETTINGS_DIR} OPTIONAL) |
| 93 | |
| 94 | if (GSETTINGS_COMPILE) |
| 95 | install (CODE "message (STATUS \"Compiling GSettings schemas\")") |
| 96 | install (CODE "execute_process (COMMAND ${_glib_comple_schemas} ${GSETTINGS_DIR})") |
| 97 | endif () |
| 98 | endmacro() |