From 65297852e500dde1899076c8eca79e11bcd2029c Mon Sep 17 00:00:00 2001 From: Emily Boudreaux Date: Thu, 9 Apr 2026 07:45:00 -0400 Subject: [PATCH] feat(GF-Version): added auto version header when building the version number is automatically injected into a header now. This allows for more certainty as to what GF version is being used. Note that this is disabled when building the python wheel as there is no clear way to map this dynamically generated header into the wheel structure. This is however not an issue as the python module has a seperate __version__ variable. --- src/include/gridfire/utils/config.h.in | 18 ++++++++--- src/include/gridfire/utils/gf_omp.h | 4 +-- src/include/gridfire/utils/meson.build | 41 ++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 6 deletions(-) diff --git a/src/include/gridfire/utils/config.h.in b/src/include/gridfire/utils/config.h.in index 838b80ae..842803db 100644 --- a/src/include/gridfire/utils/config.h.in +++ b/src/include/gridfire/utils/config.h.in @@ -1,14 +1,24 @@ #pragma once #include +#include namespace gridfire { struct version { - static constexpr int major = #STRINGIFY(GF_VERSION_MAJOR); - static constexpr int minor = #STRINGIFY(GF_VERSION_MINOR); - static constexpr int patch = #STRINGIFY(GF_VERSION_PATCH); + static constexpr int major = @GF_VERSION_MAJOR@; + static constexpr int minor = @GF_VERSION_MINOR@; + static constexpr int patch = @GF_VERSION_PATCH@; + static constexpr const char* tag = "@GF_VERSION_TAG@"; - static constexpr const char* tag = #STRINGIFY(GF_VERSION_TAG); + static std::string toString() { + std::string versionStr = std::to_string(major) + "." + + std::to_string(minor) + "." + + std::to_string(patch); + if (std::string(tag) != "") { + versionStr += "-" + std::string(tag); + } + return versionStr; + } }; } diff --git a/src/include/gridfire/utils/gf_omp.h b/src/include/gridfire/utils/gf_omp.h index 07b645ec..5f00459d 100644 --- a/src/include/gridfire/utils/gf_omp.h +++ b/src/include/gridfire/utils/gf_omp.h @@ -21,7 +21,7 @@ namespace gridfire::omp { if (s_par_mode_initialized) { return; // Only initialize once } - quill::Logger* logger = fourdst::logging::LogManager::getInstance().getLogger("log"); + [[maybe_unused]] quill::Logger* logger = fourdst::logging::LogManager::getInstance().getLogger("log"); LOG_INFO(logger, "Initializing OpenMP parallel mode with {} threads", static_cast(omp_get_max_threads())); CppAD::thread_alloc::parallel_setup( static_cast(omp_get_max_threads()), // Max threads @@ -41,7 +41,7 @@ namespace gridfire::omp { namespace gridfire::omp { inline void log_not_in_parallel_mode() { - quill::Logger* logger = fourdst::logging::LogManager::getInstance().getLogger("log"); + [[maybe_unused]] quill::Logger* logger = fourdst::logging::LogManager::getInstance().getLogger("log"); LOG_INFO(logger, "This is not an error! Note: OpenMP parallel mode is not enabled. GF_USE_OPENMP is not defined. Pass -DGF_USE_OPENMP when compiling to enable OpenMP support. When using meson use the option -Dopenmp_support=true"); } } diff --git a/src/include/gridfire/utils/meson.build b/src/include/gridfire/utils/meson.build index e69de29b..a3a75de7 100644 --- a/src/include/gridfire/utils/meson.build +++ b/src/include/gridfire/utils/meson.build @@ -0,0 +1,41 @@ +python_exe = import('python').find_installation('python3') + +version_parser = ''' +import sys, re +ver = sys.argv[1] +if ver.startswith("v"): ver = ver[1:] +m = re.match(r"^(\d+)\.(\d+)\.(\d+)(.*)$", ver) +if m: + print(f"{m.group(1)};{m.group(2)};{m.group(3)};{m.group(4)}") +else: + print("0;0;0;unknown") +''' + +ver_res = run_command(python_exe, '-c', version_parser, meson.project_version(), check: true) +ver_parts = ver_res.stdout().strip().split(';') + +conf_data = configuration_data() +conf_data.set('GF_VERSION_MAJOR', ver_parts[0]) +conf_data.set('GF_VERSION_MINOR', ver_parts[1]) +conf_data.set('GF_VERSION_PATCH', ver_parts[2]) +conf_data.set('GF_VERSION_TAG', ver_parts[3]) + +message('Configuring include/utils/config.h with version ' + meson.project_version()) +message(' Major: ' + ver_parts[0]) +message(' Minor: ' + ver_parts[1]) +message(' Patch: ' + ver_parts[2]) +message(' Tag: ' + ver_parts[3]) + +do_install_version_file = true +if get_option('build_python') + message('Not installing version file since we are building the Python extension. The version information will be included in the Python module instead.') + do_install_version_file = false +endif + +configure_file( + input : 'config.h.in', + output : 'config.h', + configuration : conf_data, + install : do_install_version_file, + install_dir : get_option('includedir') / '/gridfire/utils' +) \ No newline at end of file