-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Expand file tree
/
Copy pathCMakeDetermineRustCompiler.cmake
More file actions
50 lines (38 loc) Β· 1.66 KB
/
CMakeDetermineRustCompiler.cmake
File metadata and controls
50 lines (38 loc) Β· 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file LICENSE.rst or https://cmake.org/licensing for details.
include(${CMAKE_ROOT}/Modules/CMakeDetermineCompiler.cmake)
if(NOT "${CMAKE_GENERATOR}" MATCHES "^Ninja")
message(FATAL_ERROR "Rust language not supported by \"${CMAKE_GENERATOR}\" generator")
endif()
set(CMAKE_Rust_COMPILER_INIT "rustc")
set(CMAKE_Rust_COMPILER_HINTS "$ENV{HOME}/.cargo/bin")
_cmake_find_compiler(Rust)
get_filename_component(RUSTC_REAL "${CMAKE_Rust_COMPILER}" REALPATH)
get_filename_component(RUSTC_FILENAME "${RUSTC_REAL}" NAME)
# When rustup is used for installing rust, rustc will just be a symlink to rustup. In such cases,
# we need to query rustup for underlying rustc path.
if(RUSTC_FILENAME STREQUAL "rustup")
get_filename_component(RUSTC_DIR "${CMAKE_Rust_COMPILER}" DIRECTORY)
set(RUSTUP_PATH "${RUSTC_DIR}/rustup")
# Fix RUSTUP_HOME in ctest.
if(RUSTC_FILENAME STREQUAL "rustup" AND NOT "$ENV{CTEST_REAL_HOME}" STREQUAL "" AND "$ENV{RUSTUP_HOME}" STREQUAL "")
set(ENV{RUSTUP_HOME} "$ENV{CTEST_REAL_HOME}/.rustup")
endif()
execute_process(
COMMAND ${RUSTUP_PATH} which rustc
OUTPUT_VARIABLE REAL_RUSTC
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE _rust_result
)
if(NOT _rust_result EQUAL 0 OR "${REAL_RUSTC}" STREQUAL "")
message(FATAL_ERROR "Failed to find path to real rustc")
endif()
set_property(CACHE CMAKE_Rust_COMPILER PROPERTY VALUE "${REAL_RUSTC}")
endif()
if(CMAKE_Rust_COMPILER)
set(CMAKE_Rust_COMPILER_WORKS TRUE)
endif()
configure_file(
"${CMAKE_ROOT}/Modules/CMakeRustCompiler.cmake.in"
"${CMAKE_PLATFORM_INFO_DIR}/CMakeRustCompiler.cmake"
@ONLY)