From 942290a368443dcca10e0338e627f41d65daf9e5 Mon Sep 17 00:00:00 2001
From: Carl Philipp Klemm <philipp@uvos.xyz>
Date: Tue, 18 Jun 2024 11:02:34 +0200
Subject: [PATCH] add windows packageing

---
 CMakeLists.txt         | 17 +++++++++++++++++
 eisgenerator/eistype.h | 11 +++++++++++
 eistype.cpp            |  7 +++++++
 options.h              |  8 ++++----
 package-win.sh         | 19 +++++++++++++++++++
 5 files changed, 58 insertions(+), 4 deletions(-)
 create mode 100755 package-win.sh

diff --git a/CMakeLists.txt b/CMakeLists.txt
index f43819b..fa71b8f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,6 +6,13 @@ set (CMAKE_CXX_STANDARD 20)
 
 option(PROFILE_ENABLED "instrument for gprof" OFF)
 
+set(CMAKE_PROJECT_VERSION_MAJOR 2)
+set(CMAKE_PROJECT_VERSION_MINOR 0)
+set(CMAKE_PROJECT_VERSION_PATCH 0)
+add_compile_definitions(VERSION_MAJOR=${CMAKE_PROJECT_VERSION_MAJOR})
+add_compile_definitions(VERSION_MINOR=${CMAKE_PROJECT_VERSION_MINOR})
+add_compile_definitions(VERSION_PATCH=${CMAKE_PROJECT_VERSION_PATCH})
+
 find_package(Doxygen)
 
 set(SRC_FILES
@@ -69,6 +76,16 @@ if(WIN32)
 	)
 
 	set(COMMON_LINK_FLAGS "-flto -dl")
+
+	if(NOT CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
+		configure_file(${CMAKE_CURRENT_SOURCE_DIR}/package-win.sh ${CMAKE_CURRENT_BINARY_DIR}/package.sh @ONLY)
+		add_custom_target(package
+			COMMAND ${CMAKE_CURRENT_BINARY_DIR}/package.sh
+			WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+			COMMENT "Createing release archive"
+			VERBATIM)
+	endif()
+
 else()
 	message("Building on UNIX")
 
diff --git a/eisgenerator/eistype.h b/eisgenerator/eistype.h
index 970b4e1..c71f87d 100644
--- a/eisgenerator/eistype.h
+++ b/eisgenerator/eistype.h
@@ -452,6 +452,16 @@ std::pair<std::valarray<fvalue>, std::valarray<fvalue>> eisToValarrays(const std
 
 /** @} */
 
+
+struct VersionFixed
+{
+	int major;
+	int minor;
+	int patch;
+};
+
+const VersionFixed& getVersion();
+
 }
 
 std::ostream &operator<<(std::ostream &s, eis::DataPoint const& dp);
@@ -460,3 +470,4 @@ std::ostream &operator<<(std::ostream &s, eis::Range const& range);
 
 std::ostream &operator<<(std::ostream &s, eis::EisSpectra const& spectra);
 
+
diff --git a/eistype.cpp b/eistype.cpp
index 349688b..6061d79 100644
--- a/eistype.cpp
+++ b/eistype.cpp
@@ -394,6 +394,13 @@ EisSpectra EisSpectra::loadFromDisk(const std::filesystem::path& path)
 	}
 }
 
+static VersionFixed version = {VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH};
+
+const VersionFixed& getVersion()
+{
+	return version;
+}
+
 std::ostream &operator<<(std::ostream &s, EisSpectra const& spectra)
 {
 	spectra.saveToStream(s);
diff --git a/options.h b/options.h
index ea8b208..b477d43 100644
--- a/options.h
+++ b/options.h
@@ -20,13 +20,13 @@
 
 #pragma once
 #include <string>
-#include <vector>
 #include <argp.h>
-#include "model.h"
 #include "log.h"
-#include "strops.h"
 
-const char *argp_program_version = "eisgenerator-1.0";
+#define xstr(s) str(s)
+#define str(s) #s
+
+const char *argp_program_version = "eisgenerator-" xstr(VERSION_MAJOR) "." xstr(VERSION_MINOR) "." xstr(VERSION_PATCH);
 const char *argp_program_bug_address = "<carl@uvos.xyz>";
 static char doc[] = "Application that generates EIS spectra from model strings";
 static char args_doc[] = "";
diff --git a/package-win.sh b/package-win.sh
new file mode 100755
index 0000000..47bcc77
--- /dev/null
+++ b/package-win.sh
@@ -0,0 +1,19 @@
+#!/bin/bash -e
+
+PORJECT_NAME=@PROJECT_NAME@
+ONNXNAME="@ONNX_NAME@"
+VERSION="@CMAKE_PROJECT_VERSION_MAJOR@.@CMAKE_PROJECT_VERSION_MINOR@.@CMAKE_PROJECT_VERSION_PATCH@"
+BINARYDIR="@CMAKE_CURRENT_BINARY_DIR@"
+SRCDIR="@CMAKE_CURRENT_SOURCE_DIR@"
+RELDIRECTORY="$BINARYDIR/packaged/$VERSION/release"
+
+rm $BINARYDIR/packaged/$PORJECT_NAME-$VERSION.zip || true
+cd $BINARYDIR
+install -d $RELDIRECTORY
+cp libeisgenerator.dll $RELDIRECTORY
+cp libeisgenerator.dll.a $RELDIRECTORY
+cp libeisgenerator_static.a $RELDIRECTORY
+cp eisgenerator_export.exe $RELDIRECTORY
+cp eisgenerator_test.exe $RELDIRECTORY
+cd $RELDIRECTORY/..
+zip -r $BINARYDIR/packaged/$PORJECT_NAME-$VERSION.zip release
-- 
GitLab