Skip to content

Commit e24120e

Browse files
author
Kirill Belousov
committed
Feature: Add version information to app title
1 parent ed43f64 commit e24120e

4 files changed

Lines changed: 26 additions & 7 deletions

File tree

CMakeLists.txt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION 3.25)
2-
project(sim VERSION 1.0)
2+
project(sim VERSION 1.5)
33

44
set(CMAKE_CXX_STANDARD 23)
55
set(CMAKE_CXX_STANDARD_REQUIRED ON)
@@ -25,7 +25,6 @@ file(GLOB SIM_SOURCES "src/*.cpp")
2525

2626
add_executable(sim ${SIM_SOURCES})
2727

28-
2928
if(WIN32)
3029
set_target_properties(${PROJECT_NAME} PROPERTIES WIN32_EXECUTABLE TRUE)
3130
target_compile_definitions(sim PRIVATE UNICODE _UNICODE)
@@ -37,6 +36,21 @@ target_compile_definitions(sim PRIVATE
3736
wxMSVC_VERSION_ABI_COMPAT # Important for wxWidgets v3.3.0+
3837
)
3938

39+
# Define project version string
40+
if(NOT DEFINED SIM_VERSION OR SIM_VERSION STREQUAL "")
41+
set(SIM_VERSION "v0.0")
42+
endif()
43+
if(NOT DEFINED SIM_BUILD_NUMBER OR SIM_BUILD_NUMBER STREQUAL "")
44+
set(SIM_BUILD_NUMBER "DevBuild")
45+
endif()
46+
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
47+
set(SIM_DEBUG_STATUS " debug")
48+
else()
49+
set(SIM_DEBUG_STATUS " release")
50+
endif()
51+
set(FULL_VERSION_STRING "version ${PROJECT_VERSION} (${SIM_VERSION}.${SIM_BUILD_NUMBER})${SIM_DEBUG_STATUS}")
52+
target_compile_definitions(${PROJECT_NAME} PRIVATE SIM_FULL_VERSION="${FULL_VERSION_STRING}")
53+
4054
# --- Dependencies with FetchContent ---
4155
include(FetchContent)
4256
set(FETCHCONTENT_BASE_DIR ${CMAKE_BINARY_DIR}/_dependencies)

scripts/build-debug.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
cmake --preset windows-msvc-x64-debug && cmake --build --preset debug-x64
1+
cmake --preset windows-msvc-x64-debug -DSIM_VERSION="%GITHUB_REF_NAME%" -DSIM_BUILD_NUMBER="%GITHUB_RUN_NUMBER%" && cmake --build --preset debug-x64

scripts/build-release.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
cmake --preset windows-msvc-x64-release && cmake --build --preset release-x64
1+
cmake --preset windows-msvc-x64-release -DSIM_VERSION="%GITHUB_REF_NAME%" -DSIM_BUILD_NUMBER="%GITHUB_RUN_NUMBER%" && cmake --build --preset release-x64

src/ui.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66
#include "speech.h"
77

88
#include <CLI/CLI.hpp>
9+
#include <cstring>
910
#include <spdlog/spdlog.h>
1011
#include <string>
1112
#include <wx/string.h>
1213

14+
static std::string PROGRAM_TITLE = std::format("SIM {}", SIM_FULL_VERSION);
15+
1316
MainFrame::MainFrame(const wxString& title, int cliVoiceIndex, int cliOutputDeviceIndex, bool cliIsHelpRequested)
1417
: wxFrame(nullptr, wxID_ANY, title) {
1518
m_cliVoiceIndex = cliVoiceIndex;
@@ -115,7 +118,7 @@ void MainFrame::OnEnterPress(wxCommandEvent& event) {
115118
return;
116119
}
117120
wxString messageText = m_messageField->GetValue();
118-
std::string text = std::string(messageText.utf8_str());
121+
auto text = std::string(messageText.utf8_str());
119122
if (!Speech::GetInstance().speak(text.c_str())) {
120123
wxMessageBox("This voice either does not work with the program or crashes it. Please select another voice.",
121124
"Error! The selected SAPI voice is not supported.", 5L, m_panel);
@@ -125,14 +128,16 @@ void MainFrame::OnEnterPress(wxCommandEvent& event) {
125128
}
126129

127130
void MainFrame::OnMessageFieldKeyDown(wxKeyEvent& event) {
128-
std::string text = std::string(m_messageField->GetValue().utf8_str());
131+
auto text = std::string(m_messageField->GetValue().utf8_str());
129132
switch (event.GetKeyCode()) {
130133
case WXK_UP:
131134
m_messageField->SetValue(wxString::FromUTF8(g_HistoryStorage.getPreviousByText(text)));
132135
break;
133136
case WXK_DOWN:
134137
m_messageField->SetValue(wxString::FromUTF8(g_HistoryStorage.getNextByText(text)));
135138
break;
139+
default:
140+
break;
136141
}
137142
event.Skip();
138143
}
@@ -168,7 +173,7 @@ bool MyApp::OnInit() {
168173
bool cliIsHelpRequested = false;
169174
CLI11_PARSE(cliApp, MyApp::argc, argv);
170175
InitializeLogging(MyApp::argc, MyApp::argv, cliIsDebugEnabled);
171-
auto* frame = new MainFrame("SIM test", cliVoiceIndex, cliOutputDeviceIndex, cliIsHelpRequested);
176+
auto* frame = new MainFrame(PROGRAM_TITLE, cliVoiceIndex, cliOutputDeviceIndex, cliIsHelpRequested);
172177
frame->Show(true);
173178
spdlog::debug("Main window shown");
174179
return true;

0 commit comments

Comments
 (0)