aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.build.yml14
-rw-r--r--CMakeLists.txt4
-rw-r--r--cmake/FindGObjectIntrospection.cmake61
-rw-r--r--cmake/FindVala.cmake57
-rw-r--r--src/CMakeLists.txt41
-rw-r--r--src/utils.h14
-rw-r--r--tests/CMakeLists.txt30
-rw-r--r--tests/tst_utils.vala57
8 files changed, 270 insertions, 8 deletions
diff --git a/.build.yml b/.build.yml
index dfdb693..1950209 100644
--- a/.build.yml
+++ b/.build.yml
@@ -17,6 +17,8 @@ requires:
- intltool
- glib2
- systemd
+ - gobject-introspection
+ - vala
debian:
# Useful URL: https://salsa.debian.org/debian-ayatana-team/ayatana-ido
@@ -33,6 +35,9 @@ requires:
- liblomiri-url-dispatcher-dev
- libgtest-dev
- systemd
+ - gobject-introspection
+ - libgirepository1.0-dev
+ - valac
debian:stable:
# Useful URL: https://salsa.debian.org/debian-ayatana-team/ayatana-ido
@@ -48,6 +53,9 @@ requires:
- libglib2.0-dev
- libgtest-dev
- systemd
+ - gobject-introspection
+ - libgirepository1.0-dev
+ - valac
ubuntu:
- autopoint
@@ -62,6 +70,9 @@ requires:
- liblomiri-url-dispatcher-dev
- libgtest-dev
- systemd
+ - gobject-introspection
+ - libgirepository1.0-dev
+ - valac
ubuntu:focal:
- autopoint
@@ -75,6 +86,9 @@ requires:
- libglib2.0-dev
- libgtest-dev
- systemd
+ - gobject-introspection
+ - libgirepository1.0-dev
+ - valac
variables:
- 'CHECKERS="
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d72cae2..751bf36 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,8 @@
project (libayatana-common C CXX)
cmake_minimum_required(VERSION 3.13)
+set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" "${CMAKE_MODULE_PATH}")
+
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
SET(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "..." FORCE)
endif(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
@@ -63,7 +65,7 @@ if (ENABLE_TESTS)
find_package(CoverageReport)
ENABLE_COVERAGE_REPORT(
TARGETS "ayatana-common"
- TESTS "tst_utils"
+ TESTS "tst_utils" "tst_utils_vala"
FILTER /usr/include ${CMAKE_BINARY_DIR}/*
)
endif()
diff --git a/cmake/FindGObjectIntrospection.cmake b/cmake/FindGObjectIntrospection.cmake
new file mode 100644
index 0000000..2073c3c
--- /dev/null
+++ b/cmake/FindGObjectIntrospection.cmake
@@ -0,0 +1,61 @@
+# - try to find gobject-introspection
+#
+# Once done this will define
+#
+# INTROSPECTION_FOUND - system has gobject-introspection
+# INTROSPECTION_SCANNER - the gobject-introspection scanner, g-ir-scanner
+# INTROSPECTION_COMPILER - the gobject-introspection compiler, g-ir-compiler
+# INTROSPECTION_GENERATE - the gobject-introspection generate, g-ir-generate
+# INTROSPECTION_GIRDIR
+# INTROSPECTION_TYPELIBDIR
+# INTROSPECTION_CFLAGS
+# INTROSPECTION_LIBS
+#
+# Copyright (C) 2010, Pino Toscano, <pino@kde.org>
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+macro(_GIR_GET_PKGCONFIG_VAR _outvar _varname)
+ execute_process(
+ COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=${_varname} gobject-introspection-1.0
+ OUTPUT_VARIABLE _result
+ RESULT_VARIABLE _null
+ )
+
+ if (_null)
+ else()
+ string(REGEX REPLACE "[\r\n]" " " _result "${_result}")
+ string(REGEX REPLACE " +$" "" _result "${_result}")
+ separate_arguments(_result)
+ set(${_outvar} ${_result} CACHE INTERNAL "")
+ endif()
+endmacro(_GIR_GET_PKGCONFIG_VAR)
+
+find_package(PkgConfig)
+if(PKG_CONFIG_FOUND)
+ if(PACKAGE_FIND_VERSION_COUNT GREATER 0)
+ set(_gir_version_cmp ">=${PACKAGE_FIND_VERSION}")
+ endif()
+ pkg_check_modules(_pc_gir gobject-introspection-1.0${_gir_version_cmp})
+ if(_pc_gir_FOUND)
+ set(INTROSPECTION_FOUND TRUE)
+ _gir_get_pkgconfig_var(INTROSPECTION_SCANNER "g_ir_scanner")
+ _gir_get_pkgconfig_var(INTROSPECTION_COMPILER "g_ir_compiler")
+ _gir_get_pkgconfig_var(INTROSPECTION_GENERATE "g_ir_generate")
+ _gir_get_pkgconfig_var(INTROSPECTION_GIRDIR "girdir")
+ _gir_get_pkgconfig_var(INTROSPECTION_TYPELIBDIR "typelibdir")
+ set(INTROSPECTION_CFLAGS "${_pc_gir_CFLAGS}")
+ set(INTROSPECTION_LIBS "${_pc_gir_LIBS}")
+ endif()
+endif()
+
+mark_as_advanced(
+ INTROSPECTION_SCANNER
+ INTROSPECTION_COMPILER
+ INTROSPECTION_GENERATE
+ INTROSPECTION_GIRDIR
+ INTROSPECTION_TYPELIBDIR
+ INTROSPECTION_CFLAGS
+ INTROSPECTION_LIBS
+)
diff --git a/cmake/FindVala.cmake b/cmake/FindVala.cmake
new file mode 100644
index 0000000..a638735
--- /dev/null
+++ b/cmake/FindVala.cmake
@@ -0,0 +1,57 @@
+# - Find Vala
+# This module looks for valac.
+# This module defines the following values:
+# VALA_FOUND
+# VALA_COMPILER
+# VALA_VERSION
+# VAPI_GEN
+# VAPI_GEN_VERSION
+
+#=============================================================================
+# Copyright Přemysl Janouch 2011
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+# OF SUCH DAMAGE.
+#=============================================================================
+
+find_program (VALA_COMPILER "valac")
+
+if (VALA_COMPILER)
+ execute_process (COMMAND ${VALA_COMPILER} --version
+ OUTPUT_VARIABLE VALA_VERSION)
+ string (REGEX MATCH "[.0-9]+" VALA_VERSION "${VALA_VERSION}")
+endif (VALA_COMPILER)
+
+find_program (VAPI_GEN "vapigen")
+
+if (VAPI_GEN)
+ execute_process (COMMAND ${VAPI_GEN} --version
+ OUTPUT_VARIABLE VAPI_GEN_VERSION)
+ string (REGEX MATCH "[.0-9]+" VAPI_GEN_VERSION "${VAPI_GEN_VERSION}")
+endif (VAPI_GEN)
+
+include (FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS (Vala
+ REQUIRED_VARS VALA_COMPILER
+ VERSION_VAR VALA_VERSION)
+
+mark_as_advanced (VALA_COMPILER VALA_VERSION VAPI_GEN)
+
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 0189cc1..637ce9f 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -27,3 +27,44 @@ configure_file(libayatana-common.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libayatana-co
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libayatana-common.pc DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig)
install(FILES ${PUBLIC_HEADERS} DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR}/ayatana/common)
install(TARGETS ayatana-common DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR})
+
+# AyatanaCommon.gir
+
+find_package(GObjectIntrospection REQUIRED QUIET)
+
+add_custom_command(
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/AyatanaCommon.gir"
+ DEPENDS "ayatana-common"
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ COMMAND
+ ${INTROSPECTION_SCANNER}
+ utils.c utils.h
+ --namespace=AyatanaCommon
+ --c-include=ayatana/common/utils.h
+ --quiet
+ --warn-all
+ --include=GLib-2.0
+ --library="ayatana-common"
+ --library-path=${CMAKE_CURRENT_BINARY_DIR}
+ --output "${CMAKE_CURRENT_BINARY_DIR}/AyatanaCommon.gir"
+)
+
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/AyatanaCommon.gir" DESTINATION "${CMAKE_INSTALL_FULL_DATADIR}/gir-1.0")
+
+# AyatanaCommon.vapi
+
+find_package(Vala REQUIRED QUIET)
+
+add_custom_command(
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/AyatanaCommon.vapi"
+ DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/AyatanaCommon.gir"
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+ COMMAND
+ ${VAPI_GEN}
+ --library=AyatanaCommon
+ AyatanaCommon.gir
+)
+
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/AyatanaCommon.vapi" DESTINATION "${CMAKE_INSTALL_FULL_DATADIR}/vala/vapi")
+
+add_custom_target("src" ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/AyatanaCommon.vapi")
diff --git a/src/utils.h b/src/utils.h
index 3098146..b8e70cb 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -22,13 +22,13 @@
#include <glib-object.h>
#include <gio/gio.h>
-#define DESKTOP_LOMIRI "Lomiri"
-#define DESKTOP_UNITY "Unity"
-#define DESKTOP_MATE "MATE"
-#define DESKTOP_GNOME "GNOME"
-#define DESKTOP_XFCE "XFCE"
-#define DESKTOP_PANTHEON "PANTHEON"
-#define DESKTOP_BUDGIE "Budgie"
+static const char *DESKTOP_LOMIRI = "Lomiri";
+static const char *DESKTOP_UNITY = "Unity";
+static const char *DESKTOP_MATE = "MATE";
+static const char *DESKTOP_GNOME = "GNOME";
+static const char *DESKTOP_XFCE = "XFCE";
+static const char *DESKTOP_PANTHEON = "PANTHEON";
+static const char *DESKTOP_BUDGIE = "Budgie";
gboolean ayatana_common_utils_is_lomiri();
gboolean ayatana_common_utils_is_unity();
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 0349ae6..61ce542 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -32,3 +32,33 @@ target_link_libraries(tst_utils
)
add_test(TstUtils tst_utils)
+
+# utils.h
+
+file(COPY "${CMAKE_SOURCE_DIR}/src/utils.h" DESTINATION "${CMAKE_BINARY_DIR}/src/ayatana/common")
+
+# tst_utils.c
+
+add_custom_command(
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/tst_utils.c"
+ DEPENDS "src"
+ DEPENDS "gschemas-compiled"
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ COMMAND
+ ${VALA_COMPILER}
+ --pkg AyatanaCommon
+ --pkg gio-2.0
+ --vapidir=${CMAKE_BINARY_DIR}/src
+ --ccode tst_utils.vala
+ --directory=${CMAKE_CURRENT_BINARY_DIR}
+)
+
+# tst_utils_vala
+
+add_executable("tst_utils_vala" "${CMAKE_CURRENT_BINARY_DIR}/tst_utils.c")
+target_include_directories("tst_utils_vala" PUBLIC "${GLIB_INCLUDE_DIRS};${CMAKE_BINARY_DIR}/src")
+target_link_libraries("tst_utils_vala" "${GLIB_LIBRARIES} -layatana-common -L${CMAKE_BINARY_DIR}/src")
+target_link_directories("tst_utils_vala" PUBLIC "${CMAKE_BINARY_DIR}/src")
+add_dependencies("tst_utils_vala" "src")
+
+add_test(NAME "TstUtilsVala" COMMAND "${CMAKE_CURRENT_BINARY_DIR}/tst_utils_vala" "${CMAKE_CURRENT_BINARY_DIR}")
diff --git a/tests/tst_utils.vala b/tests/tst_utils.vala
new file mode 100644
index 0000000..b46fb24
--- /dev/null
+++ b/tests/tst_utils.vala
@@ -0,0 +1,57 @@
+using AyatanaCommon;
+using Environment;
+
+static int main(string[] args)
+{
+ assert_true(args.length == 2);
+
+ unset_variable("XDG_CURRENT_DESKTOP");
+
+ assert_false(utils_is_lomiri());
+ set_variable("XDG_CURRENT_DESKTOP", "Lomiri", true);
+ assert_true(utils_is_lomiri());
+
+ assert_false(utils_is_gnome());
+ set_variable("XDG_CURRENT_DESKTOP", "GNOME", true);
+ assert_true(utils_is_gnome());
+
+ assert_false(utils_is_unity());
+ set_variable("XDG_CURRENT_DESKTOP", "Unity", true);
+ assert_true(utils_is_unity());
+
+ assert_false(utils_is_mate());
+ set_variable("XDG_CURRENT_DESKTOP", "MATE", true);
+ assert_true(utils_is_mate());
+
+ assert_false(utils_is_xfce());
+ set_variable("XDG_CURRENT_DESKTOP", "XFCE", true);
+ assert_true(utils_is_xfce());
+
+ assert_false(utils_is_pantheon());
+ set_variable("XDG_CURRENT_DESKTOP", "PANTHEON", true);
+ assert_true(utils_is_pantheon());
+
+ assert_false(utils_is_budgie());
+ set_variable("XDG_CURRENT_DESKTOP", "Budgie:GNOME", true);
+ assert_true(utils_is_budgie());
+
+ unset_variable("XDG_CURRENT_DESKTOP");
+ set_variable("GSETTINGS_SCHEMA_DIR", args[1], true);
+ set_variable("GSETTINGS_BACKEND", "memory", true);
+
+ Settings pSettings = new Settings("org.ayatana.common");
+ string sTest = "123456789012345678901234567890123456789012345öüóőúéáűšđß";
+ pSettings.set_uint("max-menu-text-length", 0);
+ utils_ellipsize(sTest);
+ assert_true(sTest == "123456789012345678901234567890123456789012345öüóőúéáűšđß");
+
+ pSettings.set_uint("max-menu-text-length", 100);
+ utils_ellipsize(sTest);
+ assert_true(sTest == "123456789012345678901234567890123456789012345öüóőúéáűšđß");
+
+ pSettings.set_uint("max-menu-text-length", 50);
+ utils_ellipsize(sTest);
+ assert_true(sTest == "123456789012345678901234567890123456789012345öüóőú...");
+
+ return 0;
+}