@@ -3,7 +3,8 @@ use strict;
33use warnings;
44use Config;
55
6- our $CCNAME = $ENV {CC } || $Config::Config {ccname };
6+ # ExtUtils::CBuilder uses cc not ccname
7+ our $CCNAME = $ENV {CC } || $Config::Config {cc };
78our $OS = $^O;
89
910my $checked = 0;
@@ -84,8 +85,20 @@ sub version_from_preprocessor {
8485
8586sub _openmp_defined {
8687 my $define = pop ;
88+
8789 # 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+ };
89102 return $versions -> {$define || ' ' } || ' unknown' ;
90103}
91104
@@ -94,16 +107,30 @@ sub _reset { $checked = 0; }
94107
95108sub _update_supported {
96109 return if $checked ;
110+ require File::Basename;
111+
97112 # 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' ) {
102116 require File::Which;
103117 require Path::Tiny;
104118
105119 # 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+
107134 if (my $mp = File::Which::which(' port' )) {
108135
109136 # macports /opt/local/bin/port
@@ -112,14 +139,22 @@ sub _update_supported {
112139 unshift @{$supported -> {darwin }{libs }}, " -L$mp_prefix /lib/libomp" ;
113140 }
114141 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 " ;
118145 }
119146 }
120147 $checked ++;
121148}
122149
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+
1231581;
124159
125160=encoding utf8
0 commit comments