Skip to content

Commit

Permalink
ci: Add a cpp file for version information
Browse files Browse the repository at this point in the history
This should allow us to update the version information on each commit, but
still cache most of the build.
The single compilation unit for version.cpp won't be cached, but
everything else can be cached, as the compiler arguments won't change on
every commit.
  • Loading branch information
LeonMatthesKDAB committed Jun 10, 2024
1 parent 7edfbf7 commit 3c6e34b
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 4 deletions.
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,11 @@ if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
message(STATUS "GIT not found!?")
endif()
endif()
add_definitions(-DKNUT_VERSION_STRING="${KNUT_VERSION_STRING}")

# Generate build date for the about dialog Note: This is the simplest way to get
# a build date out of CMake Drawbacks: The timestamp is only updated when CMake
# is rerun. But this should sufficient for our use-case.
string(TIMESTAMP KNUT_BUILDDATE "%Y-%m-%d")
add_definitions(-DKNUT_BUILDDATE="${KNUT_BUILDDATE}")

# Qt
# ##############################################################################
Expand Down
4 changes: 4 additions & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

project(knut-core LANGUAGES CXX)

configure_file(version.cpp.in ${CMAKE_CURRENT_BINARY_DIR}/version.cpp)

set(PROJECT_SOURCES
astnode.h
astnode.cpp
Expand Down Expand Up @@ -104,6 +106,8 @@ set(PROJECT_SOURCES
userdialog.cpp
utils.h
utils.cpp
version.h
${CMAKE_CURRENT_BINARY_DIR}/version.cpp
core.qrc)

add_library(${PROJECT_NAME} STATIC ${PROJECT_SOURCES})
Expand Down
12 changes: 12 additions & 0 deletions src/core/version.cpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "core/version.h"

namespace core {
QString knut_version()
{
return "${KNUT_VERSION_STRING}";
}

QString knut_build_date() {
return "${KNUT_BUILDDATE}";
}
}
8 changes: 8 additions & 0 deletions src/core/version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

#include <QString>

namespace core {
QString knut_version();
QString knut_build_date();
}
3 changes: 2 additions & 1 deletion src/gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "core/slintdocument.h"
#include "core/textdocument.h"
#include "core/uidocument.h"
#include "core/version.h"
#include "documentpalette.h"
#include "guisettings.h"
#include "historypanel.h"
Expand Down Expand Up @@ -572,7 +573,7 @@ Build date: %2<br/><br/>
Knut name has nothing to do with Knut Irvin, nor with Knut the polar bear.<br/>
The name Knut is coming from St Knut, which marks the end of the Christmas and holiday season in Sweden.<br/>
See Wikipedia article: <a href="https://en.wikipedia.org/wiki/Saint_Knut%27s_Day">Saint Knut's Day</a>.)")
.arg(KNUT_VERSION_STRING, KNUT_BUILDDATE);
.arg(core::knut_version(), core::knut_build_date());
QMessageBox dialog(QMessageBox::Information, tr("About Knut"), text, QMessageBox::Ok, this);
dialog.setIconPixmap(QPixmap(":/gui/icons/knut-64.png"));
dialog.exec();
Expand Down
3 changes: 2 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
Contact KDAB at <[email protected]> for commercial licensing options.
*/

#include "core/version.h"
#include "gui/knutmain.h"

#include <QApplication>
Expand All @@ -19,7 +20,7 @@ int main(int argc, char *argv[])

QApplication::setOrganizationName("KDAB");
QApplication::setApplicationName("knut");
QApplication::setApplicationVersion(KNUT_VERSION_STRING);
QApplication::setApplicationVersion(core::knut_version());
QApplication::setWindowIcon(QIcon(":/gui/icons/knut-64.png"));

Q_INIT_RESOURCE(core);
Expand Down

0 comments on commit 3c6e34b

Please sign in to comment.