From 738c15d654f67ec8aeccec2b46f5a0804c793491 Mon Sep 17 00:00:00 2001
From: Mathieu Féry <mfery@ankama.com>
Date: Thu, 15 Jun 2023 19:18:34 +0200
Subject: feat(feature): Enable pragma once management

---
 .../jogamp/gluegen/structgen/CStructAnnotationProcessor.java  | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

(limited to 'src/java/com/jogamp/gluegen/structgen/CStructAnnotationProcessor.java')

diff --git a/src/java/com/jogamp/gluegen/structgen/CStructAnnotationProcessor.java b/src/java/com/jogamp/gluegen/structgen/CStructAnnotationProcessor.java
index 13bf418..52c20e0 100644
--- a/src/java/com/jogamp/gluegen/structgen/CStructAnnotationProcessor.java
+++ b/src/java/com/jogamp/gluegen/structgen/CStructAnnotationProcessor.java
@@ -98,12 +98,15 @@ public class CStructAnnotationProcessor extends AbstractProcessor {
     }
 
     private static final String STRUCTGENOUTPUT_OPTION = "structgen.output";
+    private static final String STRUCTGENPRAGMA_ONCE = "structgen.enable.pragma.once";
     private static final String STRUCTGENOUTPUT = PropertyAccess.getProperty("jogamp.gluegen."+STRUCTGENOUTPUT_OPTION, true, "gensrc");
+    private static final String STRUCTGENPRAGMAONCE = PropertyAccess.getProperty("jogamp.gluegen."+STRUCTGENPRAGMA_ONCE, true, "false");
 
     private Filer filer;
     private Messager messager;
     private Elements eltUtils;
     private String outputPath;
+    private boolean enablePragmaOnce;
 
     private final static Set<String> generatedStructs = new HashSet<String>();
 
@@ -118,6 +121,9 @@ public class CStructAnnotationProcessor extends AbstractProcessor {
 
         outputPath = processingEnv.getOptions().get(STRUCTGENOUTPUT_OPTION);
         outputPath = outputPath == null ? STRUCTGENOUTPUT : outputPath;
+
+        final String enablePragmaOnceOpt = processingEnv.getOptions().get(STRUCTGENPRAGMAONCE);
+        enablePragmaOnce = Boolean.parseBoolean(enablePragmaOnceOpt == null ? STRUCTGENPRAGMAONCE : enablePragmaOnceOpt);
     }
 
     private File locateSource(final String packageName, final String relativeName) {
@@ -211,7 +217,7 @@ public class CStructAnnotationProcessor extends AbstractProcessor {
                 headerParent = root0.substring(0, root0.length()-headerFile.getName().length()-1);
                 rootOut = headerParent.substring(0, headerParent.length()-packageName.length()) + "..";
             }
-            System.err.println("CStruct: "+headerFile+", abs: "+headerFile.isAbsolute()+", headerParent "+headerParent+", rootOut "+rootOut);
+            System.err.println("CStruct: "+headerFile+", abs: "+headerFile.isAbsolute()+", headerParent "+headerParent+", rootOut "+rootOut+", enablePragmaOnce"+enablePragmaOnce);
 
             generateStructBinding(element, struct, isPackageOrType, rootOut, packageName, headerFile, headerParent);
         } catch (final IOException ex) {
@@ -276,7 +282,8 @@ public class CStructAnnotationProcessor extends AbstractProcessor {
             GlueGen.setDebug(true);
         }
         new GlueGen().run(reader, filename, AnnotationProcessorJavaStructEmitter.class,
-                          includePaths, cfgFiles, outputPath1, false /* copyCPPOutput2Stderr */);
+                          includePaths, cfgFiles, outputPath1, false /* copyCPPOutput2Stderr */,
+                          enablePragmaOnce /* enablePragmaOnce */);
 
         configFile.delete();
         generatedStructs.add(finalType);
-- 
cgit v1.2.3