diff --git a/.gitignore b/.gitignore index 76721d87..e24e1d2b 100644 --- a/.gitignore +++ b/.gitignore @@ -21,11 +21,9 @@ vendor /conf.log /conf.pri /Makefile -/src/cpp/Makefile -/src/cpp/cpp/Makefile -/src/cpp/tests/Makefile /src/runner/certs/*.crt /src/runner/certs/*.key +/postbuild/conf.pri /postbuild/Makefile /postbuild/*.inst /config diff --git a/build.rs b/build.rs index 21a668d7..73bd2e98 100644 --- a/build.rs +++ b/build.rs @@ -1,6 +1,7 @@ use std::collections::HashMap; use std::env; use std::error::Error; +use std::ffi::OsStr; use std::fs; use std::io::{self, BufRead, BufReader, Write}; use std::path::{Path, PathBuf}; @@ -218,17 +219,18 @@ fn main() -> Result<(), Box> { let run_dir = env_or_default("RUNDIR", &default_vars); let root_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR")?); - let cpp_src_dir = root_dir.join(Path::new("src/cpp")); - let cpp_lib_dir = root_dir.join(Path::new("target/cpp")); + let cpp_src_dir = root_dir.join("src/cpp"); + let cpp_tests_src_dir = root_dir.join("src/cpp/tests"); + let cpp_out_dir = root_dir.join("target/cpp"); for dir in ["moc", "obj", "test-moc", "test-obj", "test-work"] { - fs::create_dir_all(cpp_lib_dir.join(Path::new(dir)))?; + fs::create_dir_all(cpp_out_dir.join(dir))?; } - write_cpp_conf_pri(&cpp_lib_dir.join(Path::new("conf.pri")))?; + write_cpp_conf_pri(&cpp_out_dir.join("conf.pri"))?; write_postbuild_conf_pri( - &Path::new("target").join(Path::new("postbuild_conf.pri")), + &Path::new("postbuild").join("conf.pri"), &bin_dir, &lib_dir, &config_dir, @@ -236,19 +238,37 @@ fn main() -> Result<(), Box> { &log_dir, )?; - if !cpp_src_dir.join("Makefile").try_exists()? { - assert!(Command::new(&qmake_path) - .args(["-o", "Makefile", "cpp.pro"]) - .current_dir(&cpp_src_dir) - .status()? - .success()); - } + assert!(Command::new(&qmake_path) + .args([ + OsStr::new("-o"), + cpp_out_dir.join("Makefile").as_os_str(), + cpp_src_dir.join("cpp.pro").as_os_str(), + ]) + .status()? + .success()); + + assert!(Command::new(&qmake_path) + .args([ + OsStr::new("-o"), + cpp_out_dir.join("Makefile.test").as_os_str(), + cpp_tests_src_dir.join("tests.pro").as_os_str(), + ]) + .status()? + .success()); let proc_count = thread::available_parallelism().map_or(1, |x| x.get()); assert!(Command::new("make") + .args(["-f", "Makefile"]) + .args(["-j", &proc_count.to_string()]) + .current_dir(&cpp_out_dir) + .status()? + .success()); + + assert!(Command::new("make") + .args(["-f", "Makefile.test"]) .args(["-j", &proc_count.to_string()]) - .current_dir(&cpp_src_dir) + .current_dir(&cpp_out_dir) .status()? .success()); @@ -256,7 +276,7 @@ fn main() -> Result<(), Box> { println!("cargo:rustc-env=CONFIG_DIR={}/pushpin", config_dir); println!("cargo:rustc-env=LIB_DIR={}/pushpin", lib_dir); - println!("cargo:rustc-link-search={}", cpp_lib_dir.display()); + println!("cargo:rustc-link-search={}", cpp_out_dir.display()); #[cfg(target_os = "macos")] println!( @@ -267,6 +287,7 @@ fn main() -> Result<(), Box> { #[cfg(not(target_os = "macos"))] println!("cargo:rustc-link-search={}", qt_install_libs.display()); + println!("cargo:rerun-if-env-changed=RELEASE"); println!("cargo:rerun-if-env-changed=PREFIX"); println!("cargo:rerun-if-env-changed=BINDIR"); println!("cargo:rerun-if-env-changed=CONFIGDIR"); diff --git a/postbuild/postbuild.pro b/postbuild/postbuild.pro index efa71a69..d6c954cb 100644 --- a/postbuild/postbuild.pro +++ b/postbuild/postbuild.pro @@ -1,6 +1,6 @@ TEMPLATE = aux -include($$OUT_PWD/../target/postbuild_conf.pri) +include(conf.pri) root_dir = $$PWD/.. bin_dir = $$root_dir/bin diff --git a/src/Makefile b/src/Makefile index b6b960fd..4a1b6ead 100644 --- a/src/Makefile +++ b/src/Makefile @@ -16,3 +16,5 @@ distclean: clean check: cd .. && cargo test $(cargo_flags) + +install: diff --git a/src/cpp/cpp/cpp.pri b/src/cpp/cpp.pri similarity index 99% rename from src/cpp/cpp/cpp.pri rename to src/cpp/cpp.pri index 171cd49c..5df2767b 100644 --- a/src/cpp/cpp/cpp.pri +++ b/src/cpp/cpp.pri @@ -2,7 +2,7 @@ QMAKE_CXXFLAGS += $$(CXXFLAGS) QMAKE_CFLAGS += $$(CFLAGS) QMAKE_LFLAGS += $$(LDFLAGS) -SRC_DIR = $$PWD/.. +SRC_DIR = $$PWD QZMQ_DIR = $$SRC_DIR/qzmq RUST_DIR = $$SRC_DIR/../rust diff --git a/src/cpp/cpp.pro b/src/cpp/cpp.pro index 14cbda40..7603edb7 100644 --- a/src/cpp/cpp.pro +++ b/src/cpp/cpp.pro @@ -1,9 +1,15 @@ -TEMPLATE = subdirs +TEMPLATE = lib +CONFIG -= app_bundle +CONFIG += staticlib c++11 +QT -= gui +QT += network +TARGET = pushpin-cpp +DESTDIR = ../../target/cpp -cpp.subdir = cpp +cpp_build_dir = $$OUT_PWD -tests.subdir = tests +MOC_DIR = $$cpp_build_dir/moc +OBJECTS_DIR = $$cpp_build_dir/obj -SUBDIRS += \ - cpp \ - tests +include($$cpp_build_dir/conf.pri) +include(cpp.pri) diff --git a/src/cpp/cpp/cpp.pro b/src/cpp/cpp/cpp.pro deleted file mode 100644 index 2fd2a390..00000000 --- a/src/cpp/cpp/cpp.pro +++ /dev/null @@ -1,15 +0,0 @@ -TEMPLATE = lib -CONFIG -= app_bundle -CONFIG += staticlib c++11 -QT -= gui -QT += network -TARGET = pushpin-cpp -DESTDIR = ../../../target/cpp - -cpp_build_dir = $$OUT_PWD/../../../target/cpp - -MOC_DIR = $$cpp_build_dir/moc -OBJECTS_DIR = $$cpp_build_dir/obj - -include($$OUT_PWD/../../../target/cpp/conf.pri) -include(cpp.pri) diff --git a/src/cpp/tests/tests.pro b/src/cpp/tests/tests.pro index 7a3503f7..834a108e 100644 --- a/src/cpp/tests/tests.pro +++ b/src/cpp/tests/tests.pro @@ -6,7 +6,7 @@ QT *= network testlib TARGET = pushpin-cpptest DESTDIR = ../../../target/cpp -cpp_build_dir = $$OUT_PWD/../../../target/cpp +cpp_build_dir = $$OUT_PWD MOC_DIR = $$cpp_build_dir/test-moc OBJECTS_DIR = $$cpp_build_dir/test-obj @@ -15,7 +15,7 @@ SRC_DIR = $$PWD/.. QZMQ_DIR = $$SRC_DIR/qzmq RUST_DIR = $$SRC_DIR/../rust -include($$PWD/../../../target/cpp/conf.pri) +include($$cpp_build_dir/conf.pri) INCLUDEPATH += $$SRC_DIR INCLUDEPATH += $$SRC_DIR/proxy