3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
5
import 'dart:math' ;
6
+ import 'dart:io' ;
6
7
7
8
import 'package:logging/logging.dart' ;
8
9
import 'package:native_assets_cli/code_assets.dart' ;
@@ -348,6 +349,21 @@ class RunCBuilder {
348
349
archiver_ = await archiver ();
349
350
}
350
351
352
+ // create temporary "Name Forced Include" file
353
+ final nfiFile = File .fromUri (outDir.resolve ('nfi.txt' ));
354
+ // add each preprocessor definition to the file
355
+ for (final MapEntry (key: name, : value) in defines.entries) {
356
+ (value == null )
357
+ ? await nfiFile.writeAsString (
358
+ '#ifndef $name \n #define $name \n #endif\n ' ,
359
+ mode: FileMode .append,
360
+ )
361
+ : await nfiFile.writeAsString (
362
+ '#ifndef $name \n #define $name $value \n #endif\n ' ,
363
+ mode: FileMode .append,
364
+ );
365
+ }
366
+
351
367
final result = await runProcess (
352
368
executable: tool.uri,
353
369
arguments: [
@@ -356,8 +372,7 @@ class RunCBuilder {
356
372
if (std != null ) '/std:$std ' ,
357
373
if (language == Language .cpp) '/TP' ,
358
374
...flags,
359
- for (final MapEntry (key: name, : value) in defines.entries)
360
- if (value == null ) '/D$name ' else '/D$name =$value ' ,
375
+ ...defines.isNotEmpty ? ['/FI${nfiFile .path }' ] : [],
361
376
for (final directory in includes) '/I${directory .toFilePath ()}' ,
362
377
if (executable != null ) ...[
363
378
...sources.map ((e) => e.toFilePath ()),
0 commit comments