From 2f2eb90b69cceee30f75bb5cdbd1c4059fc21460 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Mon, 11 Mar 2019 10:36:02 +0100 Subject: [PATCH] Add automatic version numbering to command line and GUI --- CMakeLists.txt | 4 +++- glade/main.glade | 3 +-- main-window.c | 6 ++++++ main.c | 17 ++++++++++++++- version/CMakeLists.txt | 5 +++++ version/generate-version-string.sh | 1 + version/version.c | 34 ++++++++++++++++++++++++++++++ version/version.h | 28 ++++++++++++++++++++++++ 8 files changed, 94 insertions(+), 4 deletions(-) create mode 100644 version/CMakeLists.txt create mode 100755 version/generate-version-string.sh create mode 100644 version/version.c create mode 100644 version/version.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 50ca59b..03b94df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,7 @@ pkg_check_modules(CAIRO REQUIRED cairo) add_subdirectory(glade) add_subdirectory(doxygen) +add_subdirectory(version) include_directories(${GLIB_INCLUDE_DIRS} ${GTK3_INCLUDE_DIRS} ${CAIRO_INCLUDE_DIRS}) link_directories(${GLIB_LINK_DIRS} ${GTK3_LINK_DIRS} ${CAIRO_LINK_DIRS}) @@ -35,7 +36,8 @@ add_compile_options(-Wall) add_executable(${PROJECT_NAME} ${SOURCE} ${CMAKE_CURRENT_BINARY_DIR}/glade/resources.c) add_dependencies(${PROJECT_NAME} glib-resources) +add_dependencies(${PROJECT_NAME} version) SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_BINARY_DIR}/glade/resources.c PROPERTIES GENERATED 1) -target_link_libraries(${PROJECT_NAME} ${GLIB_LDFLAGS} ${GTK3_LDFLAGS} ${CAIRO_LDFLAGS} m ${CMAKE_DL_LIBS}) +target_link_libraries(${PROJECT_NAME} ${GLIB_LDFLAGS} ${GTK3_LDFLAGS} ${CAIRO_LDFLAGS} m version ${CMAKE_DL_LIBS}) install (TARGETS ${PROJECT_NAME} DESTINATION bin) diff --git a/glade/main.glade b/glade/main.glade index 7df45fb..5904919 100644 --- a/glade/main.glade +++ b/glade/main.glade @@ -7,12 +7,11 @@ False gds-render - + header True False GDS Renderer - GDSII to PDF/TikZ Converter True diff --git a/main-window.c b/main-window.c index 600bf0a..3475461 100644 --- a/main-window.c +++ b/main-window.c @@ -37,6 +37,7 @@ #include "widgets/conv-settings-dialog.h" #include "cairo-output/cairo-output.h" #include "trigonometric/cell-trigonometrics.h" +#include "version/version.h" /** * @brief User data supplied to callback function of the open button @@ -354,6 +355,7 @@ GtkWindow *create_main_window() GtkWidget *listbox; GtkWidget *conv_button; GtkWidget *search_entry; + GtkHeaderBar *header_bar; static GList *gds_libs; static struct open_button_data open_data; static struct convert_button_data conv_data; @@ -397,6 +399,10 @@ GtkWindow *create_main_window() g_signal_connect(G_OBJECT(gtk_tree_view_get_selection(cell_tree)), "changed", G_CALLBACK(cell_selection_changed), conv_button); + /* Set version in main window subtitle */ + header_bar = GTK_HEADER_BAR(gtk_builder_get_object(main_builder, "header-bar")); + gtk_header_bar_set_subtitle(header_bar, _app_version_string); + g_object_unref(main_builder); return (conv_data.main_window); diff --git a/main.c b/main.c index 1eea1f7..89274fd 100644 --- a/main.c +++ b/main.c @@ -23,6 +23,7 @@ #include "main-window.h" #include "command-line.h" #include "external-renderer.h" +#include "version/version.h" struct application_data { GtkApplication *app; @@ -106,6 +107,12 @@ static int start_gui(int argc, char **argv) return app_status; } +static void print_version() +{ + printf("This is gds-render, version: %s\n\nFor a list of supported commands execute with --help option.\n", + _app_version_string); +} + int main(int argc, char **argv) { GError *error = NULL; @@ -114,12 +121,14 @@ int main(int argc, char **argv) gchar *basename; gchar *pdfname = NULL, *texname = NULL, *mappingname = NULL, *cellname = NULL, *svgname = NULL; gboolean tikz = FALSE, pdf = FALSE, pdf_layers = FALSE, pdf_standalone = FALSE, svg = FALSE; + gboolean version = FALSE; gchar *custom_library_path = NULL; gchar *custom_library_file_name = NULL; int scale = 1000; - int app_status; + int app_status = 0; GOptionEntry entries[] = { + {"version", 'v', 0, G_OPTION_ARG_NONE, &version, "Print version", NULL}, {"tikz", 't', 0, G_OPTION_ARG_NONE, &tikz, "Output TikZ code", NULL }, {"pdf", 'p', 0, G_OPTION_ARG_NONE, &pdf, "Output PDF document", NULL }, //{"svg", 'S', 0, G_OPTION_ARG_NONE, &svg, "Output SVG image", NULL }, @@ -145,6 +154,11 @@ int main(int argc, char **argv) exit(1); } + if (version) { + print_version(); + goto ret_status; + } + if (argc >= 2) { if (scale < 1) { printf("Scale < 1 not allowed. Setting to 1\n"); @@ -188,5 +202,6 @@ int main(int argc, char **argv) app_status = start_gui(argc, argv); } +ret_status: return app_status; } diff --git a/version/CMakeLists.txt b/version/CMakeLists.txt new file mode 100644 index 0000000..0efa079 --- /dev/null +++ b/version/CMakeLists.txt @@ -0,0 +1,5 @@ +add_library(version STATIC "version.c") +execute_process(COMMAND bash ./generate-version-string.sh + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE GIT_VER) +target_compile_definitions(version PUBLIC PROJECT_GIT_VERSION=${GIT_VER}) diff --git a/version/generate-version-string.sh b/version/generate-version-string.sh new file mode 100755 index 0000000..b807569 --- /dev/null +++ b/version/generate-version-string.sh @@ -0,0 +1 @@ +git describe --tags diff --git a/version/version.c b/version/version.c new file mode 100644 index 0000000..b25a2d7 --- /dev/null +++ b/version/version.c @@ -0,0 +1,34 @@ +/* + * GDSII-Converter + * Copyright (C) 2018 Mario Hüttel + * + * This file is part of GDSII-Converter. + * + * GDSII-Converter is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * GDSII-Converter is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GDSII-Converter. If not, see . + */ + +/** + * @addtogroup MainApplication + * @{ + */ + +#ifdef PROJECT_GIT_VERSION + +#define xstr(a) str(a) +#define str(a) #a +const char *_app_version_string = xstr(PROJECT_GIT_VERSION); +#else +const char *_app_version_string = "! version not set !"; +#endif + +/** @} */ diff --git a/version/version.h b/version/version.h new file mode 100644 index 0000000..27b7cc3 --- /dev/null +++ b/version/version.h @@ -0,0 +1,28 @@ +/* + * GDSII-Converter + * Copyright (C) 2018 Mario Hüttel + * + * This file is part of GDSII-Converter. + * + * GDSII-Converter is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * GDSII-Converter is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GDSII-Converter. If not, see . + */ + +/** + * @addtogroup MainApplication + * @{ + */ + +/** @brief This string holds the 'git describe' version of the app */ +extern char *_app_version_string; + +/** @} */