@@ -191,6 +191,7 @@ function getProjectModules(): array
191191 'FindPackageMessage ' => ['find_package_message ' ],
192192 'ProcessorCount ' => ['processorcount ' ],
193193 'PHP/AddCustomCommand ' => ['php_add_custom_command ' ],
194+ 'PHP/Bison ' => ['php_bison ' , '/find_package\([\n ]*BISON/ ' ],
194195 'PHP/CheckAttribute ' => [
195196 'php_check_function_attribute ' ,
196197 'php_check_variable_attribute ' ,
@@ -199,6 +200,7 @@ function getProjectModules(): array
199200 'PHP/ConfigureFile ' => ['php_configure_file ' ],
200201 'PHP/Install ' => ['php_install ' ],
201202 'PHP/PkgConfigGenerator ' => ['pkgconfig_generate_pc ' ],
203+ 'PHP/Re2c ' => ['php_re2c ' , '/find_package\([\n ]*RE2C/ ' ],
202204 'PHP/SearchLibraries ' => ['php_search_libraries ' ],
203205 'PHP/Set ' => ['php_set ' ],
204206 'PHP/SystemExtensions ' => ['PHP::SystemExtensions ' ],
@@ -273,24 +275,29 @@ function checkCMakeInclude(Iterator $files, array $modules): int
273275 $ content = getCMakeCode ($ file );
274276
275277 // Check for redundant includes.
276- foreach ($ modules as $ module => $ commands ) {
278+ foreach ($ modules as $ module => $ patterns ) {
277279 $ hasModule = false ;
278280 $ moduleEscaped = str_replace ('/ ' , '\/ ' , $ module );
279281
280282 if (1 === preg_match ('/^[ \t]*include[ \t]*\( ' . $ moduleEscaped . '[ \t]*\)/m ' , $ content )) {
281283 $ hasModule = true ;
282284 }
283285
284- $ hasCommand = false ;
285- foreach ($ commands as $ command ) {
286- if (
286+ $ hasPattern = false ;
287+ foreach ($ patterns as $ pattern ) {
288+ if (isRegularExpression ($ pattern )) {
289+ if (1 === preg_match ($ pattern , $ content )) {
290+ $ hasPattern = true ;
291+ break ;
292+ }
293+ } elseif (
287294 (
288- 1 === preg_match ('/::/ ' , $ command )
289- && 1 === preg_match ('/[^A-Za-z0-9_] ' . $ command . '[^A-Za-z0-9_]/m ' , $ content )
295+ 1 === preg_match ('/::/ ' , $ pattern )
296+ && 1 === preg_match ('/[^A-Za-z0-9_] ' . $ pattern . '[^A-Za-z0-9_]/m ' , $ content )
290297 )
291- || 1 === preg_match ('/^[ \t]* ' . $ command . '[ \t]*\(/m ' , $ content )
298+ || 1 === preg_match ('/^[ \t]* ' . $ pattern . '[ \t]*\(/m ' , $ content )
292299 ) {
293- $ hasCommand = true ;
300+ $ hasPattern = true ;
294301 break ;
295302 }
296303 }
@@ -304,12 +311,12 @@ function checkCMakeInclude(Iterator $files, array $modules): int
304311 continue ;
305312 }
306313
307- if ($ hasModule && !$ hasCommand ) {
314+ if ($ hasModule && !$ hasPattern ) {
308315 $ status = 1 ;
309316 output ("E: redundant include( $ module) in $ file " );
310317 }
311318
312- if (!$ hasModule && $ hasCommand ) {
319+ if (!$ hasModule && $ hasPattern ) {
313320 $ status = 1 ;
314321 output ("E: missing include( $ module) in $ file " );
315322 }
@@ -319,6 +326,18 @@ function checkCMakeInclude(Iterator $files, array $modules): int
319326 return $ status ;
320327};
321328
329+ /**
330+ * Check if given string is regular expression.
331+ */
332+ function isRegularExpression (string $ string ): bool
333+ {
334+ set_error_handler (static function () {}, E_WARNING );
335+ $ isRegularExpression = false !== preg_match ($ string , '' );
336+ restore_error_handler ();
337+
338+ return $ isRegularExpression ;
339+ }
340+
322341/**
323342 * Check for set(<variable>) usages with only one argument. These should be
324343 * replaced with set(<variable> "").
0 commit comments