Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version-awareness #165

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 55 additions & 7 deletions cmake-local/Version.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,81 @@
set(CPACK_PACKAGE_NAME "osvr-core")
set(CPACK_PACKAGE_VENDOR "Sensics, Inc.")
set(CPACK_PACKAGE_CONTACT "<[email protected]>")
set(CPACK_PACKAGE_VERSION_MAJOR 0)
set(CPACK_PACKAGE_VERSION_MINOR 2)
set(OSVR_VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION ${OSVR_VERSION})
set(OSVR_CORE_VERSION_1 0)
set(OSVR_CORE_VERSION_2 2)
set(OSVR_CORE_VERSION_3 0)
set(OSVR_CORE_VERSION_4 0)
set(OSVR_CORE_VERSION_STRING ${OSVR_CORE_VERSION_1}.${OSVR_CORE_VERSION_2})

include(GetGitRevisionDescription)
git_describe(GIT_REVISION_DESCRIPTION --tags --match v*)
if(GIT_REVISION_DESCRIPTION)
string(REPLACE "v" ""
GIT_REVISION_DESCRIPTION
"${GIT_REVISION_DESCRIPTION}")
set(CPACK_PACKAGE_VERSION "${GIT_REVISION_DESCRIPTION}")
message(STATUS "Git reports version ${CPACK_PACKAGE_VERSION}")
set(OSVR_CORE_VERSION_STRING "${GIT_REVISION_DESCRIPTION}")
message(STATUS "Git reports version ${OSVR_CORE_VERSION_STRING}")
string(REGEX REPLACE ".*-g" "" OSVR_CORE_VERSION_COMMIT "${GIT_REVISION_DESCRIPTION}")
string(REGEX REPLACE "-g.*" "" DESCRIBE_COMPONENTS "${GIT_REVISION_DESCRIPTION}")
string(REGEX MATCHALL "[0-9]+" DESCRIBE_COMPONENTS "${DESCRIBE_COMPONENTS}")

list(LENGTH DESCRIBE_COMPONENTS NUM_COMPONENTS)

if(NUM_COMPONENTS GREATER 0)
list(GET DESCRIBE_COMPONENTS 0 VERCOMPONENT)
if(NOT ${VERCOMPONENT} EQUAL ${OSVR_CORE_VERSION_1})
message("WARNING: need to update OSVR_CORE_VERSION_1 in Version.cmake - doesn't match tag!")
set(OSVR_CORE_VERSION_1 ${VERCOMPONENT})
endif()
endif()
if(NUM_COMPONENTS GREATER 1)
list(GET DESCRIBE_COMPONENTS 1 VERCOMPONENT)
if(NOT ${VERCOMPONENT} EQUAL ${OSVR_CORE_VERSION_2})
message("WARNING: need to update OSVR_CORE_VERSION_2 in Version.cmake - doesn't match tag!")
set(OSVR_CORE_VERSION_2 ${VERCOMPONENT})
endif()
endif()
if(NUM_COMPONENTS GREATER 2)
list(GET DESCRIBE_COMPONENTS 2 OSVR_CORE_VERSION_3)
endif()

if(NUM_COMPONENTS GREATER 3)
message(FATAL_ERROR "Need to update Version.cmake - currently assumes we get 2 version components from the tag and the third from the commit number, while we got more than that!")
endif()
else()
message(STATUS "Could not get revision information from Git! Calling this just version ${CPACK_PACKAGE_VERSION}!")
message(STATUS "Could not get revision information from Git! Calling this just version ${OSVR_CORE_VERSION_STRING}!")
endif()

if(NOT "$ENV{BUILD_TAG}" STREQUAL "")
set(OSVR_CORE_BUILD_TAG "$ENV{BUILD_TAG}")
message(STATUS "Detected CI build tag ${OSVR_CORE_BUILD_TAG}")
endif()

if(OSVR_CORE_BUILD_TAG AND OSVR_OFFICIAL)
message(STATUS "Detected an official build environment!")
set(OSVR_CORE_OFFICIAL_BUILD TRUE)
endif()

