diff --git a/CMakeLists.txt b/CMakeLists.txt index 8e9fee88..d21f36a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,19 @@ cmake_minimum_required(VERSION 3.10) -# Make sure this matches ./NAM/version.h! -project(NAM VERSION 0.4.0) +file(READ "${CMAKE_CURRENT_LIST_DIR}/NAM/version.h" _nam_version_header) +foreach(_component MAJOR MINOR PATCH) + string(REGEX MATCH + "#define[ \t]+NEURAL_AMP_MODELER_DSP_VERSION_${_component}[ \t]+([0-9]+)" + _nam_version_match "${_nam_version_header}" + ) + if(NOT _nam_version_match) + message(FATAL_ERROR "Could not parse NEURAL_AMP_MODELER_DSP_VERSION_${_component} from NAM/version.h") + endif() + set(_nam_version_${_component} "${CMAKE_MATCH_1}") +endforeach() + +set(_nam_project_version "${_nam_version_MAJOR}.${_nam_version_MINOR}.${_nam_version_PATCH}") +project(NAM VERSION "${_nam_project_version}") set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") diff --git a/docs/conf.py b/docs/conf.py index 305152c8..28638cda 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -4,6 +4,7 @@ # https://www.sphinx-doc.org/en/master/usage/configuration.html import os +import re import sys from pathlib import Path @@ -19,8 +20,25 @@ project = 'NeuralAmpModelerCore' copyright = '2023-present Steven Atkinson' author = 'Neural Amp Modeler Contributors' -release = '0.4.0' -version = '0.4.0' + + +def _get_project_version(): + version_header = Path(__file__).resolve().parent.parent / 'NAM' / 'version.h' + contents = version_header.read_text(encoding='utf-8') + version_parts = {} + for component in ('MAJOR', 'MINOR', 'PATCH'): + match = re.search( + rf'#define\s+NEURAL_AMP_MODELER_DSP_VERSION_{component}\s+(\d+)', + contents, + ) + if match is None: + raise RuntimeError(f'Could not parse {component.lower()} version from {version_header}') + version_parts[component.lower()] = match.group(1) + return f"{version_parts['major']}.{version_parts['minor']}.{version_parts['patch']}" + + +release = _get_project_version() +version = release # -- General configuration --------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration