@@ -1546,13 +1546,27 @@ def _var_to_bool(self, var):
1546
1546
return True
1547
1547
return False
1548
1548
1549
- def _cmake_set (self , tline : CMakeTraceLine ):
1549
+ def _cmake_set (self , tline : CMakeTraceLine ) -> None :
1550
+ """Handler for the CMake set() function in all variaties.
1551
+
1552
+ comes in three flavors:
1553
+ set(<var> <value> [PARENT_SCOPE])
1554
+ set(<var> <value> CACHE <type> <docstring> [FORCE])
1555
+ set(ENV{<var>} <value>)
1556
+
1557
+ We don't support the ENV variant, and any uses of it will be ignored
1558
+ silently. the other two variates are supported, with some caveats:
1559
+ - we don't properly handle scoping, so calls to set() inside a
1560
+ function without PARENT_SCOPE set could incorrectly shadow the
1561
+ outer scope.
1562
+ - We don't honor the type of CACHE arguments
1563
+ """
1550
1564
# DOC: https://cmake.org/cmake/help/latest/command/set.html
1551
1565
1552
1566
# 1st remove PARENT_SCOPE and CACHE from args
1553
1567
args = []
1554
1568
for i in tline .args :
1555
- if i == 'PARENT_SCOPE' or len ( i ) == 0 :
1569
+ if not i or i == 'PARENT_SCOPE' :
1556
1570
continue
1557
1571
1558
1572
# Discard everything after the CACHE keyword
@@ -1564,13 +1578,19 @@ def _cmake_set(self, tline: CMakeTraceLine):
1564
1578
if len (args ) < 1 :
1565
1579
raise self ._gen_exception ('CMake: set() requires at least one argument\n {}' .format (tline ))
1566
1580
1567
- if len (args ) == 1 :
1581
+ # Now that we've removed extra arguments all that should be left is the
1582
+ # variable identifier and the value, join the value back together to
1583
+ # ensure spaces in the value are correctly handled. This assumes that
1584
+ # variable names don't have spaces. Please don't do that...
1585
+ identifier = args .pop (0 )
1586
+ value = ' ' .join (args )
1587
+
1588
+ if not value :
1568
1589
# Same as unset
1569
- if args [ 0 ] in self .vars :
1570
- del self .vars [args [ 0 ] ]
1590
+ if identifier in self .vars :
1591
+ del self .vars [identifier ]
1571
1592
else :
1572
- values = list (itertools .chain (* map (lambda x : x .split (';' ), args [1 :])))
1573
- self .vars [args [0 ]] = values
1593
+ self .vars [identifier ] = value .split (';' )
1574
1594
1575
1595
def _cmake_unset (self , tline : CMakeTraceLine ):
1576
1596
# DOC: https://cmake.org/cmake/help/latest/command/unset.html
0 commit comments