Skip to content

Commit 31ab962

Browse files
committed
dependencies/cmake: Handle spaces in set_target_properties
this is better, but it's still not perfect. cmake doesn't return quotes to us in the trace output, and being 100% the same as cmake is pretty much impossible without that information. What I've done should be a "good enough" implementation without having to maintain a copy of every property allowed in cmake, as well as custom properties.
1 parent eaa2329 commit 31ab962

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

mesonbuild/dependencies/base.py

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,29 +1691,46 @@ def _cmake_set_target_properties(self, tline: CMakeTraceLine) -> None:
16911691
args = list(tline.args)
16921692

16931693
targets = []
1694-
while len(args) > 0:
1694+
while args:
16951695
curr = args.pop(0)
16961696
if curr == 'PROPERTIES':
16971697
break
16981698

16991699
targets.append(curr)
17001700

1701-
if (len(args) % 2) != 0:
1702-
raise self._gen_exception('CMake: set_target_properties() uneven number of property arguments\n{}'.format(tline))
1703-
1704-
while len(args) > 0:
1705-
propName = args.pop(0)
1706-
propVal = args.pop(0).split(';')
1707-
propVal = list(filter(lambda x: len(x) > 0, propVal))
1708-
1709-
if len(propVal) == 0:
1710-
continue
1701+
# Now we need to try to reconsitute the original quoted format of the
1702+
# arguments, as a property value could have spaces in it. Unlike
1703+
# set_property() this is not context free. There are two approaches I
1704+
# can think of, both have drawbacks:
1705+
#
1706+
# 1. Assume that the property will be capitalized, this is convention
1707+
# but cmake doesn't require it.
1708+
# 2. Maintain a copy of the list here: https://cmake.org/cmake/help/latest/manual/cmake-properties.7.html#target-properties
1709+
#
1710+
# Neither of these is awesome for obvious reasons. I'm going to try
1711+
# option 1 first and fall back to 2, as 1 requires less code and less
1712+
# synchroniztion for cmake changes.
1713+
1714+
arglist = [] # type: typing.List[typing.Tuple[str, typing.List[str]]]
1715+
name = args.pop(0)
1716+
values = []
1717+
for a in args:
1718+
if a.isupper():
1719+
if values:
1720+
arglist.append((name, ' '.join(values).split(';')))
1721+
name = a
1722+
values = []
1723+
else:
1724+
values.append(a)
1725+
if values:
1726+
arglist.append((name, ' '.join(values).split(';')))
17111727

1728+
for name, value in arglist:
17121729
for i in targets:
17131730
if i not in self.targets:
17141731
raise self._gen_exception('CMake: set_target_properties() TARGET {} not found\n{}'.format(i, tline))
17151732

1716-
self.targets[i].properies[propName] = propVal
1733+
self.targets[i].properies[name] = value
17171734

17181735
def _lex_trace(self, trace):
17191736
# The trace format is: '<file>(<line>): <func>(<args -- can contain \n> )\n'

0 commit comments

Comments
 (0)