From 3d67a8eabbc8f5d1031324457987177129baa8df Mon Sep 17 00:00:00 2001 From: Owen Green Date: Fri, 21 Jan 2022 15:45:03 +0000 Subject: [PATCH] Enhance/versioning (#75) * Remove old header template * Add in TU template and declaration header * update CMake to new version scheme * Get SHA from top level source folder --- .gitignore | 3 + CMakeLists.txt | 3 +- FlucomaVersion.cmake | 65 +++++++++++++++++ {script => include}/FluidVersion.hpp | 15 ++-- ...luidVersion.hpp.in => FluidVersion.cpp.in} | 17 +++-- script/flucoma_version.cmake | 70 +++++++++---------- 6 files changed, 120 insertions(+), 53 deletions(-) create mode 100644 FlucomaVersion.cmake rename {script => include}/FluidVersion.hpp (78%) rename script/{FluidVersion.hpp.in => FluidVersion.cpp.in} (69%) diff --git a/.gitignore b/.gitignore index d68710418..001bbc334 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ build **/.DS_Store /examples/out*.wav .vs/ +.dsp_cache +FluidVersion.cpp +flucoma.version.rc diff --git a/CMakeLists.txt b/CMakeLists.txt index 82f3737ee..6d416c4bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,7 @@ endif() project (flucoma-core LANGUAGES CXX) include("${CMAKE_CURRENT_SOURCE_DIR}/script/flucoma-buildtype.cmake") +include("${CMAKE_CURRENT_SOURCE_DIR}/FlucomaVersion.cmake") include(FetchContent) set(HISS_PATH "" CACHE PATH "The path to a HISSTools_Library folder. Will pull from github if not set") @@ -150,7 +151,7 @@ target_include_directories( "${hisstools_SOURCE_DIR}" ) target_link_libraries( - FLUID_DECOMPOSITION INTERFACE HISSTools_FFT + FLUID_DECOMPOSITION INTERFACE HISSTools_FFT flucoma_VERSION_LIB ) target_sources( FLUID_DECOMPOSITION INTERFACE ${HEADERS} diff --git a/FlucomaVersion.cmake b/FlucomaVersion.cmake new file mode 100644 index 000000000..a9e85c1d9 --- /dev/null +++ b/FlucomaVersion.cmake @@ -0,0 +1,65 @@ +# Part of the Fluid Corpus Manipulation Project (http://www.flucoma.org/) +# Copyright 2017-2019 University of Huddersfield. +# Licensed under the BSD-3 License. +# See license.md file in the project root for full license information. +# This project has received funding from the European Research Council (ERC) +# under the European Union’s Horizon 2020 research and innovation programme +# (grant agreement No 725899). + +cmake_minimum_required (VERSION 3.11) + +set(flucoma_VERSION_MAJOR 1) +set(flucoma_VERSION_MINOR 0) +set(flucoma_VERSION_PATCH 0) +set(flucoma_VERSION_SUFFIX TB2.beta4) + +function(make_flucoma_version_string output_variable) + set(${output_variable} + "${flucoma_VERSION_MAJOR}.${flucoma_VERSION_MINOR}.${flucoma_VERSION_PATCH}-${flucoma_VERSION_SUFFIX}" + PARENT_SCOPE) +endfunction() + +function(make_flucoma_version_string_with_sha output_variable) + + make_flucoma_version_string(${output_variable}) + + if(NOT flucoma_CORESHA_ERR AND NOT flucoma_VERSIONSHA_ERR) + string(APPEND + ${output_variable} + "+sha.${flucoma_VERSION_SHA}.core.sha.${flucoma_CORE_SHA}" + ) + endif() + set(${output_variable} ${${output_variable}} PARENT_SCOPE) +endfunction() + +macro(getsha working_dir output_variable result_variable) + execute_process( + COMMAND ${GIT_EXECUTABLE} log -1 --format=%h + WORKING_DIRECTORY ${${working_dir}} + OUTPUT_VARIABLE ${output_variable} + RESULT_VARIABLE ${result_variable} + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE + ) +endmacro() + +getSha(CMAKE_CURRENT_LIST_DIR flucoma_CORE_SHA flucoma_CORESHA_ERR) +getSha(CMAKE_SOURCE_DIR flucoma_VERSION_SHA flucoma_VERSIONSHA_ERR) + +make_flucoma_version_string(flucoma_VERSION_STRING) + +make_flucoma_version_string_with_sha(flucoma_VERSION_STRING_SHA) + +file(WRITE + "${CMAKE_CURRENT_SOURCE_DIR}/flucoma.version.rc" "${flucoma_VERSION_STRING}" +) + +configure_file("${CMAKE_CURRENT_LIST_DIR}/script/FluidVersion.cpp.in" "${CMAKE_CURRENT_LIST_DIR}/FluidVersion.cpp" @ONLY) + +add_library(flucoma_VERSION_LIB STATIC + "${CMAKE_CURRENT_LIST_DIR}/FluidVersion.cpp" +) + +target_include_directories(flucoma_VERSION_LIB PRIVATE + "${CMAKE_CURRENT_LIST_DIR}/include" +) diff --git a/script/FluidVersion.hpp b/include/FluidVersion.hpp similarity index 78% rename from script/FluidVersion.hpp rename to include/FluidVersion.hpp index c647acef0..4f2f7d578 100644 --- a/script/FluidVersion.hpp +++ b/include/FluidVersion.hpp @@ -10,11 +10,10 @@ under the European Union’s Horizon 2020 research and innovation programme #pragma once -namespace fluid{ -namespace client{ - inline const char* fluidVersion() - { - return "1.0.0-TB2.beta4"; - } -} -} +namespace fluid { +namespace client { + +const char* fluidVersion(); + +} // namespace client +} // namespace fluid diff --git a/script/FluidVersion.hpp.in b/script/FluidVersion.cpp.in similarity index 69% rename from script/FluidVersion.hpp.in rename to script/FluidVersion.cpp.in index 6aef0dc89..b776e141e 100644 --- a/script/FluidVersion.hpp.in +++ b/script/FluidVersion.cpp.in @@ -8,13 +8,12 @@ under the European Union’s Horizon 2020 research and innovation programme (grant agreement No 725899). */ -#pragma once +#include "FluidVersion.hpp" -namespace fluid{ -namespace client{ - inline const char* fluidVersion() - { - return "@FLUID_VERSION_TAG@"; - } -} -} +namespace fluid { +namespace client { + +const char* fluidVersion() { return "@flucoma_VERSION_STRING_SHA@"; } + +} // namespace client +} // namespace fluid diff --git a/script/flucoma_version.cmake b/script/flucoma_version.cmake index 88fc8e5a5..6c5263728 100644 --- a/script/flucoma_version.cmake +++ b/script/flucoma_version.cmake @@ -6,38 +6,38 @@ # under the European Union’s Horizon 2020 research and innovation programme # (grant agreement No 725899). -include_guard() - -find_package(Git REQUIRED) - -macro(getsha workingDir varName) - execute_process( - COMMAND ${GIT_EXECUTABLE} log -1 --format=%h - WORKING_DIRECTORY ${${workingDir}} - OUTPUT_VARIABLE ${varName} - # ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE - ) -endmacro() - -getSha(CMAKE_CURRENT_LIST_DIR FLUID_CORE_SHA) -getSha(CMAKE_CURRENT_SOURCE_DIR FLUID_VERSION_SHA) - -execute_process( - COMMAND ${GIT_EXECUTABLE} describe --abbrev=0 --always - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - RESULT_VARIABLE result - OUTPUT_VARIABLE FLUID_VERSION_TAG - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE -) - -set(FLUID_VERSION_TAG "${FLUID_VERSION_TAG}+sha.${FLUID_VERSION_SHA}.core.sha.${FLUID_CORE_SHA}") - -if(result) - message(VERBOSE "Failed to get version string from Git, falling back to indexed header") -else() - configure_file("${CMAKE_CURRENT_LIST_DIR}/FluidVersion.hpp.in" "${CMAKE_CURRENT_LIST_DIR}/FluidVersion.hpp" @ONLY) -endif() - -set(FLUID_VERSION_PATH ${CMAKE_CURRENT_LIST_DIR}) +# include_guard() +# +# find_package(Git REQUIRED) +# +# macro(getsha workingDir varName) +# execute_process( +# COMMAND ${GIT_EXECUTABLE} log -1 --format=%h +# WORKING_DIRECTORY ${${workingDir}} +# OUTPUT_VARIABLE ${varName} +# # ERROR_QUIET +# OUTPUT_STRIP_TRAILING_WHITESPACE +# ) +# endmacro() +# +# getSha(CMAKE_CURRENT_LIST_DIR FLUID_CORE_SHA) +# getSha(CMAKE_CURRENT_SOURCE_DIR FLUID_VERSION_SHA) +# +# execute_process( +# COMMAND ${GIT_EXECUTABLE} describe --abbrev=0 --always +# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +# RESULT_VARIABLE result +# OUTPUT_VARIABLE FLUID_VERSION_TAG +# ERROR_QUIET +# OUTPUT_STRIP_TRAILING_WHITESPACE +# ) +# +# set(FLUID_VERSION_TAG "${FLUID_VERSION_TAG}+sha.${FLUID_VERSION_SHA}.core.sha.${FLUID_CORE_SHA}") +# +# if(result) +# message(VERBOSE "Failed to get version string from Git, falling back to indexed header") +# else() +# configure_file("${CMAKE_CURRENT_LIST_DIR}/FluidVersion.hpp.in" "${CMAKE_CURRENT_LIST_DIR}/FluidVersion.hpp" @ONLY) +# endif() +# +# set(FLUID_VERSION_PATH ${CMAKE_CURRENT_LIST_DIR})