Skip to content

Commit 2d69dda

Browse files
committed
openblas: use cmake
1 parent 9697234 commit 2d69dda

File tree

1 file changed

+55
-21
lines changed

1 file changed

+55
-21
lines changed

Formula/o/openblas.rb

Lines changed: 55 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
class Openblas < Formula
22
desc "Optimized BLAS library"
33
homepage "https://www.openblas.net/"
4-
url "https://github.com/OpenMathLib/OpenBLAS/archive/refs/tags/v0.3.29.tar.gz"
5-
sha256 "38240eee1b29e2bde47ebb5d61160207dc68668a54cac62c076bb5032013b1eb"
64
# The main license is BSD-3-Clause. Additionally,
75
# 1. OpenBLAS is based on GotoBLAS2 so some code is under original BSD-2-Clause-Views
86
# 2. lapack-netlib/ is a bundled LAPACK so it is BSD-3-Clause-Open-MPI
@@ -11,6 +9,29 @@ class Openblas < Formula
119
license all_of: ["BSD-3-Clause", "BSD-2-Clause-Views", "BSD-3-Clause-Open-MPI", "BSD-2-Clause"]
1210
head "https://github.com/OpenMathLib/OpenBLAS.git", branch: "develop"
1311

12+
stable do
13+
url "https://github.com/OpenMathLib/OpenBLAS/archive/refs/tags/v0.3.29.tar.gz"
14+
sha256 "38240eee1b29e2bde47ebb5d61160207dc68668a54cac62c076bb5032013b1eb"
15+
16+
# Remove patch in the next release
17+
patch do
18+
url "https://github.com/OpenMathLib/OpenBLAS/commit/70865a894e5963724ff9ccb05323ac2234a918b9.patch?full_index=1"
19+
sha256 "80beeb28e5baf21af05ac114a1cca97855faf298e40b3b290005977fad260f52"
20+
end
21+
22+
# Remove patch in the next release
23+
patch do
24+
url "https://github.com/OpenMathLib/OpenBLAS/commit/d659f3c3f6058ece8a704423b72ece3821cfba4d.patch?full_index=1"
25+
sha256 "88ad7b0802e914535dcb8ceedfaec6cc01d379d2029111c29a7b55176a511f88"
26+
end
27+
28+
# Remove patch in the next release
29+
patch do
30+
url "https://github.com/OpenMathLib/OpenBLAS/commit/9aa7a0b2a7b2770adec6ff26b34660d3bcd8c49c.patch?full_index=1"
31+
sha256 "0538ce7223ec5813c80e148388e892184b5e5e396c0868f903c8c0c5e19c5c2e"
32+
end
33+
end
34+
1435
livecheck do
1536
url :stable
1637
strategy :github_latest
@@ -28,21 +49,18 @@ class Openblas < Formula
2849

2950
keg_only :shadowed_by_macos, "macOS provides BLAS in Accelerate.framework"
3051

52+
depends_on "cmake" => :build
53+
depends_on "pkgconf" => :test
3154
depends_on "gcc" # for gfortran
32-
fails_with :clang
55+
56+
on_macos do
57+
depends_on "libomp"
58+
end
3359

3460
def install
3561
ENV.runtime_cpu_detection
36-
ENV.deparallelize # build is parallel by default, but setting -j confuses it
37-
38-
# The build log has many warnings of macOS build version mismatches.
39-
ENV["MACOSX_DEPLOYMENT_TARGET"] = MacOS.version.to_s if OS.mac?
40-
ENV["DYNAMIC_ARCH"] = "1"
41-
ENV["USE_OPENMP"] = "1"
42-
# Force a large NUM_THREADS to support larger Macs than the VMs that build the bottles
43-
ENV["NUM_THREADS"] = "56"
44-
# See available targets in TargetList.txt
45-
ENV["TARGET"] = case Hardware.oldest_cpu
62+
63+
target = case Hardware.oldest_cpu
4664
when :arm_vortex_tempest
4765
"VORTEX"
4866
when :westmere
@@ -51,16 +69,30 @@ def install
5169
Hardware.oldest_cpu.upcase.to_s
5270
end
5371

54-
# Apple Silicon does not support SVE
55-
# https://github.com/xianyi/OpenBLAS/issues/4212
56-
ENV["NO_SVE"] = "1" if Hardware::CPU.arm?
72+
args = %W[
73+
-DUSE_OPENMP=ON
74+
-DBUILD_SHARED_LIBS=ON
75+
-DBUILD_STATIC_LIBS=ON
76+
-DNUM_THREADS=64
77+
-DTARGET=#{target}
78+
]
79+
80+
args << "-DDYNAMIC_ARCH=ON" if !OS.mac? || Hardware::CPU.intel?
5781

58-
# Must call in two steps
59-
system "make", "CC=#{ENV.cc}", "FC=gfortran", "libs", "netlib", "shared"
60-
system "make", "PREFIX=#{prefix}", "install"
82+
if OS.mac?
83+
libomp = Formula["libomp"]
84+
args << "-DOpenMP_Fortran_LIB_NAMES=omp"
85+
args << "-DOpenMP_omp_LIBRARY=#{libomp.opt_lib}/libomp.dylib"
86+
end
87+
88+
system "cmake", "-S", ".", "-B", "build", *args, *std_cmake_args
89+
system "cmake", "--build", "build"
90+
system "cmake", "--install", "build"
6191

6292
lib.install_symlink shared_library("libopenblas") => shared_library("libblas")
6393
lib.install_symlink shared_library("libopenblas") => shared_library("liblapack")
94+
95+
inreplace lib/"pkgconfig/openblas.pc", prefix, opt_prefix
6496
end
6597

6698
test do
@@ -85,8 +117,10 @@ def install
85117
return 0;
86118
}
87119
C
88-
system ENV.cc, "test.c", "-I#{include}", "-L#{lib}", "-lopenblas",
89-
"-o", "test"
120+
121+
ENV.prepend_path "PKG_CONFIG_PATH", lib/"pkgconfig"
122+
flags = shell_output("pkgconf --cflags --libs openblas").chomp.split
123+
system ENV.cc, "test.c", "-o", "test", *flags
90124
system "./test"
91125
end
92126
end

0 commit comments

Comments
 (0)