~zanneth/somafm-gtk

5f1370b046fc349bfa5982a2de380575f36ada1a — James Magahern 6 months ago e0b409d master
cmake: Adds a install/compile step for the gsettings schema, and adds a nix flake
6 files changed, 171 insertions(+), 6 deletions(-)

M CMakeLists.txt
A cmake/GSettings.cmake
M default.nix
A flake.lock
A flake.nix
R share/{gsettings-schema.xml => com.zanneth.somafm-gtk.gschema.xml}
M CMakeLists.txt => CMakeLists.txt +9 -5
@@ 5,6 5,9 @@ project(SomaFMGTK)
set(EXECUTABLE_NAME somafm-gtk)
add_executable(${EXECUTABLE_NAME} "src/main.cpp")

# CMake includes in cmake/
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake )

find_package(PkgConfig)

pkg_check_modules(GTKMM REQUIRED gtkmm-3.0)


@@ 61,12 64,13 @@ execute_process(
    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)

# GSettings
include(GSettings)
set(GSETTINGS_DIR ${CMAKE_SOURCE_DIR}/share)
add_schemas(${EXECUTABLE_NAME} ${GSETTINGS_DIR} ${CMAKE_INSTALL_PREFIX})

# install paths
install(TARGETS ${EXECUTABLE_NAME} DESTINATION bin)
install(FILES img/somafm.png DESTINATION share/icons/hicolor/512x512/apps)
install(FILES share/somafm.desktop DESTINATION share/applications)
install(
        FILES share/gsettings-schema.xml
        RENAME com.zanneth.somafmgtk.gschema.xml
        DESTINATION share/glib-2.0/schemas
)


A cmake/GSettings.cmake => cmake/GSettings.cmake +112 -0
@@ 0,0 1,112 @@
# 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 PREFIX)
    set(PKG_CONFIG_EXECUTABLE pkg-config)
    
    # Locate all schema files.
    file(GLOB all_schema_files
        "${SCHEMA_DIRECTORY}/*.gschema.xml"
    )
    
    if ("${PREFIX}" STREQUAL "")
        # 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
        )
    else ()
        set(_glib_prefix ${PREFIX})
    endif ()
    
    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)


M default.nix => default.nix +5 -1
@@ 1,4 1,6 @@
with import <nixpkgs> {}; stdenv.mkDerivation {
{ pkgs }: 

pkgs.stdenv.mkDerivation {
	name = "somafmgtk";
	src = ./.;



@@ 11,6 13,7 @@ with import <nixpkgs> {}; stdenv.mkDerivation {
	];

	buildInputs = with pkgs; [
		glib
		gtkmm3
		curl curlpp
		jsoncpp


@@ 24,6 27,7 @@ with import <nixpkgs> {}; stdenv.mkDerivation {
		gst_all_1.gst-plugins-bad
		gst_all_1.gst-plugins-ugly
		gst_all_1.gst-libav

	];
}


A flake.lock => flake.lock +25 -0
@@ 0,0 1,25 @@
{
  "nodes": {
    "nixpkgs": {
      "locked": {
        "lastModified": 1685012353,
        "narHash": "sha256-U3oOge4cHnav8OLGdRVhL45xoRj4Ppd+It6nPC9nNIU=",
        "owner": "NixOS",
        "repo": "nixpkgs",
        "rev": "aeb75dba965e790de427b73315d5addf91a54955",
        "type": "github"
      },
      "original": {
        "id": "nixpkgs",
        "type": "indirect"
      }
    },
    "root": {
      "inputs": {
        "nixpkgs": "nixpkgs"
      }
    }
  },
  "root": "root",
  "version": 7
}

A flake.nix => flake.nix +20 -0
@@ 0,0 1,20 @@
{
	description = "SomaFM Gtk+ Client";

	outputs = { self, nixpkgs }: 
	let 
		systems = [ "x86_64-linux" "i686-linux" "aarch64-linux" ];
      	forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f system);
	in {
		overlay = final: prev: {
			somafmgtk = prev.callPackage ./default.nix {};                                 
		};

		packages = forAllSystems (system: 
			with import nixpkgs {
				inherit system;
				overlays = [ self.overlay ];
			}; { default = somafmgtk; }
		);
	};
}

R share/gsettings-schema.xml => share/com.zanneth.somafm-gtk.gschema.xml +0 -0