diff --git a/cmd/genbindings/README.md b/cmd/genbindings/README.md index 665cf1ee..41030393 100644 --- a/cmd/genbindings/README.md +++ b/cmd/genbindings/README.md @@ -31,5 +31,5 @@ It's tested to work on with Debian 12 / Qt 5.15 / Clang 14 / GCC 12. You should check the following configuration: -- `main.go`: Input directories containing Qt headers -- `exceptions.go`: Check everything +- `config-libraries.go`: Input directories containing Qt headers +- `config-allowlist.go`: Check everything diff --git a/cmd/genbindings/exceptions.go b/cmd/genbindings/config-allowlist.go similarity index 100% rename from cmd/genbindings/exceptions.go rename to cmd/genbindings/config-allowlist.go diff --git a/cmd/genbindings/config-libraries.go b/cmd/genbindings/config-libraries.go new file mode 100644 index 00000000..c8e9ecc7 --- /dev/null +++ b/cmd/genbindings/config-libraries.go @@ -0,0 +1,90 @@ +package main + +import ( + "path/filepath" +) + +func ProcessLibraries(clangBin, outDir, extraLibsDir string) { + + flushKnownTypes() + InsertTypedefs(false) + + generate( + "qt", + []string{ + "/usr/include/x86_64-linux-gnu/qt5/QtCore", + "/usr/include/x86_64-linux-gnu/qt5/QtGui", + "/usr/include/x86_64-linux-gnu/qt5/QtWidgets", + }, + clangBin, + pkgConfigCflags("Qt5Widgets"), + outDir, + ClangMatchSameHeaderDefinitionOnly, + ) + + generate( + "qt/qprintsupport", + []string{ + "/usr/include/x86_64-linux-gnu/qt5/QtPrintSupport", + }, + clangBin, + pkgConfigCflags("Qt5PrintSupport"), + outDir, + ClangMatchSameHeaderDefinitionOnly, + ) + + // Depends on QtCore/Gui/Widgets, QPrintSupport + generate( + "qt-restricted-extras/qscintilla", + []string{ + "/usr/include/x86_64-linux-gnu/qt5/Qsci", + }, + clangBin, + pkgConfigCflags("Qt5PrintSupport"), + outDir, + ClangMatchSameHeaderDefinitionOnly, + ) + + // Depends on QtCore/Gui/Widgets + generate( + "qt-extras/scintillaedit", + []string{ + filepath.Join(extraLibsDir, "scintilla/qt/ScintillaEdit/ScintillaEdit.h"), + }, + clangBin, + "--std=c++1z "+pkgConfigCflags("ScintillaEdit"), + outDir, + (&clangMatchUnderPath{filepath.Join(extraLibsDir, "scintilla")}).Match, + ) + + // FLUSH all known typedefs / ... + + flushKnownTypes() + InsertTypedefs(true) + + // Qt 6 + generate( + "qt6", + []string{ + "/usr/include/x86_64-linux-gnu/qt6/QtCore", + "/usr/include/x86_64-linux-gnu/qt6/QtGui", + "/usr/include/x86_64-linux-gnu/qt6/QtWidgets", + }, + clangBin, + "--std=c++17 "+pkgConfigCflags("Qt6Widgets"), + outDir, + ClangMatchSameHeaderDefinitionOnly, + ) + + // Qt 6 QtPrintSupport + generate( + "qt6/qprintsupport", + []string{ + "/usr/include/x86_64-linux-gnu/qt6/QtPrintSupport", + }, + clangBin, + "--std=c++17 "+pkgConfigCflags("Qt6PrintSupport"), + outDir, + ClangMatchSameHeaderDefinitionOnly, + ) +} diff --git a/cmd/genbindings/main.go b/cmd/genbindings/main.go index 143db35f..9b1fc3c9 100644 --- a/cmd/genbindings/main.go +++ b/cmd/genbindings/main.go @@ -92,97 +92,7 @@ func pkgConfigCflags(packageName string) string { return string(stdout) } -func main() { - clang := flag.String("clang", "clang", "Custom path to clang") - outDir := flag.String("outdir", "../../", "Output directory for generated gen_** files") - extraLibsDir := flag.String("extralibs", "/usr/local/src/", "Base directory to find extra library checkouts") - - flag.Parse() - - flushKnownTypes() - InsertTypedefs(false) - - generate( - "qt", - []string{ - "/usr/include/x86_64-linux-gnu/qt5/QtCore", - "/usr/include/x86_64-linux-gnu/qt5/QtGui", - "/usr/include/x86_64-linux-gnu/qt5/QtWidgets", - }, - *clang, - strings.Fields(pkgConfigCflags("Qt5Widgets")), - *outDir, - ClangMatchSameHeaderDefinitionOnly, - ) - - generate( - "qt/qprintsupport", - []string{ - "/usr/include/x86_64-linux-gnu/qt5/QtPrintSupport", - }, - *clang, - strings.Fields(pkgConfigCflags("Qt5PrintSupport")), - *outDir, - ClangMatchSameHeaderDefinitionOnly, - ) - - // Depends on QtCore/Gui/Widgets, QPrintSupport - generate( - "qt-restricted-extras/qscintilla", - []string{ - "/usr/include/x86_64-linux-gnu/qt5/Qsci", - }, - *clang, - strings.Fields(pkgConfigCflags("Qt5PrintSupport")), - *outDir, - ClangMatchSameHeaderDefinitionOnly, - ) - - // Depends on QtCore/Gui/Widgets - generate( - "qt-extras/scintillaedit", - []string{ - filepath.Join(*extraLibsDir, "scintilla/qt/ScintillaEdit/ScintillaEdit.h"), - }, - *clang, - strings.Fields("--std=c++1z "+pkgConfigCflags("ScintillaEdit")), - *outDir, - (&clangMatchUnderPath{filepath.Join(*extraLibsDir, "scintilla")}).Match, - ) - - // FLUSH all known typedefs / ... - - flushKnownTypes() - InsertTypedefs(true) - - // Qt 6 - generate( - "qt6", - []string{ - "/usr/include/x86_64-linux-gnu/qt6/QtCore", - "/usr/include/x86_64-linux-gnu/qt6/QtGui", - "/usr/include/x86_64-linux-gnu/qt6/QtWidgets", - }, - *clang, - strings.Fields("--std=c++17 "+pkgConfigCflags("Qt6Widgets")), - *outDir, - ClangMatchSameHeaderDefinitionOnly, - ) - - // Qt 6 QtPrintSupport - generate( - "qt6/qprintsupport", - []string{ - "/usr/include/x86_64-linux-gnu/qt6/QtPrintSupport", - }, - *clang, - strings.Fields("--std=c++17 "+pkgConfigCflags("Qt6PrintSupport")), - *outDir, - ClangMatchSameHeaderDefinitionOnly, - ) -} - -func generate(packageName string, srcDirs []string, clangBin string, cflags []string, outDir string, matcher ClangMatcher) { +func generate(packageName string, srcDirs []string, clangBin, cflagsCombined, outDir string, matcher ClangMatcher) { var includeFiles []string for _, srcDir := range srcDirs { @@ -195,6 +105,8 @@ func generate(packageName string, srcDirs []string, clangBin string, cflags []st log.Printf("Found %d header files to process.", len(includeFiles)) + cflags := strings.Fields(cflagsCombined) + outDir = filepath.Join(outDir, packageName) cleanGeneratedFilesInDir(outDir) @@ -396,3 +308,13 @@ func generateClangCaches(includeFiles []string, clangBin string, cflags []string close(clangChan) clangWg.Wait() } + +func main() { + clang := flag.String("clang", "clang", "Custom path to clang") + outDir := flag.String("outdir", "../../", "Output directory for generated gen_** files") + extraLibsDir := flag.String("extralibs", "/usr/local/src/", "Base directory to find extra library checkouts") + + flag.Parse() + + ProcessLibraries(*clang, *outDir, *extraLibsDir) +}