set(OSVR_VERSION ${OSVR_CORE_VERSION_1}.${OSVR_CORE_VERSION_2})
set(CPACK_PACKAGE_VERSION_MAJOR ${OSVR_CORE_VERSION_1})
set(CPACK_PACKAGE_VERSION_MINOR ${OSVR_CORE_VERSION_2})
set(CPACK_PACKAGE_VERSION_PATCH ${OSVR_CORE_VERSION_3})
set(CPACK_PACKAGE_VERSION ${OSVR_CORE_VERSION_STRING})

if(WIN32)
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CMAKE_CXX_COMPILER_ID}")
if(MSVC)
include(GetMSVCVersion)
get_msvc_major_minor_version(_vs_major _vs_minor)
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}${_vs_major}${_vs_minor}")
set(OSVR_INTERNAL_API_VARIANT "Visual Studio ${_vs_major}.${_vs_minor}")
endif()

if(CMAKE_CXX_SIZEOF_DATA_PTR EQUAL 8)
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}-64bit")
set(OSVR_BIT_VARIANT "64-bit")
else()
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}-32bit")
set(OSVR_BIT_VARIANT "32-bit")
endif()
endif()
77 changes: 77 additions & 0 deletions inc/osvr/Client/GetRuntimeVersion.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/** @file
@brief Header for accessing runtime version information.

Generated by running:

`cmake -P src/osvr/GenerateGetRuntimeVersion.cmake`

@date 2015

@author
Sensics, Inc.
<http://sensics.com/osvr>
*/

// Copyright 2015 Sensics, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef INCLUDED_GetRuntimeVersion_h_GUID_487199D9_CA87_4E85_52A2_D1BDBC119163
#define INCLUDED_GetRuntimeVersion_h_GUID_487199D9_CA87_4E85_52A2_D1BDBC119163

// Internal Includes
#include <osvr/Client/Export.h>
#include <osvr/Util/RuntimeNumericVersion.h>

// Library/third-party includes
// - none

// Standard includes
// - none

namespace osvr {
namespace client {
/// @brief Returns the value of the version component (zero-indexed)
/// specified, in the inclusive range [0,3].
/// @return version component value, or 0 if component out of range.
OSVR_CLIENT_EXPORT util::NumericVersionComponent
getVersionComponent(uint8_t componentIndex);

/// @brief Gets all numeric components of the runtime version in a tuple.
OSVR_CLIENT_EXPORT util::RuntimeNumericVersion getRuntimeNumericVersion();

/// @brief Gets the Git commit hash corresponding to this library build.
/// @returns an empty string if the commit hash could not be detected.
OSVR_CLIENT_EXPORT const char *getCommit();

/// @brief Gets the full descriptive version string, typically including the
/// numerical version components and the commit hash.
OSVR_CLIENT_EXPORT const char *getVersionString();

/// @brief If this was built by the CI, return the "Build Tag" the CI
/// associated with the build job. (Unrelated to git tags.)
/// @returns empty string if we don't have a CI build tag recorded.
OSVR_CLIENT_EXPORT const char *getCIBuildTag();

/// @brief Does this build identify itself as a dev build, rather than a
/// CI-build "production" build? This is not necessarily 100% accurate - for
/// informational purposes only.
OSVR_CLIENT_EXPORT bool isKnownDevBuild();

/// @brief Gets the name of this library/module, or an empty string if the
/// build system did not incorporate this information into the build.
OSVR_CLIENT_EXPORT const char *getModuleName();
} // namespace client
} // namespace osvr

#endif // INCLUDED_GetRuntimeVersion_h_GUID_487199D9_CA87_4E85_52A2_D1BDBC119163
77 changes: 77 additions & 0 deletions inc/osvr/Common/GetRuntimeVersion.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/** @file
@brief Header for accessing runtime version information.

Generated by running:

`cmake -P src/osvr/GenerateGetRuntimeVersion.cmake`

@date 2015

@author
Sensics, Inc.
<http://sensics.com/osvr>
*/

// Copyright 2015 Sensics, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef INCLUDED_GetRuntimeVersion_h_GUID_5BF26574_26A9_4DB1_27B9_B5B8E69F2AE1
#define INCLUDED_GetRuntimeVersion_h_GUID_5BF26574_26A9_4DB1_27B9_B5B8E69F2AE1

// Internal Includes
#include <osvr/Common/Export.h>
#include <osvr/Util/RuntimeNumericVersion.h>

