Skip to content

Commit

Permalink
Enhance/versioning (#75)
Browse files Browse the repository at this point in the history
* Remove old header template

* Add in TU template and declaration header

* update CMake to new version scheme

* Get SHA from top level source folder
  • Loading branch information
weefuzzy authored Jan 21, 2022
1 parent 93f83dc commit 3d67a8e
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 53 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ build
**/.DS_Store
/examples/out*.wav
.vs/
.dsp_cache
FluidVersion.cpp
flucoma.version.rc
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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}
Expand Down
65 changes: 65 additions & 0 deletions FlucomaVersion.cmake
Original file line number Diff line number Diff line change
@@ -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"
)
15 changes: 7 additions & 8 deletions script/FluidVersion.hpp → include/FluidVersion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 8 additions & 9 deletions script/FluidVersion.hpp.in → script/FluidVersion.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
70 changes: 35 additions & 35 deletions script/flucoma_version.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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})

0 comments on commit 3d67a8e

Please sign in to comment.