From 808727b9b49328d8e46097fccdd1614de774ed00 Mon Sep 17 00:00:00 2001 From: Guido Berhoerster Date: Mon, 1 Mar 2021 19:13:17 +0100 Subject: Add macros for compile-time version checking --- src/CMakeLists.txt | 25 ++++++++-- src/app-indicator-version.h.in | 109 +++++++++++++++++++++++++++++++++++++++++ src/app-indicator.h | 4 ++ 3 files changed, 135 insertions(+), 3 deletions(-) create mode 100644 src/app-indicator-version.h.in (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3e5f591..b0990a8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -21,6 +21,11 @@ elseif (FLAVOUR_GTK2) set (gtk_girver "Gtk-2.0") endif() +set(GIR_SOURCES + app-indicator.c + app-indicator.h +) + install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/app-indicator.h" DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}/lib${ayatana_appindicator_gtkver}-0.1/libayatana-appindicator") # ayatana-appindicator{,3}-0.1.pc @@ -132,16 +137,24 @@ install(TARGETS "${ayatana_appindicator_gtkver}" LIBRARY DESTINATION "${CMAKE_IN # AyatanaAppIndicator{,3}-0.1.gir +add_custom_command( + TARGET "${ayatana_appindicator_gtkver}" PRE_BUILD + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND + ${CMAKE_COMMAND} + -E copy + ${GIR_SOURCES} + ${CMAKE_CURRENT_BINARY_DIR} +) + find_package(GObjectIntrospection REQUIRED) add_custom_command( OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${ayatana_appindicator_girver}-0.1.gir" DEPENDS "${ayatana_appindicator_gtkver}" - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMAND ${INTROSPECTION_SCANNER} - app-indicator.c ${HEADERS} - --add-include-path=${CMAKE_CURRENT_BINARY_DIR} + ${GIR_SOURCES} --c-include=libayatana-appindicator/app-indicator.h --symbol-prefix=app --identifier-prefix=App @@ -173,3 +186,9 @@ add_custom_command( install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${ayatana_appindicator_girver}-0.1.typelib" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/girepository-1.0") add_custom_target(src ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${ayatana_appindicator_girver}-0.1.typelib") + +# app-indicator-version.h + +configure_file(app-indicator-version.h.in app-indicator-version.h @ONLY) + +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/app-indicator-version.h" DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}/lib${ayatana_appindicator_gtkver}-0.1/libayatana-appindicator") diff --git a/src/app-indicator-version.h.in b/src/app-indicator-version.h.in new file mode 100644 index 0000000..7d99c87 --- /dev/null +++ b/src/app-indicator-version.h.in @@ -0,0 +1,109 @@ +/* +Copyright (C) 2021 Guido Berhoerster + +This program is free software: you can redistribute it and/or modify it +under the terms of either or both of the following licenses: + +1) the GNU Lesser General Public License version 3, as published by the + Free Software Foundation; and/or +2) the GNU Lesser General Public License version 2.1, as published by + the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR +PURPOSE. See the applicable version of the GNU Lesser General Public +License for more details. + +You should have received a copy of both the GNU Lesser General Public +License version 3 and version 2.1 along with this program. If not, see + +*/ + +#ifndef APP_INDICATOR_VERSION_H +#define APP_INDICATOR_VERSION_H + +#if !defined(APP_INDICATOR_INSIDE) && !defined(APP_INDICATOR_COMPILATION) +#error "Only can be included directly." +#endif + +G_BEGIN_DECLS + +/** + * SECTION:app-indicator-version + * @Title: Versioning + * @short_description: Ayatana Application Indicators version checking + * + * ayatana-appindicator provides macros for checking the version of the library + * an application is compiled against. + */ + +/** + * AYATANA_APP_INDICATOR_MAJOR_VERSION: + * + * Ayatana Application Indicators major version component (e.g. 1 if + * %AYATANA_APP_INDICATOR_VERSION is 1.2.3) + */ +#define AYATANA_APP_INDICATOR_MAJOR_VERSION (@PROJECT_VERSION_MAJOR@) + +/** + * AYATANA_APP_INDICATOR_MINOR_VERSION: + * + * Ayatana Application Indicators minor version component (e.g. 2 if + * %AYATANA_APP_INDICATOR_VERSION is 1.2.3) + */ +#define AYATANA_APP_INDICATOR_MINOR_VERSION (@PROJECT_VERSION_MINOR@) + +/** + * AYATANA_APP_INDICATOR_MICRO_VERSION: + * + * Ayatana Application Indicators micro version component (e.g. 3 if + * %AYATANA_APP_INDICATOR_VERSION is 1.2.3) + */ +#define AYATANA_APP_INDICATOR_MICRO_VERSION (@PROJECT_VERSION_PATCH@) + +/** + * AYATANA_APP_INDICATOR_VERSION + * + * Ayatana Application Indicators version, e.g. 1.2.3. + */ +#define AYATANA_APP_INDICATOR_VERSION (@PROJECT_VERSION@) + +/** + * AYATANA_APP_INDICATOR_VERSION_S: + * + * Ayatana Application Indicators version, encoded as a string which may be + * concatenated, e.g. "1.2.3". + */ +#define AYATANA_APP_INDICATOR_VERSION_S "@PROJECT_VERSION@" + +#define AYATANA_APP_INDICATOR_ENCODE_VERSION(major,minor,micro) \ + ((major) << 24 | (minor) << 16 | (micro) << 8) + +/** + * AYATANA_APP_INDICATOR_VERSION_HEX: + * + * Ayatana Application Indicators version, encoded as an hexadecimal number + * which may be compared to an integer number, e.g. 0x010203. + */ +#define AYATANA_APP_INDICATOR_VERSION_HEX \ + (AYATANA_APP_INDICATOR_ENCODE_VERSION (AYATANA_APP_INDICATOR_MAJOR_VERSION, AYATANA_APP_INDICATOR_MINOR_VERSION, AYATANA_APP_INDICATOR_MICRO_VERSION)) + +/** + * AYATANA_APP_INDICATOR_CHECK_VERSION: + * @major: required major version + * @minor: required minor version + * @micro: required micro version + * + * Compile-time version checking. Evaluates to %TRUE if the version of + * ayatana-appindicator is greater than the given @major, @minor, and @micro + * numbers. + */ +#define AYATANA_APP_INDICATOR_CHECK_VERSION(major,minor,micro) \ + (AYATANA_APP_INDICATOR_MAJOR_VERSION > (major) || \ + (AYATANA_APP_INDICATOR_MAJOR_VERSION == (major) && AYATANA_APP_INDICATOR_MINOR_VERSION > (minor)) || \ + (AYATANA_APP_INDICATOR_MAJOR_VERSION == (major) && AYATANA_APP_INDICATOR_MINOR_VERSION == (minor) && AYATANA_APP_INDICATOR_MICRO_VERSION >= (micro))) + +G_END_DECLS + +#endif /* APP_INDICATOR_VERSION_H */ diff --git a/src/app-indicator.h b/src/app-indicator.h index b53b7fd..4ac78f4 100644 --- a/src/app-indicator.h +++ b/src/app-indicator.h @@ -32,6 +32,10 @@ License version 3 and version 2.1 along with this program. If not, see #include +#define APP_INDICATOR_INSIDE +#include "app-indicator-version.h" +#undef APP_INDICATOR_INSIDE + G_BEGIN_DECLS /** -- cgit v1.2.3