@@ -3,7 +3,8 @@ use strict;
3
3
use warnings;
4
4
use Config;
5
5
6
- our $CCNAME = $ENV {CC } || $Config::Config {ccname };
6
+ # ExtUtils::CBuilder uses cc not ccname
7
+ our $CCNAME = $ENV {CC } || $Config::Config {cc };
7
8
our $OS = $^O;
8
9
9
10
my $checked = 0;
@@ -84,8 +85,20 @@ sub version_from_preprocessor {
84
85
85
86
sub _openmp_defined {
86
87
my $define = pop ;
88
+
87
89
# From https://github.com/jeffhammond/HPCInfo/blob/master/docs/Preprocessor-Macros.md
88
- my $versions = {200505 => ' 2.5' , 200805 => ' 3.0' , 201107 => ' 3.1' , 201307 => ' 4.0' , 201511 => ' 4.5' , 201811 => ' 5.0' };
90
+ # also https://www.openmp.org/specifications/
91
+ my $versions = {
92
+ 200505 => ' 2.5' ,
93
+ 200805 => ' 3.0' ,
94
+ 201107 => ' 3.1' ,
95
+ 201307 => ' 4.0' ,
96
+ 201511 => ' 4.5' ,
97
+ 201811 => ' 5.0' ,
98
+ 202011 => ' 5.1' ,
99
+ 202111 => ' 5.2' ,
100
+ 202411 => ' 6.0' ,
101
+ };
89
102
return $versions -> {$define || ' ' } || ' unknown' ;
90
103
}
91
104
@@ -94,16 +107,30 @@ sub _reset { $checked = 0; }
94
107
95
108
sub _update_supported {
96
109
return if $checked ;
110
+ require File::Basename;
111
+
97
112
# handles situation where $CCNAME is gcc as part of a path
98
- if ($CCNAME =~ m { /gcc$} ) {
99
- $CCNAME = ' gcc' ;
100
- }
101
- elsif ($OS eq ' darwin' ) {
113
+ $CCNAME = File::Basename::basename($CCNAME );
114
+
115
+ if ($OS eq ' darwin' ) {
102
116
require File::Which;
103
117
require Path::Tiny;
104
118
105
119
# The issue here is that ccname=gcc and cc=cc as an interface to clang
106
- $supported -> {darwin } = {cflags => [' -Xclang' , ' -fopenmp' ], libs => [' -lomp' ],};
120
+ # First check if clang/gcc, then discern omp location
121
+ my $flavour = _compiler_flavour();
122
+ if ($flavour eq ' clang' || $flavour eq ' default' ) {
123
+ $supported -> {darwin } = {cflags => [' -Xclang' , ' -fopenmp' ], libs => [' -lomp' ],};
124
+ $supported -> {$CCNAME } ||= {auto_include => join qq{ \n } , (' #include <omp.h>' )};
125
+ }
126
+ elsif ($flavour eq ' gcc' ) {
127
+ $supported -> {darwin } = {cflags => [' -fopenmp' ], libs => [' -lomp' ],};
128
+ $supported -> {$CCNAME } ||= {auto_include => join qq{ \n } , (' #include <omp.h>' )};
129
+ }
130
+ else {
131
+ return ++$checked ;
132
+ }
133
+
107
134
if (my $mp = File::Which::which(' port' )) {
108
135
109
136
# macports /opt/local/bin/port
@@ -112,14 +139,22 @@ sub _update_supported {
112
139
unshift @{$supported -> {darwin }{libs }}, " -L$mp_prefix /lib/libomp" ;
113
140
}
114
141
else {
115
- # homebrew has the headers and library in /usr/local
116
- push @{$supported -> {darwin }{cflags }}, " -I/usr/local/include" ;
117
- unshift @{$supported -> {darwin }{libs }}, " -L/usr/local/lib" ;
142
+ # homebrew has the headers and library in /usr/local, but is not always symlinked
143
+ push @{$supported -> {darwin }{cflags }}, " -I/usr/local/include" , " -I/opt/homebrew/opt/libomp/include " ;
144
+ unshift @{$supported -> {darwin }{libs }}, " -L/usr/local/lib" , " -L/opt/homebrew/opt/libomp/lib " ;
118
145
}
119
146
}
120
147
$checked ++;
121
148
}
122
149
150
+ # not looking for openmp
151
+ sub _compiler_flavour {
152
+ my $defines = qx{ $CCNAME -dM -E - < /dev/null} ;
153
+ return ' clang' if ($defines =~ m { ^#define __clang__} m );
154
+ return ' gcc' if ($defines =~ m { ^#define __GCC_} m && $defines =~ m { ^#define __APPLE__} m );
155
+ return ' default' ;
156
+ }
157
+
123
158
1;
124
159
125
160
=encoding utf8
0 commit comments