Skip to content

Commit 4771501

Browse files
To1nepks-t
authored andcommitted
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 <ps@pks.im> Signed-off-by: Toon Claes <toon@iotcl.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent fbe8d30 commit 4771501

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

meson.build

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1493,7 +1493,9 @@ libgit_version_library = static_library('git-version',
14931493
'version.c',
14941494
version_def_h,
14951495
],
1496-
c_args: libgit_c_args,
1496+
c_args: libgit_c_args + [
1497+
'-DGIT_VERSION_H="' + version_def_h.full_path() + '"',
1498+
],
14971499
dependencies: libgit_dependencies,
14981500
include_directories: libgit_include_directories,
14991501
)

version.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
#include "git-compat-util.h"
22
#include "version.h"
3-
#include "version-def.h"
43
#include "strbuf.h"
54

5+
#ifndef GIT_VERSION_H
6+
# include "version-def.h"
7+
#else
8+
# include GIT_VERSION_H
9+
#endif
10+
611
const char git_version_string[] = GIT_VERSION;
712
const char git_built_from_commit_string[] = GIT_BUILT_FROM_COMMIT;
813

0 commit comments

Comments
 (0)