summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorarch1t3cht <arch1t3cht@gmail.com>2023-12-05 00:53:59 +0100
committerEli Schwartz <eschwartz93@gmail.com>2023-12-10 22:01:03 -0500
commitaf0464352aa46324a1a59f8a1e82b6cdd46ec891 (patch)
tree949148de1f4125eb4a74a5a4afe7cfcbc052b5ad
parent17c6d5eb478386ad183fa7e11b688217645d8f4f (diff)
downloadmeson-af0464352aa46324a1a59f8a1e82b6cdd46ec891.tar.gz
vs: Manually link generated .o files
Fixes #12550 . VS automatically links CustomBuild outputs ending in .obj or .res, but others need to be included explicitly.
-rw-r--r--mesonbuild/backend/vs2010backend.py21
-rw-r--r--test cases/common/52 object generator/meson.build10
-rw-r--r--test cases/common/52 object generator/prog.c3
-rw-r--r--test cases/common/52 object generator/source4.c3
4 files changed, 20 insertions, 17 deletions
diff --git a/mesonbuild/backend/vs2010backend.py b/mesonbuild/backend/vs2010backend.py
index f4de65823..f102fbe14 100644
--- a/mesonbuild/backend/vs2010backend.py
+++ b/mesonbuild/backend/vs2010backend.py
@@ -895,18 +895,6 @@ class Vs2010Backend(backends.Backend):
ET.SubElement(parent_node, "AdditionalIncludeDirectories").text = ';'.join(dirs)
@staticmethod
- def has_objects(objects, additional_objects, generated_objects):
- # Ignore generated objects, those are automatically used by MSBuild because they are part of
- # the CustomBuild Outputs.
- return len(objects) + len(additional_objects) > 0
-
- @staticmethod
- def add_generated_objects(node, generated_objects):
- # Do not add generated objects to project file. Those are automatically used by MSBuild, because
- # they are part of the CustomBuild Outputs.
- return
-
- @staticmethod
def escape_preprocessor_define(define: str) -> str:
# See: https://msdn.microsoft.com/en-us/library/bb383819.aspx
table = str.maketrans({'%': '%25', '$': '%24', '@': '%40',
@@ -1779,17 +1767,20 @@ class Vs2010Backend(backends.Backend):
for o in custom_objs:
additional_objects.append(o)
+ # VS automatically links CustomBuild outputs whose name ends in .obj or .res,
+ # but the others need to be included explicitly
+ explicit_link_gen_objs = [obj for obj in gen_objs if not obj.endswith(('.obj', '.res'))]
+
previous_objects = []
- if self.has_objects(objects, additional_objects, gen_objs):
+ if len(objects) + len(additional_objects) + len(explicit_link_gen_objs) > 0:
inc_objs = ET.SubElement(root, 'ItemGroup')
for s in objects:
relpath = os.path.join(proj_to_build_root, s.rel_to_builddir(self.build_to_src))
if path_normalize_add(relpath, previous_objects):
ET.SubElement(inc_objs, 'Object', Include=relpath)
- for s in additional_objects:
+ for s in additional_objects + explicit_link_gen_objs:
if path_normalize_add(s, previous_objects):
ET.SubElement(inc_objs, 'Object', Include=s)
- self.add_generated_objects(inc_objs, gen_objs)
ET.SubElement(root, 'Import', Project=r'$(VCTargetsPath)\Microsoft.Cpp.targets')
self.add_regen_dependency(root)
diff --git a/test cases/common/52 object generator/meson.build b/test cases/common/52 object generator/meson.build
index e20da6f46..49590d6d6 100644
--- a/test cases/common/52 object generator/meson.build
+++ b/test cases/common/52 object generator/meson.build
@@ -29,6 +29,14 @@ gen2 = generator(python,
arguments : [comp, cc, '@INPUT@', '@OUTPUT0@'])
generated2 = gen2.process(['source3.c'])
-e = executable('prog', 'prog.c', generated, generated2)
+# Generate an object file ending with .o even on Windows.
+# The VS backend needs to handle .o objects differently from .obj objects.
+gen3 = generator(python,
+ output : '@BASENAME@.o',
+ arguments : [comp, cc, '@INPUT@', '@OUTPUT@'])
+
+generated3 = gen3.process(['source4.c'])
+
+e = executable('prog', 'prog.c', generated, generated2, generated3)
test('objgen', e) \ No newline at end of file
diff --git a/test cases/common/52 object generator/prog.c b/test cases/common/52 object generator/prog.c
index 9841180d0..80056dc03 100644
--- a/test cases/common/52 object generator/prog.c
+++ b/test cases/common/52 object generator/prog.c
@@ -1,7 +1,8 @@
int func1_in_obj(void);
int func2_in_obj(void);
int func3_in_obj(void);
+int func4_in_obj(void);
int main(void) {
- return func1_in_obj() + func2_in_obj() + func3_in_obj();
+ return func1_in_obj() + func2_in_obj() + func3_in_obj() + func4_in_obj();
}
diff --git a/test cases/common/52 object generator/source4.c b/test cases/common/52 object generator/source4.c
new file mode 100644
index 000000000..83f4fab81
--- /dev/null
+++ b/test cases/common/52 object generator/source4.c
@@ -0,0 +1,3 @@
+int func4_in_obj(void) {
+ return 0;
+}