Switch to CMake for Qt build

master
Fabien Freling 2019-05-11 15:56:42 +02:00
parent 2138179760
commit 761fc4aa90
8 changed files with 73 additions and 53 deletions

View File

@ -1,12 +1,15 @@
all:
dune build src/lib/oboy.exe
BUILD:=_build
# all:
# dune build src/core/oboy.exe
core:
dune build src/core/oboy.a
dune build src/core/oboy.so
cp _build/default/src/core/oboy.so $(BUILD)/liboboycore.so
check:
ocamlbuild -use-ocamlfind -I src -lflag -g test/test_bit.byte --
ocamlbuild -use-ocamlfind -I src -lflag -g test/test_interrupt.byte --
# check:
# ocamlbuild -use-ocamlfind -I src -lflag -g test/test_bit.byte --
# ocamlbuild -use-ocamlfind -I src -lflag -g test/test_interrupt.byte --
clean:
dune clean

View File

@ -1,3 +1,7 @@
(library
; oboy.ml as the top-level file
; building a shared library because we are relying on pthread and we cannot
; combine static pthread with dynamic libc
(executable
(name oboy)
(libraries threads))
(libraries threads)
(modes shared_object))

View File

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

View File

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

24
src/qt/CMakeLists.txt Normal file
View File

@ -0,0 +1,24 @@
cmake_minimum_required(VERSION 3.1)
project(oboy LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt5 COMPONENTS Core Quick REQUIRED)
add_executable(${PROJECT_NAME} "main.cpp" "qml.qrc")
target_compile_definitions(${PROJECT_NAME} PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Quick)
# OCaml
set(OCAML_ROOT "/usr/lib/ocaml")
target_include_directories(${PROJECT_NAME} PRIVATE ${OCAML_ROOT})
target_link_directories(${PROJECT_NAME} PRIVATE ${OCAML_ROOT} ${CMAKE_SOURCE_DIR}/../../_build)
target_link_libraries(${PROJECT_NAME} PRIVATE oboycore m dl asmrun)
#target_link_options(${PROJECT_NAME} PRIVATE -L${CMAKE_SOURCE_DIR}/../../_build -loboy)
#target_link_options(${PROJECT_NAME} PRIVATE -L${OCAML_ROOT} -lm -ldl -lasmrun)

View File

@ -1,13 +0,0 @@
unix:!android {
isEmpty(target.path) {
qnx {
target.path = /tmp/$${TARGET}/bin
} else {
target.path = /opt/$${TARGET}/bin
}
export(target.path)
}
INSTALLS += target
}
export(INSTALLS)

View File

@ -1,5 +1,7 @@
#include <QApplication>
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <iostream>
#include <string>
#include <caml/mlvalues.h>
#include <caml/callback.h>
@ -9,14 +11,38 @@ void load_caml(char *argv[])
caml_main(argv);
}
void print_closure(const std::string &closure_name) {
value * closure_f = caml_named_value(closure_name.c_str());
if (closure_f == nullptr) {
std::cerr << "ERROR: Unreachable closure " << closure_name << "\n";
return;
}
const char *str = String_val(caml_callback(*closure_f, Val_unit));
std::cout << closure_name << ": " << str << "\n";
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
engine.load(url);
load_caml(argv);
std::cout << "test std::cout" << "\n";
std::cerr << "test std::cerr" << "\n";
print_closure("name");
print_closure("version");
return app.exec();
}

View File

@ -1,21 +0,0 @@
TEMPLATE = app
QT += qml quick widgets
CONFIG += c++11
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
# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =
# Default rules for deployment.
include(deployment.pri)