aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2020-07-02 14:22:11 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2020-07-02 14:46:31 -0400
commit0c6b6035c3318e95e5d417639a3d7854cce72464 (patch)
treee4312192086078caeebac5ac58f0f32ad3b795df
parent5dd87260434756f3c974a6c75d373645d84f7b30 (diff)
downloadsplitfits-0c6b6035c3318e95e5d417639a3d7854cce72464.tar.gz
Add version information
-rw-r--r--CMakeLists.txt15
-rw-r--r--splitfits.c6
-rw-r--r--version.h.in6
3 files changed, 26 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index db56622..43f002c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,15 +1,28 @@
cmake_minimum_required(VERSION 3.1...3.16)
project(splitfits C)
-
set(CMAKE_C_STANDARD 99)
+find_package(Git)
+if(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
+ execute_process(COMMAND ${GIT_EXECUTABLE} describe --always --long --tags --dirty
+ OUTPUT_VARIABLE GIT_VERSION
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+else()
+ message(WARNING "git not found or directory is not a repository")
+ set(GIT_VERSION, "unknown")
+endif()
+
add_executable(splitfits splitfits.c)
+include_directories("${CMAKE_CURRENT_BINARY_DIR}")
+configure_file("${CMAKE_CURRENT_SOURCE_DIR}/version.h.in"
+ "${CMAKE_CURRENT_BINARY_DIR}/version.h" @ONLY)
file(GLOB TEST_RUNNER "test*.sh")
file(COPY ${TEST_RUNNER} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(GLOB TEST_FRAMEWORK "tests")
file(COPY ${TEST_FRAMEWORK} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
+
add_custom_target(check "${CMAKE_CURRENT_BINARY_DIR}/test.sh")
install(TARGETS splitfits
diff --git a/splitfits.c b/splitfits.c
index dd0e6d3..6347c4a 100644
--- a/splitfits.c
+++ b/splitfits.c
@@ -5,6 +5,7 @@
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
+#include "version.h"
#define OP_SPLIT 0
#define OP_COMBINE 1
@@ -486,6 +487,7 @@ void usage(char *program_name) {
printf(" -h --help This message\n");
printf(" -c --combine Reconstruct original file using .part_map data\n");
printf(" -o --outdir Path where output files are stored\n");
+ printf(" -V --version Display version\n");
}
int main(int argc, char *argv[]) {
@@ -532,6 +534,10 @@ int main(int argc, char *argv[]) {
} else if (strcmp(argv[inputs], "-c") == 0 || strcmp(argv[inputs], "--combine") == 0) {
// User wants to reconstruct a FITS file using a .part_map
op_mode = OP_COMBINE;
+ } else if (strcmp(argv[inputs], "-V") == 0 || strcmp(argv[inputs], "--version") == 0) {
+ // Dump version and exit
+ puts(SPLITFITS_VERSION);
+ exit(0);
} else {
// Arguments beyond this point are considered input file paths
break;
diff --git a/version.h.in b/version.h.in
new file mode 100644
index 0000000..581156e
--- /dev/null
+++ b/version.h.in
@@ -0,0 +1,6 @@
+#ifndef SPLITFITS_VERSION_H
+#define SPLITFITS_VERSION_H
+
+#define SPLITFITS_VERSION "@GIT_VERSION@"
+
+#endif