Skip to content

Commit

Permalink
Merge pull request #649 from jgrewe/lib_version
Browse files Browse the repository at this point in the history
add static method for library version to File

LGTM
  • Loading branch information
gicmo committed Nov 11, 2016
2 parents 4f2af50 + a3171aa commit 87c5e6c
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 4 deletions.
14 changes: 12 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ cmake_minimum_required (VERSION 2.8.10)
project (nix C CXX)

set(VERSION_MAJOR 1)
set(VERSION_MINOR 2)
set(VERSION_MINOR 3)
set(VERSION_PATCH 0)

set(VERSION_ABI 1)


if(NOT WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_INIT} -std=c++11") ## Optimize
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wunreachable-code")
Expand Down Expand Up @@ -80,9 +79,19 @@ endif(DOXYGEN_FOUND)
########################################
# NIX

### AUTO-GENERATED VERSION HEADER
configure_file (
"${PROJECT_SOURCE_DIR}/version.h.in"
"${PROJECT_BINARY_DIR}/include/nix/nixversion.hpp"
)

include_directories("${PROJECT_BINARY_DIR}/include")

### scan files
include_directories(BEFORE include)
file(GLOB_RECURSE nix_SOURCES src/*.cpp)
file(GLOB_RECURSE nix_INCLUDES include/*.hpp)
list(APPEND nix_INCLUDES "${PROJECT_BINARY_DIR}/include/nix/nixversion.hpp")

### BACKENDS
set(backends "hdf5")
Expand Down Expand Up @@ -110,6 +119,7 @@ foreach(backend ${backends})
list(APPEND nix_INCLUDES ${backend_INCLUDES})
endforeach()


### LIBRARY

add_library(nix SHARED ${nix_INCLUDES} ${nix_SOURCES})
Expand Down
12 changes: 11 additions & 1 deletion include/nix/Version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,22 @@
#include <vector>
#include <stdexcept>
#include <initializer_list>
#include <nix/nixversion.hpp>

#include <nix/Platform.hpp>

#ifndef NIX_VERSION_HPP
#define NIX_VERSION_HPP

namespace nix {

/**
* @brief Returns the version of the library.
*
* @return the version as a vector<int> in the order major, minor, patch
*/
NIXAPI std::vector<int> apiVersion();


class FormatVersion {
public:

Expand Down
9 changes: 9 additions & 0 deletions src/Version.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <nix/Version.hpp>

namespace nix {

std::vector<int> apiVersion() {
return std::vector<int> {VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH};
}

}
6 changes: 6 additions & 0 deletions test/TestVersion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "TestVersion.hpp"


void TestVersion::setUp() {
}

Expand Down Expand Up @@ -62,3 +63,8 @@ void TestVersion::testFormatVersion() {
}

}

void TestVersion::testAPIVersion() {
std::vector<int> v = nix::apiVersion();
CPPUNIT_ASSERT(v.size() == 3);
}
3 changes: 3 additions & 0 deletions test/TestVersion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <iterator>
#include <stdexcept>
#include <limits>
#include <vector>

#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
Expand All @@ -38,11 +39,13 @@ class TestVersion : public CPPUNIT_NS::TestFixture {
void tearDown();

void testFormatVersion();
void testAPIVersion();

private:

CPPUNIT_TEST_SUITE(TestVersion);
CPPUNIT_TEST(testFormatVersion);
CPPUNIT_TEST(testAPIVersion);
CPPUNIT_TEST_SUITE_END ();

};
1 change: 0 additions & 1 deletion test/hdf5/TestFileHDF5.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class TestFileHDF5: public BaseTestFile {

public:


void testVersion() override;

void setUp() override {
Expand Down
7 changes: 7 additions & 0 deletions version.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// the configured options and settings for NIX

namespace nix {
#define VERSION_MAJOR @VERSION_MAJOR@
#define VERSION_MINOR @VERSION_MINOR@
#define VERSION_PATCH @VERSION_PATCH@
}

0 comments on commit 87c5e6c

Please sign in to comment.