|
19 | 19 |
|
20 | 20 | # Find Rust executables and paths |
21 | 21 | # |
22 | | -# RUST_FOUND - True if rust was found |
23 | | -# CARGO_HOME - Cargo home folder |
24 | | -# CARGO_EXECUTABLE - Cargo package manager executable path |
25 | | -# RUSTC_EXECUTABLE - Rust compiler executable path |
26 | | -# RUSTC_SYSROOT - Rust compiler root location (includes binaries and libraries) |
27 | | -# RUSTC_LIBRARIES - Rust compiler runtime library list |
28 | | -# RUSTDOC_EXECUTABLE - Rust doc executable plath |
29 | | -# RUSTUP_EXECUTABLE - Rustup executable path |
30 | | -# RUST_GDB_EXECUTABLE - Rust GDB debugger executable path |
31 | | -# RUST_LLDB_EXECUTABLE - Rust LLDB debugger executable path |
| 22 | +# Rust_FOUND - True if rust was found |
| 23 | +# Rust_CARGO_HOME - Cargo home folder |
| 24 | +# Rust_CARGO_EXECUTABLE - Cargo package manager executable path |
| 25 | +# Rust_RUSTC_EXECUTABLE - Rust compiler executable path |
| 26 | +# Rust_RUSTC_VERSION - Rust compiler vesion string |
| 27 | +# Rust_RUSTC_SYSROOT - Rust compiler root location (includes binaries and libraries) |
| 28 | +# Rust_RUSTC_LIBRARIES - Rust compiler runtime library list |
| 29 | +# Rust_RUSTDOC_EXECUTABLE - Rust doc executable plath |
| 30 | +# Rust_RUSTUP_EXECUTABLE - Rustup executable path |
| 31 | +# Rust_GDB_EXECUTABLE - Rust GDB debugger executable path |
| 32 | +# Rust_LLDB_EXECUTABLE - Rust LLDB debugger executable path |
32 | 33 |
|
33 | 34 | if(WIN32) |
34 | 35 | set(USER_HOME "$ENV{USERPROFILE}") |
35 | 36 | else() |
36 | 37 | set(USER_HOME "$ENV{HOME}") |
37 | 38 | endif() |
38 | 39 |
|
39 | | -if(NOT DEFINED CARGO_HOME) |
40 | | - if("$ENV{CARGO_HOME}" STREQUAL "") |
41 | | - set(CARGO_HOME "${USER_HOME}/.cargo") |
| 40 | +if(NOT DEFINED Rust_CARGO_HOME) |
| 41 | + if("$ENV{Rust_CARGO_HOME}" STREQUAL "") |
| 42 | + set(Rust_CARGO_HOME "${USER_HOME}/.cargo") |
42 | 43 | else() |
43 | | - set(CARGO_HOME "$ENV{CARGO_HOME}") |
| 44 | + set(Rust_CARGO_HOME "$ENV{Rust_CARGO_HOME}") |
44 | 45 | endif() |
45 | 46 | endif() |
46 | 47 |
|
47 | | -set(CARGO_HOME "${CARGO_HOME}" CACHE PATH "Rust Cargo Home") |
| 48 | +set(Rust_CARGO_HOME "${Rust_CARGO_HOME}" CACHE PATH "Rust Cargo Home") |
48 | 49 |
|
49 | | -set(RUST_PATHS |
| 50 | +set(Rust_PATHS |
50 | 51 | /usr |
51 | 52 | /usr/local |
52 | | - ${CARGO_HOME} |
| 53 | + ${Rust_CARGO_HOME} |
53 | 54 | ) |
54 | 55 |
|
55 | | -find_program(CARGO_EXECUTABLE cargo |
56 | | - HINTS ${RUST_PATHS} |
| 56 | +find_program(Rust_RUSTUP_EXECUTABLE rustup |
| 57 | + HINTS ${Rust_PATHS} |
57 | 58 | PATH_SUFFIXES "bin" |
58 | 59 | ) |
59 | 60 |
|
60 | | -find_program(RUSTC_EXECUTABLE rustc |
61 | | - HINTS ${RUST_PATHS} |
| 61 | +if(Rust_RUSTUP_EXECUTABLE AND Rust_FIND_COMPONENTS) |
| 62 | + # Install the required toolchain (only one allowed by now) |
| 63 | + list(GET Rust_FIND_COMPONENTS 0 Rust_TOOLCHAIN) |
| 64 | + |
| 65 | + if(Rust_TOOLCHAIN) |
| 66 | + execute_process( |
| 67 | + COMMAND ${Rust_RUSTUP_EXECUTABLE} toolchain install ${Rust_TOOLCHAIN} --force |
| 68 | + ) |
| 69 | + execute_process( |
| 70 | + COMMAND ${Rust_RUSTUP_EXECUTABLE} default ${Rust_TOOLCHAIN} |
| 71 | + ) |
| 72 | + |
| 73 | + # Obtain toolchain full name and triplet (not needed for now) |
| 74 | + # execute_process( |
| 75 | + # COMMAND ${Rust_RUSTUP_EXECUTABLE} default |
| 76 | + # OUTPUT_VARIABLE Rust_TOOLCHAIN_FULL_NAME |
| 77 | + # OUTPUT_STRIP_TRAILING_WHITESPACE |
| 78 | + # ) |
| 79 | + |
| 80 | + # string(REPLACE " " ";" Rust_TOOLCHAIN_FULL_NAME ${Rust_TOOLCHAIN_FULL_NAME}) |
| 81 | + # list(GET Rust_TOOLCHAIN_FULL_NAME 0 Rust_TOOLCHAIN_FULL_NAME) |
| 82 | + # string(REPLACE "${Rust_TOOLCHAIN}-" "" Rust_TOOLCHAIN_TRIPLET ${Rust_TOOLCHAIN_FULL_NAME}) |
| 83 | + |
| 84 | + set(Rust_TOOLCHAIN_COMPONENT_LIST |
| 85 | + cargo |
| 86 | + clippy |
| 87 | + llvm-tools-preview |
| 88 | + rls |
| 89 | + rust-analysis |
| 90 | + rust-analyzer-preview |
| 91 | + rust-docs |
| 92 | + rust-std |
| 93 | + rustc |
| 94 | + rustc-dev |
| 95 | + rustfmt |
| 96 | + rust-src |
| 97 | + ) |
| 98 | + |
| 99 | + foreach(Rust_TOOLCHAIN_COMPONENT ${Rust_TOOLCHAIN_COMPONENT_LIST}) |
| 100 | + execute_process( |
| 101 | + COMMAND ${Rust_RUSTUP_EXECUTABLE} toolchain install ${Rust_TOOLCHAIN} --component ${Rust_TOOLCHAIN_COMPONENT} |
| 102 | + ) |
| 103 | + endforeach() |
| 104 | + endif() |
| 105 | + |
| 106 | +endif() |
| 107 | + |
| 108 | +find_program(Rust_CARGO_EXECUTABLE cargo |
| 109 | + HINTS ${Rust_PATHS} |
62 | 110 | PATH_SUFFIXES "bin" |
63 | 111 | ) |
64 | 112 |
|
65 | | -find_program(RUSTDOC_EXECUTABLE rustdoc |
66 | | - HINTS ${RUST_PATHS} |
| 113 | +find_program(Rust_RUSTC_EXECUTABLE rustc |
| 114 | + HINTS ${Rust_PATHS} |
67 | 115 | PATH_SUFFIXES "bin" |
68 | 116 | ) |
69 | 117 |
|
70 | | -find_program(RUSTUP_EXECUTABLE rustup |
71 | | - HINTS ${RUST_PATHS} |
| 118 | +find_program(Rust_RUSTDOC_EXECUTABLE rustdoc |
| 119 | + HINTS ${Rust_PATHS} |
72 | 120 | PATH_SUFFIXES "bin" |
73 | 121 | ) |
74 | 122 |
|
75 | | -find_program(RUST_GDB_EXECUTABLE rust-gdb |
76 | | - HINTS ${RUST_PATHS} |
| 123 | +find_program(Rust_GDB_EXECUTABLE rust-gdb |
| 124 | + HINTS ${Rust_PATHS} |
77 | 125 | PATH_SUFFIXES "bin" |
78 | 126 | ) |
79 | 127 |
|
80 | | -find_program(RUST_LLDB_EXECUTABLE rust-lldb |
81 | | - HINTS ${RUST_PATHS} |
| 128 | +find_program(Rust_LLDB_EXECUTABLE rust-lldb |
| 129 | + HINTS ${Rust_PATHS} |
82 | 130 | PATH_SUFFIXES "bin" |
83 | 131 | ) |
84 | 132 |
|
85 | | -if(RUSTC_EXECUTABLE) |
| 133 | +if(Rust_RUSTC_EXECUTABLE) |
86 | 134 | execute_process( |
87 | | - COMMAND ${RUSTC_EXECUTABLE} --version |
88 | | - OUTPUT_VARIABLE RUSTC_VERSION |
| 135 | + COMMAND ${Rust_RUSTC_EXECUTABLE} --version |
| 136 | + OUTPUT_VARIABLE Rust_RUSTC_VERSION |
89 | 137 | OUTPUT_STRIP_TRAILING_WHITESPACE |
90 | 138 | ) |
91 | | - string(REGEX REPLACE "rustc ([^ ]+) .*" "\\1" RUSTC_VERSION "${RUSTC_VERSION}") |
| 139 | + string(REGEX REPLACE "rustc ([^ ]+) .*" "\\1" Rust_RUSTC_VERSION "${Rust_RUSTC_VERSION}") |
92 | 140 |
|
93 | 141 | execute_process( |
94 | | - COMMAND ${RUSTC_EXECUTABLE} --print sysroot |
95 | | - OUTPUT_VARIABLE RUSTC_SYSROOT |
| 142 | + COMMAND ${Rust_RUSTC_EXECUTABLE} --print sysroot |
| 143 | + OUTPUT_VARIABLE Rust_RUSTC_SYSROOT |
96 | 144 | OUTPUT_STRIP_TRAILING_WHITESPACE |
97 | 145 | ) |
98 | 146 |
|
99 | 147 | file( |
100 | | - GLOB RUSTC_LIBRARIES |
101 | | - ${RUSTC_SYSROOT}/lib/*${CMAKE_SHARED_LIBRARY_SUFFIX} |
| 148 | + GLOB Rust_RUSTC_LIBRARIES |
| 149 | + ${Rust_RUSTC_SYSROOT}/lib/*${CMAKE_SHARED_LIBRARY_SUFFIX} |
102 | 150 | ) |
103 | 151 | endif() |
104 | 152 |
|
105 | 153 | include(FindPackageHandleStandardArgs) |
106 | 154 |
|
107 | 155 | find_package_handle_standard_args(Rust |
108 | | - FOUND_VAR RUST_FOUND |
109 | | - REQUIRED_VARS CARGO_EXECUTABLE RUSTC_EXECUTABLE RUSTC_LIBRARIES |
110 | | - VERSION_VAR RUSTC_VERSION |
| 156 | + FOUND_VAR Rust_FOUND |
| 157 | + REQUIRED_VARS Rust_CARGO_EXECUTABLE Rust_RUSTC_EXECUTABLE Rust_RUSTC_LIBRARIES |
| 158 | + VERSION_VAR Rust_RUSTC_VERSION |
111 | 159 | ) |
112 | 160 |
|
113 | 161 | mark_as_advanced( |
114 | | - RUST_FOUND |
115 | | - CARGO_EXECUTABLE |
116 | | - RUSTC_EXECUTABLE |
117 | | - RUSTC_SYSROOT |
118 | | - RUSTC_LIBRARIES |
119 | | - RUSTUP_EXECUTABLE |
120 | | - RUSTDOC_EXECUTABLE |
121 | | - RUST_GDB_EXECUTABLE |
122 | | - RUST_LLDB_EXECUTABLE |
| 162 | + Rust_FOUND |
| 163 | + Rust_CARGO_EXECUTABLE |
| 164 | + Rust_RUSTC_EXECUTABLE |
| 165 | + Rust_RUSTC_SYSROOT |
| 166 | + Rust_RUSTC_LIBRARIES |
| 167 | + Rust_RUSTUP_EXECUTABLE |
| 168 | + Rust_RUSTDOC_EXECUTABLE |
| 169 | + Rust_GDB_EXECUTABLE |
| 170 | + Rust_LLDB_EXECUTABLE |
123 | 171 | ) |
0 commit comments