2017-08-11 08:24:24 -07:00
|
|
|
|
2017-08-22 04:45:34 -07:00
|
|
|
SET(GENERATOR "${CMAKE_BINARY_DIR}/src/rust_qt_binding_generator")
|
2017-08-20 14:36:33 -07:00
|
|
|
include_directories("${CMAKE_CURRENT_BINARY_DIR}")
|
2017-08-11 12:55:51 -07:00
|
|
|
|
2017-08-12 05:03:11 -07:00
|
|
|
add_custom_target("clean-rust")
|
|
|
|
|
2017-08-11 12:55:51 -07:00
|
|
|
function(rust_test NAME DIRECTORY)
|
|
|
|
set(SRC "${CMAKE_CURRENT_SOURCE_DIR}")
|
|
|
|
set(DIR "${SRC}/${DIRECTORY}")
|
|
|
|
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT "${DIR}/src/interface.rs"
|
|
|
|
"${SRC}/${NAME}_rust.h"
|
|
|
|
# if the cpp file is marked GENERATED, CMake will not check it for moc
|
|
|
|
# "${SRC}/${NAME}_rust.cpp"
|
2017-11-20 00:05:48 -08:00
|
|
|
COMMAND "${GENERATOR}" "${SRC}/${NAME}.json"
|
2017-08-11 12:55:51 -07:00
|
|
|
MAIN_DEPENDENCY "${NAME}.json"
|
2017-08-22 04:45:34 -07:00
|
|
|
DEPENDS rust_qt_binding_generator
|
2017-08-11 12:55:51 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT "${DIR}/${RUST_TARGET_DIR}/librust.a"
|
2017-09-01 10:15:13 -07:00
|
|
|
COMMAND ${Cargo_EXECUTABLE} build ${RUST_BUILD_FLAG}
|
2017-08-12 04:41:49 -07:00
|
|
|
DEPENDS "${DIR}/src/lib.rs"
|
|
|
|
"${DIR}/src/implementation.rs"
|
|
|
|
"${DIR}/src/interface.rs"
|
2017-08-11 12:55:51 -07:00
|
|
|
WORKING_DIRECTORY "${DIR}"
|
|
|
|
)
|
|
|
|
add_custom_target("test_${DIRECTORY}"
|
|
|
|
DEPENDS "${DIR}/${RUST_TARGET_DIR}/librust.a")
|
|
|
|
|
|
|
|
add_executable("${NAME}" "${NAME}.cpp" "${NAME}_rust.cpp" "${NAME}_rust.h")
|
2017-08-20 14:36:33 -07:00
|
|
|
set_target_properties("${NAME}" PROPERTIES
|
|
|
|
CXX_STANDARD 11
|
|
|
|
CXX_STANDARD_REQUIRED ON
|
|
|
|
)
|
2017-08-11 12:55:51 -07:00
|
|
|
add_dependencies("${NAME}" "test_${DIRECTORY}")
|
|
|
|
target_link_libraries("${NAME}"
|
|
|
|
Qt5::Core
|
|
|
|
Qt5::Test
|
|
|
|
"${DIR}/${RUST_TARGET_DIR}/librust.a"
|
2017-09-03 07:24:23 -07:00
|
|
|
Threads::Threads ${DL_LIBRARY}
|
2017-08-11 12:55:51 -07:00
|
|
|
)
|
|
|
|
set_property(TARGET ${NAME}
|
2017-08-11 14:47:56 -07:00
|
|
|
APPEND PROPERTY AUTOGEN_TARGET_DEPENDS "${SRC}/${NAME}_rust.h"
|
|
|
|
APPEND PROPERTY AUTOGEN_TARGET_DEPENDS "${SRC}/${NAME}_rust.cpp")
|
2017-08-11 12:55:51 -07:00
|
|
|
|
|
|
|
add_test("build_${NAME}"
|
|
|
|
"${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target "${NAME}")
|
|
|
|
add_test("${NAME}" "${NAME}")
|
|
|
|
set_tests_properties("${NAME}" PROPERTIES DEPENDS "build_${NAME}")
|
|
|
|
|
2017-08-12 05:03:11 -07:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT "clean_${NAME}"
|
2017-09-02 14:21:50 -07:00
|
|
|
COMMAND ${Cargo_EXECUTABLE} clean
|
2017-08-12 05:03:11 -07:00
|
|
|
WORKING_DIRECTORY "${DIR}"
|
|
|
|
)
|
|
|
|
add_custom_target("clean-${NAME}" DEPENDS "clean_${NAME}")
|
|
|
|
add_dependencies("clean-rust" "clean-${NAME}")
|
|
|
|
|
|
|
|
|
2017-08-11 12:55:51 -07:00
|
|
|
endfunction(rust_test)
|
|
|
|
|
|
|
|
rust_test(test_object rust_object)
|
|
|
|
rust_test(test_object_types rust_object_types)
|
2017-08-20 07:11:58 -07:00
|
|
|
rust_test(test_list rust_list)
|
2017-08-20 08:15:27 -07:00
|
|
|
rust_test(test_tree rust_tree)
|
2017-08-26 10:10:18 -07:00
|
|
|
rust_test(test_objects rust_objects)
|
2017-10-14 16:56:03 -07:00
|
|
|
rust_test(test_functions rust_functions)
|