git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] meson: ensure correct version-def.h is used
@ 2025-01-13 10:28 Toon Claes
  2025-01-13 10:50 ` Patrick Steinhardt
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Toon Claes @ 2025-01-13 10:28 UTC (permalink / raw)
  To: git; +Cc: Patrick Steinhardt, Toon Claes

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 compilers 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.

Copy `version.c` to the build directory before compiling it to ensure
`version-def.h` from the build directory is used.

Signed-off-by: Toon Claes <toon@iotcl.com>
---
---
 meson.build | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/meson.build b/meson.build
index 0064eb64f546a6349a8694ce251bd352febda6fe..8ecb22c80e4fc3f194e97c14dbf83f541d72b25b 100644
--- a/meson.build
+++ b/meson.build
@@ -1486,11 +1486,15 @@ version_def_h = custom_target(
   env: version_gen_environment,
 )
 
+# Because most compilers prefer header files in the same directory as the source
+# file, copy version.c to the build directory.
+version_c = fs.copyfile(meson.current_source_dir() / 'version.c', 'version.c')
+
 # Build a separate library for "version.c" so that we do not have to rebuild
 # everything when the current Git commit changes.
 libgit_version_library = static_library('git-version',
   sources: [
-    'version.c',
+    version_c,
     version_def_h,
   ],
   c_args: libgit_c_args,

---

base-commit: fbe8d3079d4a96aeb4e4529cc93cc0043b759a05
change-id: 20250113-toon-fix-meson-version-3d4d33fdabe3

Thanks
--
Toon


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-01-16 16:02 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-13 10:28 [PATCH] meson: ensure correct version-def.h is used Toon Claes
2025-01-13 10:50 ` Patrick Steinhardt
2025-01-13 17:01 ` Junio C Hamano
2025-01-13 17:24   ` Toon Claes
2025-01-14  6:52     ` Patrick Steinhardt
2025-01-14 11:15 ` [PATCH v2] " Toon Claes
2025-01-16  9:43   ` Patrick Steinhardt
2025-01-16 15:57     ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).