forked from mesonbuild/meson
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix excluding sources for static lib in both_libraries()
When using both_libraries(), or library() with default_library=both, we remove all sources from args and kwargs when building the static library, and replace them by the objects from the shared library. But sources could also come from any InternalDependency, in which case we currently build them twice (not efficient) and link both objects into the static library. It also means that when we needlessly build those source for the static library, it miss order dependency on generated headers that we removed from args/kwargs, which can cause build errors in the case the source from static lib is compiled before the header in shared lib gets generated. This happened in GLib: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/2917.
- Loading branch information
Showing
3 changed files
with
35 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "foo.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
project('generated header dep', 'c') | ||
|
||
# Regression test case for a very specific case: | ||
# - Uses both_libraries(), or library() with default_library=both. | ||
# - A header file is generated by a custom_target() and passed as source. | ||
# - A C file that uses that header is passed as a declare_dependency() source. | ||
# Under those specific conditions, the static library used to miss an order | ||
# dependency on the header file. This happened in GLib: | ||
# https://gitlab.gnome.org/GNOME/glib/-/merge_requests/2917. | ||
|
||
python = import('python').find_installation() | ||
header = custom_target( | ||
output: 'foo.h', | ||
capture: true, | ||
command: [python, '-c', 'print("#define FOO")'], | ||
) | ||
|
||
sources_dep = declare_dependency(sources: files('foo.c')) | ||
|
||
both_libraries('foo', header, | ||
dependencies: sources_dep, | ||
) |