From 2804065cfeb1df8e3c1beed09b9989e7d0d63490 Mon Sep 17 00:00:00 2001 From: Toon Claes Date: Mon, 13 Jan 2025 11:00:13 +0100 Subject: [PATCH 1/2] meson: ensure correct version-def.h is used This is version 2 of the patch trying to ensure the Meson build does not include `version-def.h` created by Make. Signed-off-by: Toon Claes Cc: Patrick Steinhardt Cc: Junio C Hamano --- Changes in v2: - Instead of copying `version.c` to the Meson build directory, define a macro with the absolute path of `version-def.h` to include. - Link to v1: https://lore.kernel.org/r/20250113-toon-fix-meson-version-v1-1-9637e2be32e3@iotcl.com --- b4-submit-tracking --- # This section is used internally by b4 prep for tracking purposes. { "series": { "revision": 2, "change-id": "20250113-toon-fix-meson-version-3d4d33fdabe3", "prefixes": [], "history": { "v1": [ "20250113-toon-fix-meson-version-v1-1-9637e2be32e3@iotcl.com" ] } } } -- GitLab From c1ca20345132bb8f63589a33acea52f0254d57f2 Mon Sep 17 00:00:00 2001 From: Toon Claes Date: Mon, 13 Jan 2025 11:00:22 +0100 Subject: [PATCH 2/2] meson: ensure correct version-def.h is used To build the libgit-version library, Meson first generates `version-def.h` in the build directory. Then it compiles `version.c` into a library. During compilation, Meson tells to include both the build directory and the project root directory. However, when the user previously has compiled Git using Make, they will have a `version-def.h` file in project root directory as well. Because `version-def.h` is included in `version.c` using the #include directive with double quotes, some preprocessors will look for the header file in the same directory as the source file. This will cause compilation of `version.c` ran by Meson to include `version-def.h` previously made by Make, which might be out of date. To explicitly tell the preprocessor which `version-def.h` to use, pass the absolute path of this file as macro GIT_VERSION_H to the preprocessor using option `-D` and have `version.c` `#include GIT_VERSION_H`. To remain working with other build systems than Meson, include "version-def.h" if that macro is not defined. Co-authored-by: Patrick Steinhardt Signed-off-by: Toon Claes --- meson.build | 4 +++- version.c | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index 0064eb64f54..db27afa9998 100644 --- a/meson.build +++ b/meson.build @@ -1493,7 +1493,9 @@ libgit_version_library = static_library('git-version', 'version.c', version_def_h, ], - c_args: libgit_c_args, + c_args: libgit_c_args + [ + '-DGIT_VERSION_H="' + version_def_h.full_path() + '"', + ], dependencies: libgit_dependencies, include_directories: libgit_include_directories, ) diff --git a/version.c b/version.c index 4d763ab48dd..4786c4e0a54 100644 --- a/version.c +++ b/version.c @@ -1,8 +1,13 @@ #include "git-compat-util.h" #include "version.h" -#include "version-def.h" #include "strbuf.h" +#ifndef GIT_VERSION_H +# include "version-def.h" +#else +# include GIT_VERSION_H +#endif + const char git_version_string[] = GIT_VERSION; const char git_built_from_commit_string[] = GIT_BUILT_FROM_COMMIT; -- GitLab