Last active
August 6, 2020 18:40
-
-
Save handicraftsman/f99d2562fa8c987fa25572c290f5be75 to your computer and use it in GitHub Desktop.
CMakeRS.cmake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set(CMAKERS OFF) | |
if (NOT CMAKERS) | |
set(CMAKERS ON CACHE INTERNAL "" FORCE) | |
find_program(CMAKERS_CARGO cargo REQUIRED) | |
if (CMAKE_BUILD_TYPE STREQUAL "Release") | |
set(CMAKERS_RELEASE "--release") | |
set(CMAKERS_TDIR "release") | |
else () | |
set(CMAKERS_TDIR "debug") | |
endif () | |
macro (rust_crate RUST_NAME) | |
set(options IS_RELEASE) | |
set(oneval CRATE_DIR TARGET) | |
set(multival OUTPUTS) | |
cmake_parse_arguments(RUST "${options}" "${oneval}" "${multival}" ${ARGN}) | |
if (RUST_TARGET STREQUAL "host") | |
set(TARGET_ARGS) | |
set(TARGET_DIR "${RUST_CRATE_DIR}/target/${CMAKERS_TDIR}/") | |
else () | |
set(TARGET_ARGS "--target" "${RUST_TARGET}") | |
set(TARGET_DIR "${RUST_CRATE_DIR}/target/${RUST_TARGET}/${CMAKERS_TDIR}/") | |
endif () | |
foreach (o ${RUST_OUTPUTS}) | |
set(RUST_OUTPUTS_ ${RUST_OUTPUTS_} "${TARGET_DIR}/${o}") | |
endforeach () | |
add_custom_command( | |
COMMAND ${CMAKERS_CARGO} build ${TARGET_ARGS} ${CMAKERS_RELEASE} | |
WORKING_DIRECTORY ${RUST_CRATE_DIR} | |
OUTPUT ${RUST_OUTPUTS_} | |
USES_TERMINAL ON | |
COMMENT "Build crate `${RUST_NAME}` for `${RUST_TARGET}`" | |
) | |
add_custom_target( | |
"cmakers-${RUST_NAME}-${RUST_TARGET}" ALL | |
COMMAND ${CMAKE_COMMAND} -E copy ${RUST_OUTPUTS_} "${CMAKE_CURRENT_BINARY_DIR}" | |
DEPENDS ${RUST_OUTPUTS_} | |
) | |
endmacro () | |
endif () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment