tycho: build script magic

master
an 2019-06-09 16:02:26 -04:00
parent 0b075b0276
commit 5fb8c710a9
11 changed files with 146 additions and 122 deletions

View File

@ -1,91 +0,0 @@
cmake_minimum_required(VERSION 3.14)
project(maraiah-tycho CXX)
include(FeatureSummary)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_FLAGS_DEBUGOPT "-O2 -g")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DQT_QML_DEBUG")
set(THREADS_PREFER_PTHREAD_FLAG ON)
set(CARGO_FLAGS)
if(CMAKE_BUILD_TYPE STREQUAL Release)
set(RUST_TARGET_DIR "release")
set(CARGO_FLAGS "${CARGO_FLAGS} --release")
else()
set(RUST_TARGET_DIR "debug")
endif()
set(CARGO_TARGET_DIR "${CMAKE_BINARY_DIR}/rust")
set(RUST_LIB "${CARGO_TARGET_DIR}/${RUST_TARGET_DIR}/libtycho.a")
find_package(Threads REQUIRED)
find_package(Qt5 5.6.0 CONFIG REQUIRED COMPONENTS Core Widgets)
feature_summary(
WHAT
ALL
INCLUDE_QUIET_PACKAGES
FATAL_ON_MISSING_REQUIRED_PACKAGES
)
add_custom_command(
OUTPUT "${RUST_LIB}"
COMMAND env CARGO_TARGET_DIR="${CARGO_TARGET_DIR}" cargo build -p maraiah-tycho ${CARGO_FLAGS}
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
COMMENT "Building Rust library"
)
add_custom_target(
test
COMMAND env CARGO_TARGET_DIR="${CARGO_TARGET_DIR}" cargo test
DEPENDS "${RUST_LIB}"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
)
add_custom_target(maraiah-tycho-rust DEPENDS "${RUST_LIB}")
add_executable(
maraiah-tycho
WIN32
source/tycho/headers/mapprops.h
source/tycho/headers/menu.h
source/tycho/headers/tycho.h
source/tycho/resources/resources.qrc
source/tycho/source/main.cc
source/tycho/source/mapprops.cc
source/tycho/source/menu.cc
source/tycho/ui/about.ui
source/tycho/ui/mapprops.ui
source/tycho/ui/mapview.ui
source/tycho/ui/menu.ui
source/tycho/ui/points.ui
)
set_target_properties(
maraiah-tycho
PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
)
target_include_directories(maraiah-tycho PUBLIC source/tycho/headers)
add_dependencies(maraiah-tycho maraiah-tycho-rust)
target_link_libraries(
maraiah-tycho
"${RUST_LIB}"
Threads::Threads
${CMAKE_DL_LIBS}
Qt5::Core
Qt5::Widgets
)
## EOF

View File

@ -3,8 +3,7 @@ name = "maraiah-leela"
version = "0.1.0"
authors = ["Alison Watson <marrub@greyserv.net>"]
description = "Maraiah testbed program."
edition = "2018"
edition = "2018"
[dependencies]
clap = "2"

View File

@ -0,0 +1,61 @@
cmake_minimum_required(VERSION 3.14)
cmake_policy(SET CMP0046 NEW)
cmake_policy(SET CMP0063 NEW)
cmake_policy(SET CMP0071 NEW)
project(maraiah-tycho-hermes CXX)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package(
Qt5 5.6.0
CONFIG
REQUIRED
COMPONENTS Core Widgets
)
add_library(
maraiah-tycho-hermes
SHARED
$ENV{OUT_DIR}/bindings.cc
$ENV{OUT_DIR}/bindings.h
headers/mapprops.h
headers/menu.h
headers/tycho.h
resources/resources.qrc
source/main.cc
source/mapprops.cc
source/menu.cc
ui/about.ui
ui/mapprops.ui
ui/mapview.ui
ui/menu.ui
ui/points.ui
)
set_target_properties(
maraiah-tycho-hermes
PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
)
target_include_directories(
maraiah-tycho-hermes
PUBLIC
headers
$ENV{OUT_DIR}
)
target_link_libraries(
maraiah-tycho-hermes
Qt5::Core
Qt5::Widgets
)
install(TARGETS maraiah-tycho-hermes)
## EOF

