@@ -404,7 +404,18 @@ def lua_list(items, ind):
404404def defines_lua (defset ):
405405 return "defines = { " + ", " .join (f'"{ D (f )} "' for f in sorted (defset )) + " }"
406406
407+ # base flag-globs vs dnn-feature flag-globs. Flag-globs for the dnn groups
408+ # (mlas/mlasgemm/protobuf/dnn) only match a source when the `dnn` feature is
409+ # on; kept in the base `flags` they glob nothing in the default (feature-off)
410+ # profile -> mcpp 0.0.101 warns "[build].flags glob matched no source file".
411+ # mcpp#253 per-feature flags let them ride WITH the feature (features.dnn.flags),
412+ # so they resolve exactly when their sources do. (dnn-group flag-globs are
413+ # arch-specific for the per-ISA entries -> they land per-OS via merge_opencv.lua.)
407414flags_entries = []
415+ dnn_flags_entries = []
416+ def is_dnn_glob (g ):
417+ return any (m in g for m in ("3rdparty/mlas" , "3rdparty/protobuf" ,
418+ "modules/dnn" , "tu/mlasgemm" ))
408419# curated exception: mlas/lib/platform.cpp calls syscall(2); glibc hides it
409420# under __STRICT_ANSI__ (-std=c++NN). The reference build's gcc13 tolerated
410421# this only because ninja -k discards the object; consumers must compile it,
@@ -416,7 +427,8 @@ def defines_lua(defset):
416427 key = "cflags" if dk in ("zlib" , "png" , "jpeg" , "jpeg12" , "jpeg16" ) else "cxxflags"
417428 parts = [f'glob = "{ GROUP_GLOB [dk ]} "' ]
418429 if dir_defs [dk ]: parts .append (defines_lua (dir_defs [dk ]))
419- flags_entries .append ("{ " + ", " .join (parts ) + " }," )
430+ (dnn_flags_entries if dk in FEATURE_DNN_GROUPS else flags_entries ).append (
431+ "{ " + ", " .join (parts ) + " }," )
420432if ("jpeg-asm" , None ) in groups :
421433 cs = groups [("jpeg-asm" , None )]
422434 common = frozenset .intersection (* [c [2 ] for c in cs ])
@@ -426,17 +438,18 @@ def defines_lua(defset):
426438 ms = ", " .join (f'"{ m } "' for m in isa_m [(dk , isa )])
427439 g = GROUP_GLOB [dk ]
428440 g = (g [:- 3 ] if g .endswith ("/**" ) else g ) + f"/**/*.{ isa } .cpp"
429- flags_entries .append (
441+ ( dnn_flags_entries if dk in FEATURE_DNN_GROUPS else flags_entries ) .append (
430442 f'{{ glob = "{ g } ", defines = {{ { ds } }}, cxxflags = {{ { ms } }} }},' )
431443for mod , dk in sorted (kernel_files ):
432444 flags_entries .append (
433445 f'{{ glob = "**/clsrc/opencl_kernels_{ mod } .cpp", ' + defines_lua (dir_defs [dk ]) + " }," )
434446for g , extra in sorted (per_file_flag_entries ):
435- flags_entries .append (f'{{ glob = "{ g } ", ' + defines_lua (extra ) + " }," )
447+ (dnn_flags_entries if is_dnn_glob (g ) else flags_entries ).append (
448+ f'{{ glob = "{ g } ", ' + defines_lua (extra ) + " }," )
436449# curated exception #2: mlas/lib/platform.cpp calls syscall(2) but includes
437450# only <sys/syscall.h> (the prototype lives in <unistd.h>; upstream
438451# toolchains leak it transitively, the hermetic glibc does not).
439- flags_entries .append ('{ glob = "*/3rdparty/mlas/lib/platform.cpp", cxxflags = { "-include", "unistd.h" } },' )
452+ dnn_flags_entries .append ('{ glob = "*/3rdparty/mlas/lib/platform.cpp", cxxflags = { "-include", "unistd.h" } },' )
440453
441454# upstream reference uses -std=c++17; the index floor is c++23 and the whole
442455# TU set builds green under gcc16 -std=c++23 (validated by the O0 spike).
@@ -464,6 +477,7 @@ def defines_lua(defset):
464477sources_dnn_out .append ("mcpp_generated/mlas_hgemm_stub.cpp" )
465478
466479dnn_sources_lua = lua_list (sources_dnn_out , " " * 20 )
480+ dnn_flags_lua = ("\n " + " " * 20 ).join (dnn_flags_entries )
467481n_dnn = len (sources_dnn )
468482L = []
469483L .append (f"""-- Auto-generated by tools/compat-opencv/gen_descriptor.py — do not edit by hand.
@@ -530,6 +544,9 @@ def defines_lua(defset):
530544 }},
531545 ["dnn"] = {{
532546 defines = {{ "HAVE_OPENCV_DNN" }},
547+ flags = {{
548+ { dnn_flags_lua }
549+ }},
533550 sources = {{
534551 { dnn_sources_lua }
535552 }},
0 commit comments