Commit efee14dc authored by David Flynn's avatar David Flynn
Browse files

build: determine version string from VCS

parent ebb046e5
# Generate a version file from a template based on the VCS version
# - Determine the current version string
# => If git is unavailable, fallback to specified string
# - Test if it is the same as the cached version
# - If same, do nothing, otherwise generate output
if(NOT GIT_EXECUTABLE)
set(VERSION ${VERSION_FALLBACK})
else()
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tags --long --always --dirty=+dirty
OUTPUT_VARIABLE VERSION
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()
if(EXISTS ${VERSION_CACHE_FILE})
FILE(READ ${VERSION_CACHE_FILE} VERSION_CACHED)
endif()
FILE(WRITE ${VERSION_CACHE_FILE} ${VERSION}${VERSION_EXTRA})
if(NOT VERSION_CACHED STREQUAL VERSION OR ${TEMPLATE} IS_NEWER_THAN ${OUTPUT})
configure_file ("${TEMPLATE}" "${OUTPUT}")
endif()
...@@ -8,8 +8,30 @@ endif() ...@@ -8,8 +8,30 @@ endif()
include(CheckSymbolExists) include(CheckSymbolExists)
check_symbol_exists(getrusage sys/resource.h HAVE_GETRUSAGE) check_symbol_exists(getrusage sys/resource.h HAVE_GETRUSAGE)
set (TMC3_VERSION_MAJOR 1) ##
set (TMC3_VERSION_MINOR 0) # Determine the software version from VCS
# Fallback to descriptive version if VCS unavailable
set(VERSION_FALLBACK "unconfirmed-release-1.0b")
set(VERSION_FILE ${CMAKE_CURRENT_BINARY_DIR}/version.cpp)
set(VERSION_FILE_IN ${CMAKE_CURRENT_SOURCE_DIR}/version.cpp.in)
set(VERSION_CACHE_FILE ${CMAKE_CURRENT_BINARY_DIR}/version.cache)
find_package(Git)
add_custom_target(
genversion
COMMAND ${CMAKE_COMMAND} -D OUTPUT=${VERSION_FILE}
-D TEMPLATE=${VERSION_FILE_IN}
-D VERSION_FALLBACK=${VERSION_FALLBACK}
-D VERSION_EXTRA=${VERSION_EXTRA}
-D VERSION_CACHE_FILE=${VERSION_CACHE_FILE}
-D GIT_EXECUTABLE=${GIT_EXECUTABLE}
-P ${CMAKE_SOURCE_DIR}/scripts/genversion.cmake
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
add_custom_command(
OUTPUT ${VERSION_FILE}
DEPENDS genversion
)
configure_file ( configure_file (
"${CMAKE_CURRENT_SOURCE_DIR}/TMC3Config.h.in" "${CMAKE_CURRENT_SOURCE_DIR}/TMC3Config.h.in"
...@@ -41,13 +63,24 @@ source_group (cl FILES ${PROJECT_CL_FILES}) ...@@ -41,13 +63,24 @@ source_group (cl FILES ${PROJECT_CL_FILES})
include_directories( include_directories(
"${PROJECT_BINARY_DIR}/tmc3" "${PROJECT_BINARY_DIR}/tmc3"
"${CMAKE_CURRENT_SOURCE_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/../dependencies/nanoflann" "${CMAKE_CURRENT_SOURCE_DIR}/../dependencies/nanoflann"
"${CMAKE_CURRENT_SOURCE_DIR}/../dependencies/tbb/include" "${CMAKE_CURRENT_SOURCE_DIR}/../dependencies/tbb/include"
"${CMAKE_CURRENT_SOURCE_DIR}/../dependencies/arithmetic-coding/inc" "${CMAKE_CURRENT_SOURCE_DIR}/../dependencies/arithmetic-coding/inc"
"${CMAKE_CURRENT_SOURCE_DIR}/../dependencies/program-options-lite" "${CMAKE_CURRENT_SOURCE_DIR}/../dependencies/program-options-lite"
) )
add_executable(tmc3 ${PROJECT_CPP_FILES} ${PROJECT_C_FILES} ${PROJECT_CL_FILES} ${PROJECT_PUB_FILES} ${PROJECT_INC_FILES} ${PROJECT_IN_FILES} ${PROJECT_INL_FILES}) add_executable (tmc3
${PROJECT_CPP_FILES}
${PROJECT_C_FILES}
${PROJECT_CL_FILES}
${PROJECT_PUB_FILES}
${PROJECT_INC_FILES}
${PROJECT_IN_FILES}
${PROJECT_INL_FILES}
${VERSION_FILE}
)
add_dependencies(tmc3 genversion)
target_link_libraries (tmc3 tbb_static) target_link_libraries (tmc3 tbb_static)
install (TARGETS tmc3 DESTINATION bin) install (TARGETS tmc3 DESTINATION bin)
...@@ -35,13 +35,13 @@ ...@@ -35,13 +35,13 @@
#include "TMC3.h" #include "TMC3.h"
#include "program_options_lite.h" #include "program_options_lite.h"
#include "version.h"
using namespace std; using namespace std;
using namespace pcc; using namespace pcc;
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
std::cout << "tmc3 v" << TMC3_VERSION_MAJOR << "." << TMC3_VERSION_MINOR << std::endl cout << "MPEG PCC tmc3 version " << ::pcc::version << endl;
<< std::endl;
Parameters params; Parameters params;
if (!ParseParameters(argc, argv, params)) { if (!ParseParameters(argc, argv, params)) {
......
#define TMC3_VERSION_MAJOR @TMC3_VERSION_MAJOR@ #pragma once
#define TMC3_VERSION_MINOR @TMC3_VERSION_MINOR@
/* Define to 1 if getrusage(2) is present */ /* Define to 1 if getrusage(2) is present */
#cmakedefine01 HAVE_GETRUSAGE #cmakedefine01 HAVE_GETRUSAGE
#include "version.h"
namespace pcc {
const char version[] = "@VERSION@";
}
/* The copyright in this software is being made available under the BSD
* Licence, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such
* rights are granted under this licence.
*
* Copyright (c) 2017-2018, ISO/IEC
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of the ISO/IEC nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
namespace pcc {
// Description of the software source version
extern const char version[];
} /* namespace pcc */
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment