Skip to content

Commit e837a93

Browse files
authored
[build] Fixed proper compiler selection for --with-compiler-type configure option (#3021).
1 parent 53d611a commit e837a93

File tree

1 file changed

+74
-10
lines changed

1 file changed

+74
-10
lines changed

configure-data.tcl

Lines changed: 74 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,55 @@ proc preprocess {} {
191191
}
192192
}
193193

194-
proc GetCompilerCommand {} {
194+
# Added also the Intel compiler names, just in case.
195+
set compiler_map {
196+
cc c++
197+
gcc g++
198+
icc icpc
199+
icx icpx
200+
}
201+
202+
proc SplitCompilerVersionSuffix {cmd} {
203+
# If there's no version suffix, return just $cmd.
204+
# Otherwise return a list with cmd cut and version suffix
205+
206+
set parts [split $cmd -]
207+
if {[llength $parts] == 1} {
208+
return $cmd
209+
}
210+
211+
set last [lindex $parts end]
212+
if {![regexp {[0-9]+.*} $last]} {
213+
return $cmd
214+
}
215+
216+
# Got the version
217+
if {[llength $parts] == 2} {
218+
set first [lindex $parts 0]
219+
} else {
220+
set first [join [lrange $parts 0 end-1] -]
221+
}
222+
223+
return [list $first -$last]
224+
}
225+
226+
# This uses 'compiler' in the form of the C compiler
227+
# command line. For C++ it returns the C++ command line,
228+
# which is normally the C compiler command with ++.
229+
proc GetCompilerCmdName {compiler lang} {
230+
lassign [SplitCompilerVersionSuffix $compiler] compiler suffix
231+
if {$lang == "c++"} {
232+
if { [dict exists $::compiler_map $compiler] } {
233+
return [dict get $::compiler_map $compiler]$suffix
234+
}
235+
236+
return ${compiler}++${suffix}
237+
}
238+
239+
return $compiler${suffix}
240+
}
241+
242+
proc GetCompilerCommand { {lang {}} } {
195243
# Expect that the compiler was set through:
196244
# --with-compiler-prefix
197245
# --cmake-c[++]-compiler
@@ -204,21 +252,25 @@ proc GetCompilerCommand {} {
204252

205253
if { [info exists ::optval(--with-compiler-prefix)] } {
206254
set prefix $::optval(--with-compiler-prefix)
207-
return ${prefix}$compiler
255+
return ${prefix}[GetCompilerCmdName $compiler $lang]
208256
} else {
209-
return $compiler
257+
return [GetCompilerCmdName $compiler $lang]
210258
}
211259

212-
if { [info exists ::optval(--cmake-c-compiler)] } {
213-
return $::optval(--cmake-c-compiler)
260+
if { $lang != "c++" } {
261+
if { [info exists ::optval(--cmake-c-compiler)] } {
262+
return $::optval(--cmake-c-compiler)
263+
}
214264
}
215265

216-
if { [info exists ::optval(--cmake-c++-compiler)] } {
217-
return $::optval(--cmake-c++-compiler)
218-
}
266+
if { $lang != "c" } {
267+
if { [info exists ::optval(--cmake-c++-compiler)] } {
268+
return $::optval(--cmake-c++-compiler)
269+
}
219270

220-
if { [info exists ::optval(--cmake-cxx-compiler)] } {
221-
return $::optval(--cmake-cxx-compiler)
271+
if { [info exists ::optval(--cmake-cxx-compiler)] } {
272+
return $::optval(--cmake-cxx-compiler)
273+
}
222274
}
223275

224276
puts "NOTE: Cannot obtain compiler, assuming toolchain file will do what's necessary"
@@ -284,6 +336,18 @@ proc postprocess {} {
284336
} else {
285337
puts "CONFIGURE: default compiler used"
286338
}
339+
340+
# Complete the variables before calling cmake, otherwise it might not work
341+
342+
if { [info exists ::optval(--with-compiler-type)] } {
343+
if { ![info exists ::optval(--cmake-c-compiler)] } {
344+
lappend ::cmakeopt "-DCMAKE_C_COMPILER=[GetCompilerCommand c]"
345+
}
346+
347+
if { ![info exists ::optval(--cmake-c++-compiler)] } {
348+
lappend ::cmakeopt "-DCMAKE_CXX_COMPILER=[GetCompilerCommand c++]"
349+
}
350+
}
287351
}
288352

289353
if { $::srt_name != "" } {

0 commit comments

Comments
 (0)