Integrate OCaml in Qt project

This commit is contained in:
Fabien Freling 2019-05-08 23:09:31 +02:00
parent 3c0c2cff6f
commit dbc17bb003
8 changed files with 59 additions and 2 deletions

View file

@ -2,7 +2,7 @@ all:
dune build src/lib/oboy.exe dune build src/lib/oboy.exe
core: core:
dune build src/retroarch dune build src/core/oboy.a
check: check:
ocamlbuild -use-ocamlfind -I src -lflag -g test/test_bit.byte -- ocamlbuild -use-ocamlfind -I src -lflag -g test/test_bit.byte --

View file

@ -60,7 +60,7 @@ let power_up cartridge =
run cpu mem screen run cpu mem screen
let () = let main =
if Array.length Sys.argv < 2 then begin if Array.length Sys.argv < 2 then begin
prerr_endline "Please specify a ROM."; prerr_endline "Please specify a ROM.";
eprintf "Usage: %s path/to/rom\n" Sys.argv.(0); eprintf "Usage: %s path/to/rom\n" Sys.argv.(0);
@ -71,3 +71,6 @@ let () =
match cartridge with match cartridge with
| None -> print_endline "Invalid ROM file." | None -> print_endline "Invalid ROM file."
| Some c -> power_up c | Some c -> power_up c
(** let () =
main *)

6
src/core/version.ml Normal file
View file

@ -0,0 +1,6 @@
let name () = "oboy"
let version () = "1.0a"
let () =
Callback.register "name" name;
Callback.register "version" version;

19
src/qt/About.qml Normal file
View file

@ -0,0 +1,19 @@
import QtQuick 2.4
import QtQuick.Window 2.0
Window {
title: "About"
// A background map is 32 x 32 tiles.
// Each tile is 8 x 8 pixels.
width: 128
height: 128
maximumWidth: width
minimumWidth: width
maximumHeight: height
minimumHeight: height
Text {
id: name
text: qsTr("About name")
}
}

View file

@ -1,6 +1,14 @@
#include <QApplication> #include <QApplication>
#include <QQmlApplicationEngine> #include <QQmlApplicationEngine>
#include <caml/mlvalues.h>
#include <caml/callback.h>
void load_caml(char *argv[])
{
caml_main(argv);
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication app(argc, argv); QApplication app(argc, argv);
@ -8,5 +16,7 @@ int main(int argc, char *argv[])
QQmlApplicationEngine engine; QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
load_caml(argv);
return app.exec(); return app.exec();
} }

View file

@ -35,6 +35,18 @@ ApplicationWindow {
} }
} }
Menu {
title: qsTr("Help")
MenuItem {
text: qsTr("About")
onTriggered: {
var component = Qt.createComponent("About.qml")
var about = component.createObject(root)
about.show()
}
}
}
} }
MainForm { MainForm {

View file

@ -6,6 +6,12 @@ CONFIG += c++11
SOURCES += main.cpp SOURCES += main.cpp
# `ocamlc -where` = /usr/lib/ocaml
INCLUDEPATH += /usr/lib/ocaml
LIBS += -L/home/fabs/Code/oboy/_build/default/src/core -loboy # TODO: fix path to OCaml library
LIBS += -L/usr/lib/ocaml -lm -ldl -lasmrun # /usr/lib/ocaml/Makefile.config | grep NATIVECCLIBS
RESOURCES += qml.qrc RESOURCES += qml.qrc
# Additional import path used to resolve QML modules in Qt Creator's code model # Additional import path used to resolve QML modules in Qt Creator's code model

View file

@ -4,5 +4,6 @@
<file>MainForm.ui.qml</file> <file>MainForm.ui.qml</file>
<file>BackgroundMap.qml</file> <file>BackgroundMap.qml</file>
<file>BackgroundMapForm.ui.qml</file> <file>BackgroundMapForm.ui.qml</file>
<file>About.qml</file>
</qresource> </qresource>
</RCC> </RCC>