From fa9dda01e6c013c7fe9be99b21d8bbf3c95c0482 Mon Sep 17 00:00:00 2001 From: albert-github Date: Sun, 7 Apr 2019 15:10:53 +0200 Subject: Show git version information Show the git version on designated places (currently version, help and Doxyfile difference). The implementation is based on the git_watcher.cmake (https://github.com/andrew-hardin/cmake-git-version-tracking). The information is useful to see which. master, version of doxygen is used for a build on systems where a lot of builds are make (Fossies.org) or very regular builds are made (CGAL) Furthermore the tracking of the VERSION file was not done (when changed the version.cpp was not updated), this is corrected as well. --- CMakeLists.txt | 6 +- addon/doxywizard/CMakeLists.txt | 6 +- cmake/git_watcher.cmake | 213 ++++++++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 10 +- src/configimpl.l | 7 +- src/doxygen.cpp | 29 +++++- src/gitversion.cpp.in | 14 +++ src/version.h | 2 + src/version.py | 23 +++++ 9 files changed, 301 insertions(+), 9 deletions(-) create mode 100644 cmake/git_watcher.cmake create mode 100644 src/gitversion.cpp.in create mode 100644 src/version.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 6bf9246..c116bbb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ # Documents produced by Doxygen are derivative works derived from the # input used in their production; they are not affected by this license. -cmake_minimum_required(VERSION 3.1.3) +cmake_minimum_required(VERSION 3.2) project(doxygen) option(build_wizard "Build the GUI frontend for doxygen." OFF) @@ -110,6 +110,10 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${EXECUTABLE_OUTPUT_PATH}) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${EXECUTABLE_OUTPUT_PATH}) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${EXECUTABLE_OUTPUT_PATH}) +# setup information for git version handling +set(PRE_CONFIGURE_GIT_VERSION_FILE "${CMAKE_SOURCE_DIR}/src/gitversion.cpp.in") +set(POST_CONFIGURE_GIT_VERSION_FILE "${GENERATED_SRC}/gitversion.cpp") + # gather lang codes for translation file(GLOB lang_files RELATIVE "${CMAKE_SOURCE_DIR}/src" "${CMAKE_SOURCE_DIR}/src/translator_??.h") if (english_only) # user only wants English diff --git a/addon/doxywizard/CMakeLists.txt b/addon/doxywizard/CMakeLists.txt index a89864d..c61c737 100644 --- a/addon/doxywizard/CMakeLists.txt +++ b/addon/doxywizard/CMakeLists.txt @@ -57,8 +57,10 @@ CONTENT "#ifndef SETTINGS_H set_source_files_properties(${GENERATED_SRC_WIZARD}/settings.h PROPERTIES GENERATED 1) # generate version.cpp -file(GENERATE OUTPUT ${GENERATED_SRC_WIZARD}/version.cpp - CONTENT "char versionString[]=\"${VERSION}\";" +add_custom_command( + COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/src/version.py ${VERSION} > ${GENERATED_SRC_WIZARD}/version.cpp + DEPENDS ${CMAKE_SOURCE_DIR}/VERSION ${CMAKE_SOURCE_DIR}/src/version.py + OUTPUT ${GENERATED_SRC_WIZARD}/version.cpp ) set_source_files_properties(${GENERATED_SRC_WIZARD}/version.cpp PROPERTIES GENERATED 1) diff --git a/cmake/git_watcher.cmake b/cmake/git_watcher.cmake new file mode 100644 index 0000000..6447b86 --- /dev/null +++ b/cmake/git_watcher.cmake @@ -0,0 +1,213 @@ +# git_watcher.cmake +# +# License: MIT +# Source: https://raw.githubusercontent.com/andrew-hardin/cmake-git-version-tracking/master/git_watcher.cmake + + +# This file defines the functions and targets needed to monitor +# the state of a git repo. If the state changes (e.g. a commit is made), +# then a file gets reconfigured. +# +# The behavior of this script can be modified by defining any of these variables: +# +# PRE_CONFIGURE_GIT_VERSION_FILE (REQUIRED) +# -- The path to the file that'll be configured. +# +# POST_CONFIGURE_GIT_VERSION_FILE (REQUIRED) +# -- The path to the configured PRE_CONFIGURE_GIT_VERSION_FILE. +# +# GIT_STATE_FILE (OPTIONAL) +# -- The path to the file used to store the previous build's git state. +# Defaults to the current binary directory. +# +# GIT_WORKING_DIR (OPTIONAL) +# -- The directory from which git commands will be run. +# Defaults to the directory with the top level CMakeLists.txt. +# +# GIT_EXECUTABLE (OPTIONAL) +# -- The path to the git executable. It'll automatically be set if the +# user doesn't supply a path. +# +# Script design: +# - This script was designed similar to a Python application +# with a Main() function. I wanted to keep it compact to +# simplify "copy + paste" usage. +# +# - This script is made to operate in two CMake contexts: +# 1. Configure time context (when build files are created). +# 2. Build time context (called via CMake -P) +# If you see something odd (e.g. the NOT DEFINED clauses), +# consider that it can run in one of two contexts. + +# Short hand for converting paths to absolute. +macro(PATH_TO_ABSOLUTE var_name) + get_filename_component(${var_name} "${${var_name}}" ABSOLUTE) +endmacro() + +# Check that a required variable is set. +macro(CHECK_REQUIRED_VARIABLE var_name) + if(NOT DEFINED ${var_name}) + message(FATAL_ERROR "The \"${var_name}\" variable must be defined.") + endif() + PATH_TO_ABSOLUTE(${var_name}) +endmacro() + +# Check that an optional variable is set, or, set it to a default value. +macro(CHECK_OPTIONAL_VARIABLE var_name default_value) + if(NOT DEFINED ${var_name}) + set(${var_name} ${default_value}) + endif() + PATH_TO_ABSOLUTE(${var_name}) +endmacro() + +CHECK_REQUIRED_VARIABLE(PRE_CONFIGURE_GIT_VERSION_FILE) +CHECK_REQUIRED_VARIABLE(POST_CONFIGURE_GIT_VERSION_FILE) +CHECK_OPTIONAL_VARIABLE(GIT_STATE_FILE "${GENERATED_SRC}/git_state") +#CHECK_REQUIRED_VARIABLE(GIT_STATE_FILE) +CHECK_OPTIONAL_VARIABLE(GIT_WORKING_DIR "${CMAKE_SOURCE_DIR}") + +# Check the optional git variable. +# If it's not set, we'll try to find it using the CMake packaging system. +if(NOT DEFINED GIT_EXECUTABLE) + find_package(Git QUIET REQUIRED) +endif() +CHECK_REQUIRED_VARIABLE(GIT_EXECUTABLE) + + + +# Function: GitStateChangedAction +# Description: this function is executed when the state of the git +# repo changes (e.g. a commit is made). +function(GitStateChangedAction _state_as_list) + # Set variables by index, then configure the file w/ these variables defined. + LIST(GET _state_as_list 0 GIT_RETRIEVED_STATE) + LIST(GET _state_as_list 1 GIT_HEAD_SHA1) + LIST(GET _state_as_list 2 GIT_IS_DIRTY) + configure_file("${PRE_CONFIGURE_GIT_VERSION_FILE}" "${POST_CONFIGURE_GIT_VERSION_FILE}" @ONLY) +endfunction() + + + +# Function: GetGitState +# Description: gets the current state of the git repo. +# Args: +# _working_dir (in) string; the directory from which git commands will be executed. +# _state (out) list; a collection of variables representing the state of the +# repository (e.g. commit SHA). +function(GetGitState _working_dir _state) + + # Get the hash for HEAD. + set(_success "true") + execute_process(COMMAND + "${GIT_EXECUTABLE}" rev-parse --verify HEAD + WORKING_DIRECTORY "${_working_dir}" + RESULT_VARIABLE res + OUTPUT_VARIABLE _hashvar + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + if(NOT res EQUAL 0) + set(_success "false") + set(_hashvar "GIT-NOTFOUND") + endif() + + # Get whether or not the working tree is dirty. + execute_process(COMMAND + "${GIT_EXECUTABLE}" status --porcelain + WORKING_DIRECTORY "${_working_dir}" + RESULT_VARIABLE res + OUTPUT_VARIABLE out + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + if(NOT res EQUAL 0) + set(_success "false") + set(_dirty "false") + else() + if(NOT "${out}" STREQUAL "") + set(_dirty "true") + else() + set(_dirty "false") + endif() + endif() + + # Return a list of our variables to the parent scope. + set(${_state} ${_success} ${_hashvar} ${_dirty} PARENT_SCOPE) +endfunction() + + + +# Function: CheckGit +# Description: check if the git repo has changed. If so, update the state file. +# Args: +# _working_dir (in) string; the directory from which git commands will be ran. +# _state_changed (out) bool; whether or no the state of the repo has changed. +# _state (out) list; the repository state as a list (e.g. commit SHA). +function(CheckGit _working_dir _state_changed _state) + + # Get the current state of the repo. + GetGitState("${_working_dir}" state) + + # Set the output _state variable. + # (Passing by reference in CMake is awkward...) + set(${_state} ${state} PARENT_SCOPE) + + # Check if the state has changed compared to the backup on disk. + if(EXISTS "${GIT_STATE_FILE}") + file(READ "${GIT_STATE_FILE}" OLD_HEAD_CONTENTS) + if(OLD_HEAD_CONTENTS STREQUAL "${state}") + # State didn't change. + set(${_state_changed} "false" PARENT_SCOPE) + return() + endif() + endif() + + # The state has changed. + # We need to update the state file on disk. + # Future builds will compare their state to this file. + file(WRITE "${GIT_STATE_FILE}" "${state}") + set(${_state_changed} "true" PARENT_SCOPE) +endfunction() + + + +# Function: SetupGitMonitoring +# Description: this function sets up custom commands that make the build system +# check the state of git before every build. If the state has +# changed, then a file is configured. +function(SetupGitMonitoring) + add_custom_target(check_git_repository + ALL + DEPENDS ${PRE_CONFIGURE_GIT_VERSION_FILE} + BYPRODUCTS ${POST_CONFIGURE_GIT_VERSION_FILE} + COMMENT "Checking the git repository for changes..." + COMMAND + ${CMAKE_COMMAND} + -D_BUILD_TIME_CHECK_GIT=TRUE + -DGIT_WORKING_DIR=${GIT_WORKING_DIR} + -DGIT_EXECUTABLE=${GIT_EXECUTABLE} + -DGIT_STATE_FILE=${GIT_STATE_FILE} + -DPRE_CONFIGURE_GIT_VERSION_FILE=${PRE_CONFIGURE_GIT_VERSION_FILE} + -DPOST_CONFIGURE_GIT_VERSION_FILE=${POST_CONFIGURE_GIT_VERSION_FILE} + -P "${CMAKE_CURRENT_LIST_FILE}") +endfunction() + + + +# Function: Main +# Description: primary entry-point to the script. Functions are selected based +# on whether it's configure or build time. +function(Main) + if(_BUILD_TIME_CHECK_GIT) + # Check if the repo has changed. + # If so, run the change action. + CheckGit("${GIT_WORKING_DIR}" did_change state) + if(did_change) + GitStateChangedAction("${state}") + endif() + else() + # >> Executes at configure time. + SetupGitMonitoring() + endif() +endfunction() + +# And off we go... +Main() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 92a302a..9539228 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,7 @@ # vim:ts=4:sw=4:expandtab:autoindent: +include(${CMAKE_SOURCE_DIR}/cmake/git_watcher.cmake) + include_directories( ${CMAKE_SOURCE_DIR}/qtools ${CMAKE_SOURCE_DIR}/libmd5 @@ -31,8 +33,10 @@ set_source_files_properties(${GENERATED_SRC}/settings.h PROPERTIES GENERATED 1) # generate version.cpp -file(GENERATE OUTPUT ${GENERATED_SRC}/version.cpp - CONTENT "char versionString[]=\"${VERSION}\";" +add_custom_command( + COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/src/version.py ${VERSION} > ${GENERATED_SRC}/version.cpp + DEPENDS ${CMAKE_SOURCE_DIR}/VERSION ${CMAKE_SOURCE_DIR}/src/version.py + OUTPUT ${GENERATED_SRC}/version.cpp ) set_source_files_properties(${GENERATED_SRC}/version.cpp PROPERTIES GENERATED 1) @@ -137,6 +141,7 @@ add_library(_doxygen STATIC ${GENERATED_SRC}/settings.h ${GENERATED_SRC}/layout_default.xml.h ${GENERATED_SRC}/version.cpp + ${POST_CONFIGURE_GIT_VERSION_FILE} ${GENERATED_SRC}/ce_parse.h ${GENERATED_SRC}/configvalues.h ${GENERATED_SRC}/resources.cpp @@ -240,6 +245,7 @@ add_library(_doxygen STATIC docbookvisitor.cpp docbookgen.cpp ) +add_dependencies( _doxygen check_git_repository ) add_executable(doxygen main.cpp) diff --git a/src/configimpl.l b/src/configimpl.l index 644250f..321ca5c 100644 --- a/src/configimpl.l +++ b/src/configimpl.l @@ -964,7 +964,12 @@ void ConfigImpl::writeTemplate(FTextStream &t,bool sl,bool upd) void ConfigImpl::compareDoxyfile(FTextStream &t) { - t << "# Difference with default Doxyfile " << versionString << endl; + t << "# Difference with default Doxyfile " << versionString; + if (strlen(gitVersionString)) + { + t << " (" << gitVersionString << ")"; + } + t << endl; QListIterator it = iterator(); ConfigOption *option; for (;(option=it.current());++it) diff --git a/src/doxygen.cpp b/src/doxygen.cpp index 99878a5..aabb688 100644 --- a/src/doxygen.cpp +++ b/src/doxygen.cpp @@ -9927,7 +9927,14 @@ static void devUsage() static void usage(const char *name) { - msg("Doxygen version %s\nCopyright Dimitri van Heesch 1997-2015\n\n",versionString); + if (strlen(gitVersionString)) + { + msg("Doxygen version %s (%s)\nCopyright Dimitri van Heesch 1997-2015\n\n",versionString,gitVersionString); + } + else + { + msg("Doxygen version %s\nCopyright Dimitri van Heesch 1997-2015\n\n",versionString); + } msg("You can use doxygen in a number of ways:\n\n"); msg("1) Use doxygen to generate a template configuration file:\n"); msg(" %s [-s] -g [configName]\n\n",name); @@ -9982,6 +9989,8 @@ void initDoxygen() setlocale(LC_CTYPE,"C"); // to get isspace(0xA0)==0, needed for UTF-8 setlocale(LC_NUMERIC,"C"); + correctGitVersion(); + portable_correct_path(); Doxygen::runningTime.start(); @@ -10387,7 +10396,14 @@ void readConfiguration(int argc, char **argv) g_dumpSymbolMap = TRUE; break; case 'v': - msg("%s\n",versionString); + if (strlen(gitVersionString)) + { + msg("%s (%s)\n",versionString,gitVersionString); + } + else + { + msg("%s\n",versionString); + } cleanUpDoxygen(); exit(0); break; @@ -10399,7 +10415,14 @@ void readConfiguration(int argc, char **argv) } else if (qstrcmp(&argv[optind][2],"version")==0) { - msg("%s\n",versionString); + if (strlen(gitVersionString)) + { + msg("%s (%s)\n",versionString,gitVersionString); + } + else + { + msg("%s\n",versionString); + } cleanUpDoxygen(); exit(0); } diff --git a/src/gitversion.cpp.in b/src/gitversion.cpp.in new file mode 100644 index 0000000..cbb9b13 --- /dev/null +++ b/src/gitversion.cpp.in @@ -0,0 +1,14 @@ +#include + +char gitVersionString[]="@GIT_HEAD_SHA1@"; + +/* - On some systems git is not installed or + * installed on a place whete FindGit.cmake cannot find it + * - No git information is present (no .git directory) + * in those cases clear the gitVersionString (would have string GIT-NOTFOUND). + */ +void correctGitVersion(void) +{ + if (!strcmp(gitVersionString, "GIT-NOTFOUND")) gitVersionString[0] = '\0'; +} + diff --git a/src/version.h b/src/version.h index 16bf9df..09d1b4f 100644 --- a/src/version.h +++ b/src/version.h @@ -19,5 +19,7 @@ #define VERSION_H extern char versionString[]; +extern char gitVersionString[]; +void correctGitVersion(void); #endif diff --git a/src/version.py b/src/version.py new file mode 100644 index 0000000..4aedee0 --- /dev/null +++ b/src/version.py @@ -0,0 +1,23 @@ +#!/usr/bin/python +# python script to generate version.cpp from first argument +# +# Copyright (C) 1997-2018 by Dimitri van Heesch. +# +# Permission to use, copy, modify, and distribute this software and its +# documentation under the terms of the GNU General Public License is hereby +# granted. No representations are made about the suitability of this software +# for any purpose. It is provided "as is" without express or implied warranty. +# See the GNU General Public License for more details. +# +# Documents produced by Doxygen are derivative works derived from the +# input used in their production; they are not affected by this license. +# +import sys + +def main(): + if len(sys.argv)<2: + sys.exit('Usage: %s ' % sys.argv[0]) + print('char versionString[]="%s";' % sys.argv[1]) + +if __name__ == '__main__': + main() -- cgit v0.12 From 4ad23e5d18fc294e00844fd8557f8c5dd6254d6e Mon Sep 17 00:00:00 2001 From: albert-github Date: Fri, 31 May 2019 20:03:45 +0200 Subject: Show git version information The original version has as features: - getting the git version number for usage in doxygen - making the doxygen version number inclusion dependent on the VERSION file The disadvantage of the chosen methodology was that an extra correction step was necessary, by defining getter methods to retrieve the values this correction can be hidden. The information is coming from different sources: - the VERSION file - the git "repository and build system (when present) Furthermore there are a couple of places where the version information is used (a.o. doxygen and doxywizard executable, though the doxygenwizard was only done "half hearted") The handling of the VERSION file has been made in such a way that it is comparable with the generation of the git version changes. For a better abstraction the version handling is all done in a separate directory. --- CMakeLists.txt | 5 +-- addon/doxyapp/CMakeLists.txt | 2 + addon/doxyparse/CMakeLists.txt | 2 + addon/doxywizard/CMakeLists.txt | 6 +-- addon/doxywizard/doxywizard.cpp | 2 +- addon/doxywizard/expert.cpp | 2 +- addon/doxywizard/version.h | 23 ---------- cmake/doxygen_version.cmake | 96 +++++++++++++++++++++++++++++++++++++++++ libversion/CMakeLists.txt | 27 ++++++++++++ libversion/doxyversion.cpp.in | 7 +++ libversion/gitversion.cpp.in | 16 +++++++ libversion/version.h | 22 ++++++++++ src/CMakeLists.txt | 15 +------ src/configimpl.l | 8 ++-- src/context.cpp | 2 +- src/doxygen.cpp | 20 ++++----- src/htmlgen.cpp | 18 ++++---- src/latexgen.cpp | 8 ++-- src/layout.cpp | 2 +- src/resourcemgr.cpp | 2 +- src/rtfgen.cpp | 4 +- src/searchindex.cpp | 2 +- src/sqlite3gen.cpp | 2 +- src/util.cpp | 2 +- src/version.py | 23 ---------- src/xmlgen.cpp | 4 +- 26 files changed, 216 insertions(+), 106 deletions(-) delete mode 100644 addon/doxywizard/version.h create mode 100644 cmake/doxygen_version.cmake create mode 100644 libversion/CMakeLists.txt create mode 100644 libversion/doxyversion.cpp.in create mode 100644 libversion/gitversion.cpp.in create mode 100644 libversion/version.h delete mode 100644 src/version.py diff --git a/CMakeLists.txt b/CMakeLists.txt index c116bbb..05ab57b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -110,10 +110,6 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${EXECUTABLE_OUTPUT_PATH}) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${EXECUTABLE_OUTPUT_PATH}) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${EXECUTABLE_OUTPUT_PATH}) -# setup information for git version handling -set(PRE_CONFIGURE_GIT_VERSION_FILE "${CMAKE_SOURCE_DIR}/src/gitversion.cpp.in") -set(POST_CONFIGURE_GIT_VERSION_FILE "${GENERATED_SRC}/gitversion.cpp") - # gather lang codes for translation file(GLOB lang_files RELATIVE "${CMAKE_SOURCE_DIR}/src" "${CMAKE_SOURCE_DIR}/src/translator_??.h") if (english_only) # user only wants English @@ -147,6 +143,7 @@ endif() add_subdirectory(libmd5) +add_subdirectory(libversion) add_subdirectory(qtools) add_subdirectory(vhdlparser) add_subdirectory(src) diff --git a/addon/doxyapp/CMakeLists.txt b/addon/doxyapp/CMakeLists.txt index 4fd1816..84c0ee8 100644 --- a/addon/doxyapp/CMakeLists.txt +++ b/addon/doxyapp/CMakeLists.txt @@ -10,6 +10,7 @@ find_package(Iconv) include_directories( ${CMAKE_SOURCE_DIR}/src + ${CMAKE_SOURCE_DIR}/libversion ${GENERATED_SRC} ${CMAKE_SOURCE_DIR}/qtools ${ICONV_INCLUDE_DIR} @@ -23,6 +24,7 @@ target_link_libraries(doxyapp _doxygen qtools md5 +version doxycfg vhdlparser ${ICONV_LIBRARIES} diff --git a/addon/doxyparse/CMakeLists.txt b/addon/doxyparse/CMakeLists.txt index 8e7536f..498169f 100644 --- a/addon/doxyparse/CMakeLists.txt +++ b/addon/doxyparse/CMakeLists.txt @@ -10,6 +10,7 @@ find_package(Iconv) include_directories( ${CMAKE_SOURCE_DIR}/src + ${CMAKE_SOURCE_DIR}/libversion ${GENERATED_SRC} ${CMAKE_SOURCE_DIR}/qtools ${ICONV_INCLUDE_DIR} @@ -23,6 +24,7 @@ target_link_libraries(doxyparse _doxygen qtools md5 +version doxycfg vhdlparser ${ICONV_LIBRARIES} diff --git a/addon/doxywizard/CMakeLists.txt b/addon/doxywizard/CMakeLists.txt index c61c737..9aba4e4 100644 --- a/addon/doxywizard/CMakeLists.txt +++ b/addon/doxywizard/CMakeLists.txt @@ -30,6 +30,7 @@ endif() include_directories( . + ${CMAKE_SOURCE_DIR}/libversion ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/qtools ${GENERATED_SRC} @@ -95,7 +96,6 @@ inputstring.cpp inputint.cpp inputstrlist.cpp ${GENERATED_SRC_WIZARD}/settings.h -${GENERATED_SRC_WIZARD}/version.cpp ${GENERATED_SRC_WIZARD}/config_doxyw.cpp ${GENERATED_SRC_WIZARD}/configdoc.cpp ${doxywizard_MOC} @@ -104,9 +104,9 @@ doxywizard.rc ) if(Qt5Core_FOUND) - target_link_libraries(doxywizard Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Xml) + target_link_libraries(doxywizard Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Xml version) else() - target_link_libraries(doxywizard ${QT_LIBRARIES} ${QT_QTMAIN_LIBRARY}) + target_link_libraries(doxywizard ${QT_LIBRARIES} ${QT_QTMAIN_LIBRARY} version) endif() install(TARGETS doxywizard DESTINATION bin) diff --git a/addon/doxywizard/doxywizard.cpp b/addon/doxywizard/doxywizard.cpp index 56378ed..02e8cd0 100755 --- a/addon/doxywizard/doxywizard.cpp +++ b/addon/doxywizard/doxywizard.cpp @@ -216,7 +216,7 @@ void MainWindow::about() QString msg; QTextStream t(&msg,QIODevice::WriteOnly); t << QString::fromLatin1("
A tool to configure and run doxygen version ")+ - QString::fromLatin1(versionString)+ + QString::fromLatin1(getVersion())+ QString::fromLatin1(" on your source files.


" "

Written by
Dimitri van Heesch
© 2000-2015

" ""); diff --git a/addon/doxywizard/expert.cpp b/addon/doxywizard/expert.cpp index 44dea78..c875d8d 100644 --- a/addon/doxywizard/expert.cpp +++ b/addon/doxywizard/expert.cpp @@ -781,7 +781,7 @@ void Expert::saveTopic(QTextStream &t,QDomElement &elem,QTextCodec *codec, bool Expert::writeConfig(QTextStream &t,bool brief) { // write global header - t << "# Doxyfile " << versionString << endl << endl; + t << "# Doxyfile " << getVersion() << endl << endl; if (!brief) { t << convertToComment(m_header); diff --git a/addon/doxywizard/version.h b/addon/doxywizard/version.h deleted file mode 100644 index 16bf9df..0000000 --- a/addon/doxywizard/version.h +++ /dev/null @@ -1,23 +0,0 @@ -/****************************************************************************** - * - * - * - * Copyright (C) 1997-2015 by Dimitri van Heesch. - * - * Permission to use, copy, modify, and distribute this software and its - * documentation under the terms of the GNU General Public License is hereby - * granted. No representations are made about the suitability of this software - * for any purpose. It is provided "as is" without express or implied warranty. - * See the GNU General Public License for more details. - * - * Documents produced by Doxygen are derivative works derived from the - * input used in their production; they are not affected by this license. - * - */ - -#ifndef VERSION_H -#define VERSION_H - -extern char versionString[]; - -#endif diff --git a/cmake/doxygen_version.cmake b/cmake/doxygen_version.cmake new file mode 100644 index 0000000..2433889 --- /dev/null +++ b/cmake/doxygen_version.cmake @@ -0,0 +1,96 @@ +# doxygen_version.cmake +# + +# This file defines the functions and targets needed to monitor +# doxygen VERSION file. +# +# The behavior of this script can be modified by defining any of these variables: +# +# PRE_CONFIGURE_DOXYGEN_VERSION_FILE (REQUIRED) +# -- The path to the file that'll be configured. +# +# POST_CONFIGURE_DOXYGEN_VERSION_FILE (REQUIRED) +# -- The path to the configured PRE_CONFIGURE_DOXYGEN_VERSION_FILE. +# +# DOXY_STATE_FILE (OPTIONAL) +# -- The path to the file used to store the doxygen version information. +# +# This file is based on git_watcher.cmake + +# Short hand for converting paths to absolute. +macro(PATH_TO_ABSOLUTE var_name) + get_filename_component(${var_name} "${${var_name}}" ABSOLUTE) +endmacro() + +# Check that a required variable is set. +macro(CHECK_REQUIRED_VARIABLE var_name) + if(NOT DEFINED ${var_name}) + message(FATAL_ERROR "The \"${var_name}\" variable must be defined.") + endif() + PATH_TO_ABSOLUTE(${var_name}) +endmacro() + +# Check that an optional variable is set, or, set it to a default value. +macro(CHECK_OPTIONAL_VARIABLE var_name default_value) + if(NOT DEFINED ${var_name}) + set(${var_name} ${default_value}) + endif() + PATH_TO_ABSOLUTE(${var_name}) +endmacro() + +CHECK_REQUIRED_VARIABLE(PRE_CONFIGURE_DOXYGEN_VERSION_FILE) +CHECK_REQUIRED_VARIABLE(POST_CONFIGURE_DOXYGEN_VERSION_FILE) +CHECK_OPTIONAL_VARIABLE(DOXY_STATE_FILE "${CMAKE_SOURCE_DIR}/VERSION") + +# Function: DoxygenStateChangedAction +# Description: this function is executed when the +# doxygen version file has changed. +function(DoxygenStateChangedAction _state_as_list) + # Set variables by index, then configure the file w/ these variables defined. + LIST(GET _state_as_list 0 DOXYGEN_VERSION) + configure_file("${PRE_CONFIGURE_DOXYGEN_VERSION_FILE}" "${POST_CONFIGURE_DOXYGEN_VERSION_FILE}" @ONLY) +endfunction() + + + +# Function: SetupDoxyMonitoring +# Description: this function sets up custom commands that make the build system +# check the doxygen version file before every build. If it has +# changed, then a file is configured. +function(SetupDoxyMonitoring) + add_custom_target(check_doxygen_version + ALL + DEPENDS ${PRE_CONFIGURE_DOXYGEN_VERSION_FILE} + BYPRODUCTS ${POST_CONFIGURE_DOXYGEN_VERSION_FILE} + COMMENT "Checking the doxygen version for changes..." + COMMAND + ${CMAKE_COMMAND} + -D_BUILD_TIME_CHECK_DOXY=TRUE + -DDOXY_STATE_FILE=${DOXY_STATE_FILE} + -DPRE_CONFIGURE_DOXYGEN_VERSION_FILE=${PRE_CONFIGURE_DOXYGEN_VERSION_FILE} + -DPOST_CONFIGURE_DOXYGEN_VERSION_FILE=${POST_CONFIGURE_DOXYGEN_VERSION_FILE} + -P "${CMAKE_CURRENT_LIST_FILE}") +endfunction() + + + +# Function: Main +# Description: primary entry-point to the script. Functions are selected based +# on whether it's configure or build time. +function(Main) + file(STRINGS "${DOXY_STATE_FILE}" DOXYGEN_VERSION) + if(_BUILD_TIME_CHECK_DOXY) + # Check if the doxygen version file has changed. + # If so, run the change action. + if(${DOXY_STATE_FILE} IS_NEWER_THAN ${POST_CONFIGURE_DOXYGEN_VERSION_FILE}) + DoxygenStateChangedAction("${DOXYGEN_VERSION}") + endif() + else() + # >> Executes at configure time. + SetupDoxyMonitoring() + DoxygenStateChangedAction("${DOXYGEN_VERSION}") + endif() +endfunction() + +# And off we go... +Main() diff --git a/libversion/CMakeLists.txt b/libversion/CMakeLists.txt new file mode 100644 index 0000000..1a430fd --- /dev/null +++ b/libversion/CMakeLists.txt @@ -0,0 +1,27 @@ +# vim:ts=4:sw=4:expandtab:autoindent: + +# setup information for doxygen version handling +set(PRE_CONFIGURE_DOXYGEN_VERSION_FILE "${CMAKE_SOURCE_DIR}/libversion/doxyversion.cpp.in") +set(POST_CONFIGURE_DOXYGEN_VERSION_FILE "${GENERATED_SRC}/doxyversion.cpp") + +# setup information for git version handling +set(PRE_CONFIGURE_GIT_VERSION_FILE "${CMAKE_SOURCE_DIR}/libversion/gitversion.cpp.in") +set(POST_CONFIGURE_GIT_VERSION_FILE "${GENERATED_SRC}/gitversion.cpp") + +include(${CMAKE_SOURCE_DIR}/cmake/git_watcher.cmake) +include(${CMAKE_SOURCE_DIR}/cmake/doxygen_version.cmake) + +include_directories( + . +) + +add_library(version STATIC + ${POST_CONFIGURE_DOXYGEN_VERSION_FILE} + ${POST_CONFIGURE_GIT_VERSION_FILE} +) + +add_dependencies( version check_git_repository ) +add_dependencies( version check_doxygen_version ) + +set_source_files_properties(${POST_CONFIGURE_GIT_VERSION_FILE} PROPERTIES GENERATED 1) +set_source_files_properties(${POST_CONFIGURE_DOXYGEN_VERSION_FILE} PROPERTIES GENERATED 1) diff --git a/libversion/doxyversion.cpp.in b/libversion/doxyversion.cpp.in new file mode 100644 index 0000000..11bca8d --- /dev/null +++ b/libversion/doxyversion.cpp.in @@ -0,0 +1,7 @@ +#include "version.h" + +char *getVersion(void) +{ + static char versionString[] = "@DOXYGEN_VERSION@"; + return versionString; +} diff --git a/libversion/gitversion.cpp.in b/libversion/gitversion.cpp.in new file mode 100644 index 0000000..164b50b --- /dev/null +++ b/libversion/gitversion.cpp.in @@ -0,0 +1,16 @@ +#include +#include + +/* - On some systems git is not installed or + * installed on a place where FindGit.cmake cannot find it + * - No git information is present (no .git directory) + * in those cases clear the gitVersionString (would have string GIT-NOTFOUND). + */ +char *getGitVersion(void) +{ + static char gitVersionString[100]; + strcpy(gitVersionString,"@GIT_HEAD_SHA1@"); + strcat(gitVersionString,!strcmp("@GIT_IS_DIRTY@","true")?"*":""); + if (!strcmp("@GIT_HEAD_SHA1@", "GIT-NOTFOUND")) gitVersionString[0] = '\0'; + return gitVersionString; +} diff --git a/libversion/version.h b/libversion/version.h new file mode 100644 index 0000000..a656e74 --- /dev/null +++ b/libversion/version.h @@ -0,0 +1,22 @@ +/****************************************************************************** + * + * + * + * Copyright (C) 1997-2015 by Dimitri van Heesch. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation under the terms of the GNU General Public License is hereby + * granted. No representations are made about the suitability of this software + * for any purpose. It is provided "as is" without express or implied warranty. + * See the GNU General Public License for more details. + * + * Documents produced by Doxygen are derivative works derived from the + * input used in their production; they are not affected by this license. + * + */ + +#ifndef VERSION_H +#define VERSION_H +char *getVersion(void); +char *getGitVersion(void); +#endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9539228..f4e1231 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,10 +1,9 @@ # vim:ts=4:sw=4:expandtab:autoindent: -include(${CMAKE_SOURCE_DIR}/cmake/git_watcher.cmake) - include_directories( ${CMAKE_SOURCE_DIR}/qtools ${CMAKE_SOURCE_DIR}/libmd5 + ${CMAKE_SOURCE_DIR}/libversion ${CMAKE_SOURCE_DIR}/vhdlparser/ ${CMAKE_SOURCE_DIR}/src ${CLANG_INCLUDEDIR} @@ -32,14 +31,6 @@ CONTENT "#ifndef SETTINGS_H set_source_files_properties(${GENERATED_SRC}/settings.h PROPERTIES GENERATED 1) -# generate version.cpp -add_custom_command( - COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/src/version.py ${VERSION} > ${GENERATED_SRC}/version.cpp - DEPENDS ${CMAKE_SOURCE_DIR}/VERSION ${CMAKE_SOURCE_DIR}/src/version.py - OUTPUT ${GENERATED_SRC}/version.cpp -) -set_source_files_properties(${GENERATED_SRC}/version.cpp PROPERTIES GENERATED 1) - # configvalues.h add_custom_command( COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/src/configgen.py -maph ${CMAKE_SOURCE_DIR}/src/config.xml > ${GENERATED_SRC}/configvalues.h @@ -140,8 +131,6 @@ add_library(_doxygen STATIC ${GENERATED_SRC}/lang_cfg.h ${GENERATED_SRC}/settings.h ${GENERATED_SRC}/layout_default.xml.h - ${GENERATED_SRC}/version.cpp - ${POST_CONFIGURE_GIT_VERSION_FILE} ${GENERATED_SRC}/ce_parse.h ${GENERATED_SRC}/configvalues.h ${GENERATED_SRC}/resources.cpp @@ -245,7 +234,6 @@ add_library(_doxygen STATIC docbookvisitor.cpp docbookgen.cpp ) -add_dependencies( _doxygen check_git_repository ) add_executable(doxygen main.cpp) @@ -274,6 +262,7 @@ target_link_libraries(doxygen doxycfg qtools md5 + version vhdlparser ${SQLITE3_LIBRARIES} ${ICONV_LIBRARIES} diff --git a/src/configimpl.l b/src/configimpl.l index 321ca5c..f07509a 100644 --- a/src/configimpl.l +++ b/src/configimpl.l @@ -943,7 +943,7 @@ void ConfigImpl::writeTemplate(FTextStream &t,bool sl,bool upd) { t << takeStartComment() << endl; } - t << "# Doxyfile " << versionString << endl << endl; + t << "# Doxyfile " << getVersion() << endl << endl; if (!sl) { t << convertToComment(m_header,""); @@ -964,10 +964,10 @@ void ConfigImpl::writeTemplate(FTextStream &t,bool sl,bool upd) void ConfigImpl::compareDoxyfile(FTextStream &t) { - t << "# Difference with default Doxyfile " << versionString; - if (strlen(gitVersionString)) + t << "# Difference with default Doxyfile " << getVersion(); + if (strlen(getGitVersion())) { - t << " (" << gitVersionString << ")"; + t << " (" << getGitVersion() << ")"; } t << endl; QListIterator it = iterator(); diff --git a/src/context.cpp b/src/context.cpp index 7b7c725..e14907f 100644 --- a/src/context.cpp +++ b/src/context.cpp @@ -374,7 +374,7 @@ class DoxygenContext::Private public: TemplateVariant version() const { - return versionString; + return getVersion(); } TemplateVariant date() const { diff --git a/src/doxygen.cpp b/src/doxygen.cpp index aabb688..9c98d8c 100644 --- a/src/doxygen.cpp +++ b/src/doxygen.cpp @@ -9927,13 +9927,13 @@ static void devUsage() static void usage(const char *name) { - if (strlen(gitVersionString)) + if (strlen(getGitVersion())) { - msg("Doxygen version %s (%s)\nCopyright Dimitri van Heesch 1997-2015\n\n",versionString,gitVersionString); + msg("Doxygen version %s (%s)\nCopyright Dimitri van Heesch 1997-2015\n\n",getVersion(),getGitVersion()); } else { - msg("Doxygen version %s\nCopyright Dimitri van Heesch 1997-2015\n\n",versionString); + msg("Doxygen version %s\nCopyright Dimitri van Heesch 1997-2015\n\n",getVersion()); } msg("You can use doxygen in a number of ways:\n\n"); msg("1) Use doxygen to generate a template configuration file:\n"); @@ -9989,8 +9989,6 @@ void initDoxygen() setlocale(LC_CTYPE,"C"); // to get isspace(0xA0)==0, needed for UTF-8 setlocale(LC_NUMERIC,"C"); - correctGitVersion(); - portable_correct_path(); Doxygen::runningTime.start(); @@ -10396,13 +10394,13 @@ void readConfiguration(int argc, char **argv) g_dumpSymbolMap = TRUE; break; case 'v': - if (strlen(gitVersionString)) + if (strlen(getGitVersion())) { - msg("%s (%s)\n",versionString,gitVersionString); + msg("%s (%s)\n",getVersion(),getGitVersion()); } else { - msg("%s\n",versionString); + msg("%s\n",getVersion()); } cleanUpDoxygen(); exit(0); @@ -10415,13 +10413,13 @@ void readConfiguration(int argc, char **argv) } else if (qstrcmp(&argv[optind][2],"version")==0) { - if (strlen(gitVersionString)) + if (strlen(getGitVersion())) { - msg("%s (%s)\n",versionString,gitVersionString); + msg("%s (%s)\n",getVersion(),getGitVersion()); } else { - msg("%s\n",versionString); + msg("%s\n",getVersion()); } cleanUpDoxygen(); exit(0); diff --git a/src/htmlgen.cpp b/src/htmlgen.cpp index d89bb49..cd45e5f 100644 --- a/src/htmlgen.cpp +++ b/src/htmlgen.cpp @@ -858,7 +858,7 @@ void HtmlGenerator::writeSearchData(const char *dir) { searchCss = mgr.getAsString("search.css"); } - searchCss = substitute(replaceColorMarkers(searchCss),"$doxygenversion",versionString); + searchCss = substitute(replaceColorMarkers(searchCss),"$doxygenversion",getVersion()); t << searchCss; Doxygen::indexList->addStyleSheetFile("search/search.css"); } @@ -867,20 +867,20 @@ void HtmlGenerator::writeSearchData(const char *dir) void HtmlGenerator::writeStyleSheetFile(QFile &file) { FTextStream t(&file); - t << replaceColorMarkers(substitute(ResourceMgr::instance().getAsString("doxygen.css"),"$doxygenversion",versionString)); + t << replaceColorMarkers(substitute(ResourceMgr::instance().getAsString("doxygen.css"),"$doxygenversion",getVersion())); } void HtmlGenerator::writeHeaderFile(QFile &file, const char * /*cssname*/) { FTextStream t(&file); - t << "" << endl; + t << "" << endl; t << ResourceMgr::instance().getAsString("header.html"); } void HtmlGenerator::writeFooterFile(QFile &file) { FTextStream t(&file); - t << "" << endl; + t << "" << endl; t << ResourceMgr::instance().getAsString("footer.html"); } @@ -905,7 +905,7 @@ void HtmlGenerator::startFile(const char *name,const char *, t << substituteHtmlKeywords(g_header,convertToHtml(filterTitle(title)),relPath); t << "" << endl; + << getVersion() << " -->" << endl; //static bool generateTreeView = Config_getBool(GENERATE_TREEVIEW); static bool searchEngine = Config_getBool(SEARCHENGINE); if (searchEngine /*&& !generateTreeView*/) @@ -970,7 +970,7 @@ QCString HtmlGenerator::writeLogoAsString(const char *path) "\"doxygen\"/ "; - result += versionString; + result += getVersion(); result += " "; return result; } @@ -1023,7 +1023,7 @@ void HtmlGenerator::writeStyleInfo(int part) //t << "H1 { text-align: center; border-width: thin none thin none;" << endl; //t << " border-style : double; border-color : blue; padding-left : 1em; padding-right : 1em }" << endl; - t << replaceColorMarkers(substitute(ResourceMgr::instance().getAsString("doxygen.css"),"$doxygenversion",versionString)); + t << replaceColorMarkers(substitute(ResourceMgr::instance().getAsString("doxygen.css"),"$doxygenversion",getVersion())); endPlainFile(); Doxygen::indexList->addStyleSheetFile("doxygen.css"); } @@ -2441,7 +2441,7 @@ void HtmlGenerator::writeSearchPage() t << substituteHtmlKeywords(g_header,"Search",""); t << "" << endl; + << getVersion() << " -->" << endl; t << "" << endl; t << "" << endl; diff --git a/src/sqlite3gen.cpp b/src/sqlite3gen.cpp index eceea06..a1ea115 100644 --- a/src/sqlite3gen.cpp +++ b/src/sqlite3gen.cpp @@ -924,7 +924,7 @@ static int insertPath(QCString name, bool local=TRUE, bool found=TRUE, int type= static void recordMetadata() { - bindTextParameter(meta_insert,":doxygen_version",versionString); + bindTextParameter(meta_insert,":doxygen_version",getVersion()); bindTextParameter(meta_insert,":schema_version","0.2.0"); //TODO: this should be a constant somewhere; not sure where bindTextParameter(meta_insert,":generated_at",dateToString(TRUE), FALSE); bindTextParameter(meta_insert,":generated_on",dateToString(FALSE), FALSE); diff --git a/src/util.cpp b/src/util.cpp index f92df68..507ced9 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -5327,7 +5327,7 @@ QCString substituteKeywords(const QCString &s,const char *title, result = substitute(result,"$datetime",dateToString(TRUE)); result = substitute(result,"$date",dateToString(FALSE)); result = substitute(result,"$year",yearToString()); - result = substitute(result,"$doxygenversion",versionString); + result = substitute(result,"$doxygenversion",getVersion()); result = substitute(result,"$projectname",projName); result = substitute(result,"$projectnumber",projNum); result = substitute(result,"$projectbrief",projBrief); diff --git a/src/version.py b/src/version.py deleted file mode 100644 index 4aedee0..0000000 --- a/src/version.py +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/python -# python script to generate version.cpp from first argument -# -# Copyright (C) 1997-2018 by Dimitri van Heesch. -# -# Permission to use, copy, modify, and distribute this software and its -# documentation under the terms of the GNU General Public License is hereby -# granted. No representations are made about the suitability of this software -# for any purpose. It is provided "as is" without express or implied warranty. -# See the GNU General Public License for more details. -# -# Documents produced by Doxygen are derivative works derived from the -# input used in their production; they are not affected by this license. -# -import sys - -def main(): - if len(sys.argv)<2: - sys.exit('Usage: %s ' % sys.argv[0]) - print('char versionString[]="%s";' % sys.argv[1]) - -if __name__ == '__main__': - main() diff --git a/src/xmlgen.cpp b/src/xmlgen.cpp index 251dfde..d3b8355 100644 --- a/src/xmlgen.cpp +++ b/src/xmlgen.cpp @@ -152,7 +152,7 @@ static void writeXMLHeader(FTextStream &t) t << "" << endl;; t << "" << endl; + t << "version=\"" << getVersion() << "\">" << endl; } static void writeCombineScript() @@ -1979,7 +1979,7 @@ void generateXML() t << "" << endl;; t << "" << endl; + t << "version=\"" << getVersion() << "\">" << endl; { ClassSDict::Iterator cli(*Doxygen::classSDict); -- cgit v0.12 From cb1ef441b2a4d21cf67a59fe8e57613ba3552051 Mon Sep 17 00:00:00 2001 From: albert-github Date: Fri, 31 May 2019 20:05:14 +0200 Subject: Show git version information --- src/gitversion.cpp.in | 14 -------------- src/version.h | 25 ------------------------- 2 files changed, 39 deletions(-) delete mode 100644 src/gitversion.cpp.in delete mode 100644 src/version.h diff --git a/src/gitversion.cpp.in b/src/gitversion.cpp.in deleted file mode 100644 index cbb9b13..0000000 --- a/src/gitversion.cpp.in +++ /dev/null @@ -1,14 +0,0 @@ -#include - -char gitVersionString[]="@GIT_HEAD_SHA1@"; - -/* - On some systems git is not installed or - * installed on a place whete FindGit.cmake cannot find it - * - No git information is present (no .git directory) - * in those cases clear the gitVersionString (would have string GIT-NOTFOUND). - */ -void correctGitVersion(void) -{ - if (!strcmp(gitVersionString, "GIT-NOTFOUND")) gitVersionString[0] = '\0'; -} - diff --git a/src/version.h b/src/version.h deleted file mode 100644 index 09d1b4f..0000000 --- a/src/version.h +++ /dev/null @@ -1,25 +0,0 @@ -/****************************************************************************** - * - * - * - * Copyright (C) 1997-2015 by Dimitri van Heesch. - * - * Permission to use, copy, modify, and distribute this software and its - * documentation under the terms of the GNU General Public License is hereby - * granted. No representations are made about the suitability of this software - * for any purpose. It is provided "as is" without express or implied warranty. - * See the GNU General Public License for more details. - * - * Documents produced by Doxygen are derivative works derived from the - * input used in their production; they are not affected by this license. - * - */ - -#ifndef VERSION_H -#define VERSION_H - -extern char versionString[]; -extern char gitVersionString[]; - -void correctGitVersion(void); -#endif -- cgit v0.12