File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -380,6 +380,52 @@ function checkCMakeSet(Iterator $files): int
380380 return $ status ;
381381};
382382
383+ /**
384+ * Check for obsolete usages of:
385+ * else(<condition>)
386+ * endif(<condition>)
387+ * endforeach(<loop-var>)
388+ * endwhile(<condition>)
389+ * endfunction(<name>)
390+ * endmacro(<name>)
391+ */
392+ function checkCMakeObsoleteEndCommands (Iterator $ files ): int
393+ {
394+ $ status = 0 ;
395+
396+ $ commands = [
397+ 'else ' ,
398+ 'endif ' ,
399+ 'endforeach ' ,
400+ 'endwhile ' ,
401+ 'endfunction ' ,
402+ 'endmacro ' ,
403+ ];
404+
405+ foreach ($ files as $ file ) {
406+ $ content = getCMakeCode ($ file );
407+
408+ foreach ($ commands as $ command ) {
409+ preg_match_all (
410+ '/^[ \t]*( ' . $ command . ')[ \t]*\((.+)\)/mi ' ,
411+ $ content ,
412+ $ matches ,
413+ PREG_SET_ORDER ,
414+ );
415+
416+ foreach ($ matches as $ match ) {
417+ $ foundCommand = $ match [1 ] ?? '' ;
418+ $ foundArgument = $ match [2 ] ?? '' ;
419+
420+ $ status = 1 ;
421+ output ("E: Replace $ foundCommand( $ foundArgument) with $ command() \n in $ file \n" );
422+ }
423+ }
424+ }
425+
426+ return $ status ;
427+ }
428+
383429/**
384430 * Find all local Find* modules in the project.
385431 */
@@ -673,6 +719,9 @@ function checkAll(array $options): int
673719 $ newStatus = checkCMakeSet ($ allCMakeFiles );
674720 $ status = (0 === $ status ) ? $ newStatus : $ status ;
675721
722+ $ newStatus = checkCMakeObsoleteEndCommands ($ allCMakeFiles );
723+ $ status = (0 === $ status ) ? $ newStatus : $ status ;
724+
676725 $ findModules = getFindModules ($ options ['path ' ] . '/cmake/cmake/modules ' );
677726 $ newStatus = checkFindModules ($ findModules , $ allCMakeFiles );
678727 $ status = (0 === $ status ) ? $ newStatus : $ status ;
You can’t perform that action at this time.
0 commit comments