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.
This commit is contained in:
@@ -1,14 +1,24 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <format>
|
#include <format>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace gridfire {
|
namespace gridfire {
|
||||||
struct version {
|
struct version {
|
||||||
static constexpr int major = #STRINGIFY(GF_VERSION_MAJOR);
|
static constexpr int major = @GF_VERSION_MAJOR@;
|
||||||
static constexpr int minor = #STRINGIFY(GF_VERSION_MINOR);
|
static constexpr int minor = @GF_VERSION_MINOR@;
|
||||||
static constexpr int patch = #STRINGIFY(GF_VERSION_PATCH);
|
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;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ namespace gridfire::omp {
|
|||||||
if (s_par_mode_initialized) {
|
if (s_par_mode_initialized) {
|
||||||
return; // Only initialize once
|
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<unsigned long>(omp_get_max_threads()));
|
LOG_INFO(logger, "Initializing OpenMP parallel mode with {} threads", static_cast<unsigned long>(omp_get_max_threads()));
|
||||||
CppAD::thread_alloc::parallel_setup(
|
CppAD::thread_alloc::parallel_setup(
|
||||||
static_cast<size_t>(omp_get_max_threads()), // Max threads
|
static_cast<size_t>(omp_get_max_threads()), // Max threads
|
||||||
@@ -41,7 +41,7 @@ namespace gridfire::omp {
|
|||||||
|
|
||||||
namespace gridfire::omp {
|
namespace gridfire::omp {
|
||||||
inline void log_not_in_parallel_mode() {
|
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");
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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'
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user