summaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
Diffstat (limited to 'cmake')
-rw-r--r--cmake/Modules/GlibCompileSchemas.cmake44
1 files changed, 44 insertions, 0 deletions
diff --git a/cmake/Modules/GlibCompileSchemas.cmake b/cmake/Modules/GlibCompileSchemas.cmake
new file mode 100644
index 0000000..1595e36
--- /dev/null
+++ b/cmake/Modules/GlibCompileSchemas.cmake
@@ -0,0 +1,44 @@
+find_program(GLIB_COMPILE_SCHEMAS_BIN
+ NAMES "glib-compile-schemas"
+ REQUIRED
+)
+
+function(target_add_glib_schemas TARGET)
+ set(SINGLE_VALUE_ARGS "SCHEMA_DIR")
+ cmake_parse_arguments(
+ PARSE_ARGV 1
+ ""
+ "${OPTIONS}"
+ "${SINGLE_VALUE_ARGS}"
+ "${MULTI_VALUE_ARGS}"
+ )
+
+ if(NOT TARGET "${TARGET}")
+ message(FATAL_ERROR "Target '${TARGET}' does not exist")
+ endif()
+
+ if(NOT IS_ABSOLUTE "${_SCHEMA_DIR}")
+ get_filename_component(_SCHEMA_DIR "${_SCHEMA_DIR}" REALPATH)
+ endif()
+
+ if(NOT IS_DIRECTORY "${_SCHEMA_DIR}")
+ message(FATAL_ERROR "Directory '${_SCHEMA_DIR}' does not exists")
+ endif()
+
+ file(GLOB SCHAMA_FILES CONFIGURE_DEPENDS "${_SCHEMA_DIR}/*.gschema.xml")
+
+ add_custom_command(TARGET "${TARGET}"
+ PRE_BUILD
+ BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/glib-2.0/schemas/gschemas.compiled"
+ WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
+ COMMAND "${GLIB_COMPILE_SCHEMAS_BIN}"
+ ARGS
+ "--targetdir=${CMAKE_CURRENT_BINARY_DIR}/glib-2.0/schemas"
+ "--strict"
+ "${_SCHEMA_DIR}"
+ VERBATIM
+ COMMENT "Compiling gsettings schemas"
+ DEPENDS
+ ${SCHEMA_FILES}
+ )
+endfunction()