diff --git a/CMakeLists.txt b/CMakeLists.txt index e33601f..95f5221 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,8 +40,23 @@ target_link_libraries(hype_core PUBLIC target_compile_options(hype_core PUBLIC -Wall -Wextra) set_target_properties(hype_core PROPERTIES INTERPROCEDURAL_OPTIMIZATION ON) +# The version comes from the release, never from the code: a tag's tarball unpacks as hype-, and a checkout asks git. +get_filename_component(source_dir_name "${CMAKE_CURRENT_SOURCE_DIR}" NAME) +if(source_dir_name MATCHES "^hype-([0-9][0-9.]*)$") + set(HYPE_VERSION "${CMAKE_MATCH_1}") +else() + execute_process(COMMAND git describe --tags --always --dirty + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + OUTPUT_VARIABLE HYPE_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET) + string(REGEX REPLACE "^v" "" HYPE_VERSION "${HYPE_VERSION}") + if(NOT HYPE_VERSION) + set(HYPE_VERSION dev) + endif() +endif() + add_executable(hype src/main.cpp src/resources.qrc) target_link_libraries(hype PRIVATE hype_core) +target_compile_definitions(hype PRIVATE HYPE_VERSION="${HYPE_VERSION}") set_target_properties(hype PROPERTIES INTERPROCEDURAL_OPTIMIZATION ON) enable_testing() diff --git a/src/main.cpp b/src/main.cpp index bdaf262..c3df95a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -53,7 +53,7 @@ int main(int argc, char **argv) { qputenv("QT_QPA_PLATFORM", "offscreen"); QGuiApplication app(argc, argv); app.setApplicationName("hype"); - app.setApplicationVersion("0.6.0"); + app.setApplicationVersion(HYPE_VERSION); app.setDesktopFileName(qEnvironmentVariable("HYPE_DESKTOP_FILE", "hype")); if (command) return runCli(app.arguments()); diff --git a/tests/test_cli.py b/tests/test_cli.py index c604f77..680fab7 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -53,6 +53,9 @@ def test_new_starts_a_themed_presentation_without_overwriting(self): self.assertIn('already exists', self.hype('new', self.deck, code=1).stderr) self.assertIn('paper', self.hype('new', self.root / 'other.md', '--theme', 'nope', code=1).stderr) + def test_version_comes_from_the_build(self): + self.assertRegex(self.hype('--version').stdout, r'^hype [0-9a-z][^\s]*\n$') + def test_save_applies_a_theme_and_exits(self): self.write('# One\n') self.hype(self.deck, '--theme', 'paper', '--save')