Created
September 28, 2013 07:22
-
-
Save KokaKiwi/6739487 to your computer and use it in GitHub Desktop.
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
# Find Rust compiler and define some variables: | |
# - RUST_FOUND If Rust has been found. | |
# - RUST_VERSION Installed rust version. | |
# - RUST_EXECUTABLE 'rust' executable path | |
# - RUSTC_EXECUTABLE 'rustc' executable path | |
find_program(RUST_EXECUTABLE | |
NAMES | |
rust | |
PATHS | |
ENV PATH | |
${RUST_ROOT_DIR} | |
DOC | |
"'rust' executable path" | |
) | |
find_program(RUSTC_EXECUTABLE | |
NAMES | |
rustc | |
PATHS | |
/bin | |
/usr/bin | |
${RUST_ROOT_DIR} | |
DOC | |
"'rustc' executable path" | |
) | |
if (RUST_EXECUTABLE AND RUSTC_EXECUTABLE) | |
execute_process( | |
COMMAND | |
${RUST_EXECUTABLE} -v | |
OUTPUT_VARIABLE | |
RUST_VERSION_FULL | |
OUTPUT_STRIP_TRAILING_WHITESPACE | |
) | |
string(REGEX REPLACE | |
".*rust ([0-9]+(\\.[0-9]+)*).*" | |
"\\1" | |
RUST_VERSION ${RUST_VERSION_FULL} | |
) | |
macro (rust_add_executable TARGET_NAME) | |
set(SOURCES ${ARGN}) | |
set(OUTPUT_NAME ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}) | |
add_custom_command( | |
OUTPUT | |
${OUTPUT_NAME} | |
COMMAND | |
${RUSTC_EXECUTABLE} | |
ARGS | |
-o ${OUTPUT_NAME} | |
${SOURCES} | |
DEPENDS | |
${SOURCES} | |
WORKING_DIRECTORY | |
${CMAKE_CURRENT_SOURCE_DIR} | |
COMMENT | |
"Building ${TARGET_NAME}" | |
VERBATIM | |
) | |
endmacro (rust_add_executable) | |
endif (RUST_EXECUTABLE AND RUSTC_EXECUTABLE) | |
# handle the QUIETLY and REQUIRED arguments and set RUST_FOUND to TRUE if | |
# all listed variables are TRUE | |
include(FindPackageHandleStandardArgs) | |
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Rust | |
REQUIRED_VARS | |
RUST_EXECUTABLE | |
RUSTC_EXECUTABLE | |
VERSION_VAR | |
RUST_VERSION | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment