From cdc906085a8c30442542ffcf7cd7a48437979c54 Mon Sep 17 00:00:00 2001 From: Sam Kellett Date: Wed, 30 Dec 2015 19:01:37 +0000 Subject: [PATCH] Added version.h that is prepopulated by cmake. --- .gitignore | 1 + CMakeLists.txt | 2 ++ include/yaml-cpp/version.h.in | 17 +++++++++++++++++ test/version_test.cpp | 27 +++++++++++++++++++++++++++ 4 files changed, 47 insertions(+) create mode 100644 include/yaml-cpp/version.h.in create mode 100644 test/version_test.cpp diff --git a/.gitignore b/.gitignore index 567609b..726b1a3 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ build/ +include/yaml-cpp/version.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 1897775..873d6b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -116,6 +116,8 @@ include_directories(${YAML_CPP_SOURCE_DIR}/include) find_package(Boost REQUIRED) include_directories(${Boost_INCLUDE_DIRS}) +# Create version.h +configure_file(${header_directory}/version.h.in ${CMAKE_SOURCE_DIR}/${header_directory}/version.h) ### ### General compilation settings diff --git a/include/yaml-cpp/version.h.in b/include/yaml-cpp/version.h.in new file mode 100644 index 0000000..1b60ebb --- /dev/null +++ b/include/yaml-cpp/version.h.in @@ -0,0 +1,17 @@ +#ifndef YAML_CPP_VERSION_H +#define YAML_CPP_VERSION_H + +#if defined(_MSC_VER) || \ + (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ + (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 +#pragma once +#endif + +#define YAML_CPP_VERSION_MAJOR ${YAML_CPP_VERSION_MAJOR} +#define YAML_CPP_VERSION_MINOR ${YAML_CPP_VERSION_MINOR} +#define YAML_CPP_VERSION_PATCH ${YAML_CPP_VERSION_PATCH} + +// String representation of the current version (ie. "0.1.2") +#define YAML_CPP_VERSION "${YAML_CPP_VERSION}" + +#endif // YAML_CPP_VERSION_H diff --git a/test/version_test.cpp b/test/version_test.cpp new file mode 100644 index 0000000..b55cc25 --- /dev/null +++ b/test/version_test.cpp @@ -0,0 +1,27 @@ +#include "yaml-cpp/version.h" + +#include "gtest/gtest.h" + +namespace YAML { +namespace { +TEST(VersionTest, Major) +{ + ASSERT_EQ(YAML_CPP_VERSION_MAJOR, 0); +} + +TEST(VersionTest, Minor) +{ + ASSERT_EQ(YAML_CPP_VERSION_MINOR, 5); +} + +TEST(VersionTest, Path) +{ + ASSERT_EQ(YAML_CPP_VERSION_PATCH, 2); +} + +TEST(VersionTest, String) +{ + ASSERT_STREQ(YAML_CPP_VERSION, "0.5.2"); +} +} +}