@@ -92,10 +92,31 @@ pub fn check(build: &mut Build) {
92
92
. unwrap_or ( true )
93
93
} )
94
94
. any ( |build_llvm_ourselves| build_llvm_ourselves) ;
95
- let need_cmake = building_llvm || build. config . any_sanitizers_enabled ( ) ;
96
- if need_cmake {
97
- cmd_finder. must_have ( "cmake" ) ;
98
- }
95
+ let need_default_cmake = if building_llvm || build. config . any_sanitizers_enabled ( ) {
96
+ let cmake_env_var = env:: var_os ( "CMAKE" ) ;
97
+ if let Some ( explicit_name) = build. config . cmake . take ( ) {
98
+ if let Some ( cmake_from_env) = cmake_env_var {
99
+ if explicit_name != cmake_from_env {
100
+ eprintln ! (
101
+ "env var CMAKE = {cmake_from_env:?} != {explicit_name:?} from config.toml"
102
+ )
103
+ }
104
+ }
105
+ build. config . cmake = cmd_finder. must_have ( explicit_name) . into ( ) ;
106
+ None
107
+ } else {
108
+ // _very_ simplified version of getenv_target_os("CMAKE") from
109
+ // https://docs.rs/cmake/0.1.48/src/cmake/lib.rs.html#515
110
+ if let Some ( cmake_from_env) = cmake_env_var {
111
+ cmd_finder. must_have ( cmake_from_env)
112
+ } else {
113
+ cmd_finder. must_have ( "cmake" )
114
+ }
115
+ . into ( )
116
+ }
117
+ } else {
118
+ None
119
+ } ;
99
120
100
121
build. config . python = build
101
122
. config
@@ -201,14 +222,17 @@ pub fn check(build: &mut Build) {
201
222
}
202
223
}
203
224
204
- if need_cmake && target. contains ( "msvc" ) {
205
- // There are three builds of cmake on windows: MSVC, MinGW, and
206
- // Cygwin. The Cygwin build does not have generators for Visual
207
- // Studio, so detect that here and error.
208
- let out = output ( Command :: new ( "cmake" ) . arg ( "--help" ) ) ;
209
- if !out. contains ( "Visual Studio" ) {
210
- panic ! (
211
- "
225
+ if target. contains ( "msvc" ) {
226
+ if let Some ( ref cmake_path) =
227
+ need_default_cmake. as_ref ( ) . or ( build. config . cmake . as_ref ( ) )
228
+ {
229
+ // There are three builds of cmake on windows: MSVC, MinGW, and
230
+ // Cygwin. The Cygwin build does not have generators for Visual
231
+ // Studio, so detect that here and error.
232
+ let out = output ( Command :: new ( cmake_path) . arg ( "--help" ) ) ;
233
+ if !out. contains ( "Visual Studio" ) {
234
+ panic ! (
235
+ "
212
236
cmake does not support Visual Studio generators.
213
237
214
238
This is likely due to it being an msys/cygwin build of cmake,
@@ -220,7 +244,8 @@ package instead of cmake:
220
244
221
245
$ pacman -R cmake && pacman -S mingw-w64-x86_64-cmake
222
246
"
223
- ) ;
247
+ ) ;
248
+ }
224
249
}
225
250
}
226
251
}
0 commit comments