// Library/third-party includes
// - none

// Standard includes
// - none

namespace osvr {
namespace common {
/// @brief Returns the value of the version component (zero-indexed)
/// specified, in the inclusive range [0,3].
/// @return version component value, or 0 if component out of range.
OSVR_COMMON_EXPORT util::NumericVersionComponent
getVersionComponent(uint8_t componentIndex);

/// @brief Gets all numeric components of the runtime version in a tuple.
OSVR_COMMON_EXPORT util::RuntimeNumericVersion getRuntimeNumericVersion();

/// @brief Gets the Git commit hash corresponding to this library build.
/// @returns an empty string if the commit hash could not be detected.
OSVR_COMMON_EXPORT const char *getCommit();

/// @brief Gets the full descriptive version string, typically including the
/// numerical version components and the commit hash.
OSVR_COMMON_EXPORT const char *getVersionString();

/// @brief If this was built by the CI, return the "Build Tag" the CI
/// associated with the build job. (Unrelated to git tags.)
/// @returns empty string if we don't have a CI build tag recorded.
OSVR_COMMON_EXPORT const char *getCIBuildTag();

/// @brief Does this build identify itself as a dev build, rather than a
/// CI-build "production" build? This is not necessarily 100% accurate - for
/// informational purposes only.
OSVR_COMMON_EXPORT bool isKnownDevBuild();

/// @brief Gets the name of this library/module, or an empty string if the
/// build system did not incorporate this information into the build.
OSVR_COMMON_EXPORT const char *getModuleName();
} // namespace common
} // namespace osvr

#endif // INCLUDED_GetRuntimeVersion_h_GUID_5BF26574_26A9_4DB1_27B9_B5B8E69F2AE1
77 changes: 77 additions & 0 deletions inc/osvr/Connection/GetRuntimeVersion.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/** @file
@brief Header for accessing runtime version information.

Generated by running:

`cmake -P src/osvr/GenerateGetRuntimeVersion.cmake`

@date 2015

@author
Sensics, Inc.
<http://sensics.com/osvr>
*/

// Copyright 2015 Sensics, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef INCLUDED_GetRuntimeVersion_h_GUID_6FCB818C_A087_4CB8_E0C4_29B472CCE703
#define INCLUDED_GetRuntimeVersion_h_GUID_6FCB818C_A087_4CB8_E0C4_29B472CCE703

// Internal Includes
#include <osvr/Connection/Export.h>
#include <osvr/Util/RuntimeNumericVersion.h>

// Library/third-party includes
// - none

// Standard includes
// - none

namespace osvr {
namespace connection {
/// @brief Returns the value of the version component (zero-indexed)
/// specified, in the inclusive range [0,3].
/// @return version component value, or 0 if component out of range.
OSVR_CONNECTION_EXPORT util::NumericVersionComponent
getVersionComponent(uint8_t componentIndex);

/// @brief Gets all numeric components of the runtime version in a tuple.
OSVR_CONNECTION_EXPORT util::RuntimeNumericVersion getRuntimeNumericVersion();

/// @brief Gets the Git commit hash corresponding to this library build.
/// @returns an empty string if the commit hash could not be detected.
OSVR_CONNECTION_EXPORT const char *getCommit();

/// @brief Gets the full descriptive version string, typically including the
/// numerical version components and the commit hash.
OSVR_CONNECTION_EXPORT const char *getVersionString();

/// @brief If this was built by the CI, return the "Build Tag" the CI
/// associated with the build job. (Unrelated to git tags.)
/// @returns empty string if we don't have a CI build tag recorded.
OSVR_CONNECTION_EXPORT const char *getCIBuildTag();

/// @brief Does this build identify itself as a dev build, rather than a
/// CI-build "production" build? This is not necessarily 100% accurate - for
/// informational purposes only.
OSVR_CONNECTION_EXPORT bool isKnownDevBuild();

/// @brief Gets the name of this library/module, or an empty string if the
/// build system did not incorporate this information into the build.
OSVR_CONNECTION_EXPORT const char *getModuleName();
} // namespace connection
} // namespace osvr

#endif // INCLUDED_GetRuntimeVersion_h_GUID_6FCB818C_A087_4CB8_E0C4_29B472CCE703
Loading