View File

@ -4,12 +4,16 @@ version = "0.1.0"
authors = ["Alison Sanderson <marrub@greyserv.net>"]
description = "Tycho map editor."
edition = "2018"
build = "build.rs"
[dependencies]
maraiah = {path = "../.."}
memmap = "0.7"
[lib]
[build-dependencies]
cmake = "0.1"
rust_qt_binding_generator = "0.3"
[[bin]]
name = "tycho"
path = "lib.rs"
crate-type = ["staticlib"]
path = "main.rs"

View File

@ -0,0 +1,10 @@
{
"cppFile": "",
"rust": {
"dir": "",
"interfaceModule": "interface",
"implementationModule": "implementation"
},
"objects": {
}
}

22
source/tycho/build.rs Normal file
View File

@ -0,0 +1,22 @@
use rust_qt_binding_generator::*;
use std::path::PathBuf;
fn main()
{
let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
let mut config = configuration::parse("bindings.json").unwrap();
config.overwrite_implementation = true;
config.cpp_file = out_dir.join("bindings.cc");
config.rust.dir = out_dir;
generate_bindings(&config).unwrap();
let dst = cmake::Config::new(".").build();
println!("cargo:rustc-link-search=native={}/lib", dst.display());
println!("cargo:rustc-link-lib=dylib=maraiah-tycho-hermes");
}
// EOF

View File

@ -1,16 +0,0 @@
use maraiah::durandal::ffi;
#[no_mangle]
pub extern "C" fn test_fn(fname: *const ffi::c_char)
{
let fname = unsafe {ffi::CStr::from_ptr(fname)};
println!("hello, world! from rust: {}", fname.to_str().unwrap());
}
/*
struct Project
{
}
*/
// EOF

29
source/tycho/main.rs Normal file
View File

@ -0,0 +1,29 @@
use maraiah::durandal::{err::*, ffi};
extern "C" {
fn main_cc(app_name: *mut ffi::c_char);
}
#[no_mangle]
unsafe extern "C" fn Ma_test_fn(fname: *const ffi::c_char)
{
let fname = ffi::CStr::from_ptr(fname);
println!("hello, world! from rust: {}", fname.to_str().unwrap());
}
fn main() -> ResultS<()>
{
println!("rust entry");
let mut args = std::env::args();
let app_name = args.next().ok_or(err_msg("bad launch name"))?;
let app_name = ffi::CString::new(app_name)?;
unsafe {
main_cc(app_name.into_raw());
}
Ok(())
}
// EOF

View File

@ -1,5 +1,5 @@
<RCC>
<qresource>
<qresource prefix="/">
<file>color/lines.png</file>
<file>color/map.png</file>
<file>color/points.png</file>

View File

@ -1,13 +1,19 @@
#include "menu.h"
#include <QApplication>
#include <cstdio>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Menu w;
w.show();
return a.exec();
extern "C" {
int main_cc(char *app_path)
{
puts("cc entry");
int argc = 1;
char *argv[] = {app_path, nullptr};
QApplication a(argc, argv);
Menu w;
w.show();
return a.exec();
}
}
// EOF

View File

@ -7,7 +7,7 @@
#include <QFileDialog>
#include <iostream>
extern "C" void test_fn(char const *fname);
extern "C" void Ma_test_fn(char const *fname);
Menu::Menu(QWidget *parent) :
QMainWindow(parent),
@ -35,7 +35,7 @@ void Menu::mapOpen()
QString(),
tr("Marathon Map files (*.scen *.sceA Map)"));
test_fn(qUtf8Printable(fname));
Ma_test_fn(qUtf8Printable(fname));
}
void Menu::openAbout()