diff --git a/.github/workflows/default.yml b/.github/workflows/default.yml index 598ced7..9da97bf 100644 --- a/.github/workflows/default.yml +++ b/.github/workflows/default.yml @@ -54,7 +54,9 @@ jobs: - name: Build env: CMAKE_PREFIX_PATH: ${{ env.QT6_PREFIX }} - run: cargo build --verbose - + run: | + cmake -B build -S . -DCMAKE_BUILD_TYPE=Release -DRUST_VERBOSE=ON + cmake --build build + - name: Test - run: cargo test --verbose + run: ctest --test-dir build --output-on-failure diff --git a/.gitignore b/.gitignore index 246a110..79bc20f 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,6 @@ **/cmake_install.cmake **/Makefile **/compile_commands.json +**/Testing/ output.txt *.code-workspace diff --git a/CMakeLists.txt b/CMakeLists.txt index f4e477d..6e79550 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,4 +7,44 @@ project(tlockr_qt LANGUAGES CXX) add_subdirectory(cpp) -set_property(GLOBAL PROPERTY USE_FOLDERS ON) \ No newline at end of file +set_property(GLOBAL PROPERTY USE_FOLDERS ON) + +set(CARGO_MANIFEST_PATH ${CMAKE_CURRENT_SOURCE_DIR}/Cargo.toml) +set(CARGO_TARGET_DIR ${CMAKE_CURRENT_BINARY_DIR}/target) + +option(RUST_VERBOSE "Enable verbose output for Cargo build and test" OFF) + +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + set(CARGO_PROFILE "") + set(CARGO_OUTPUT ${CARGO_TARGET_DIR}/debug/tlockr) +else() + set(CARGO_PROFILE "--release") + set(CARGO_OUTPUT ${CARGO_TARGET_DIR}/release/tlockr) +endif() + +if(RUST_VERBOSE) + set(CARGO_VERBOSE "--verbose") +else() + set(CARGO_VERBOSE "") +endif() + +add_custom_command( + OUTPUT ${CARGO_OUTPUT} + COMMAND cargo build ${CARGO_PROFILE} ${CARGO_VERBOSE} --manifest-path ${CARGO_MANIFEST_PATH} --target-dir ${CARGO_TARGET_DIR} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT "Building tlockr with Cargo (${CMAKE_BUILD_TYPE})" + DEPENDS tlockr_qt +) + +add_custom_target(tlockr ALL + DEPENDS ${CARGO_OUTPUT} +) + +add_test(NAME rust_tests + COMMAND cargo test ${CARGO_VERBOSE} --manifest-path ${CARGO_MANIFEST_PATH} --target-dir ${CARGO_TARGET_DIR} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +) + +set_tests_properties(rust_tests PROPERTIES + DEPENDS tlockr +) diff --git a/README.md b/README.md index 50dd979..11c53f2 100644 --- a/README.md +++ b/README.md @@ -54,10 +54,12 @@ You can then proceed to the building step. You will need: ```sh $ cd tlockr -$ cargo build --release +$ mkdir build && cd build +$ cmake -DCMAKE_BUILD_TYPE=Release .. +$ make -j${nproc} ``` -The compiled binary can be found at `target/release/tlockr`. +The compiled binary can be found at `build/target/release/tlockr`. ## Themes diff --git a/build.rs b/build.rs index 6b0872d..5856414 100644 --- a/build.rs +++ b/build.rs @@ -7,14 +7,12 @@ */ use std::env; -use std::path::PathBuf; fn main() { - let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); - - let dst = cmake::Config::new(".").out_dir(&out_dir).build(); - - println!("cargo:rustc-link-search=native={}/lib", dst.display()); + println!( + "cargo:rustc-link-search=native={}/build/cpp", + env!("CARGO_MANIFEST_DIR") + ); println!("cargo:rustc-link-lib=static=tlockr_qt"); println!("cargo:rustc-link-lib=Qt6Quick");