homebrew-core/Formula/vtk.rb

153 lines
5.4 KiB
Ruby

class Vtk < Formula
desc "Toolkit for 3D computer graphics, image processing, and visualization"
homepage "https://www.vtk.org/"
url "https://www.vtk.org/files/release/9.0/VTK-9.0.3.tar.gz"
sha256 "bc3eb9625b2b8dbfecb6052a2ab091fc91405de4333b0ec68f3323815154ed8a"
license "BSD-3-Clause"
head "https://github.com/Kitware/VTK.git", branch: "master"
bottle do
sha256 arm64_big_sur: "fde272807de4be00a73385e08f95daa26568d82b2bd8e49c0632d908fbf14788"
sha256 big_sur: "030677a7748f0fc0d4116424db9225ecf3d805476c08da3d07e65e381ff21589"
sha256 catalina: "beb7e778df907e3763363ad51579b4e004b1b2b745a395621cbc1f2800340d81"
sha256 mojave: "d466d33fd7932aedd24fce9c5b791e7e97cf375db629180718171a2df4b97153"
sha256 cellar: :any_skip_relocation, x86_64_linux: "a9b8909326147db522b2da5ba80df9fac4d5836e776a9b5efa9ee7e0ade081ab"
end
depends_on "cmake" => [:build, :test]
depends_on "boost"
depends_on "double-conversion"
depends_on "eigen"
depends_on "fontconfig"
depends_on "gl2ps"
depends_on "glew"
depends_on "hdf5"
depends_on "jpeg"
depends_on "jsoncpp"
depends_on "libogg"
depends_on "libpng"
depends_on "libtiff"
depends_on "lz4"
depends_on "netcdf"
depends_on "pugixml"
depends_on "pyqt@5"
depends_on "python@3.9"
depends_on "qt@5"
depends_on "sqlite"
depends_on "theora"
depends_on "utf8cpp"
depends_on "xz"
uses_from_macos "expat"
uses_from_macos "libxml2"
uses_from_macos "tcl-tk"
uses_from_macos "zlib"
on_linux do
depends_on "gcc"
depends_on "szip"
depends_on "mesa-glu"
# Apply 2 upstream commits to fix build on GCC 11.
# Remove with next release.
patch do
url "https://github.com/Kitware/VTK/commit/c7d6a8d81367a4ed92163c059aa3181386eabc24.patch?full_index=1"
sha256 "fa292347cc0b157844cba128dae1a0fd16b6bc12e707f1b5c94b25fd41171d49"
end
patch do
url "https://github.com/Kitware/VTK/commit/e066c3f4fbbfe7470c6207db0fc3f3952db633cb.patch?full_index=1"
sha256 "d20fc3287c9c36f4f9b0a43148180ccbf7960f7b141e279eb537b94d97286250"
end
end
fails_with gcc: "5"
def install
# Do not record compiler path because it references the shim directory
inreplace "Common/Core/vtkConfigure.h.in", "@CMAKE_CXX_COMPILER@", ENV.cxx
args = std_cmake_args + %W[
-DBUILD_SHARED_LIBS:BOOL=ON
-DBUILD_TESTING:BOOL=OFF
-DCMAKE_INSTALL_NAME_DIR:STRING=#{opt_lib}
-DCMAKE_INSTALL_RPATH:STRING=#{rpath}
-DVTK_WRAP_PYTHON:BOOL=ON
-DVTK_PYTHON_VERSION:STRING=3
-DVTK_LEGACY_REMOVE:BOOL=ON
-DVTK_MODULE_ENABLE_VTK_InfovisBoost:STRING=YES
-DVTK_MODULE_ENABLE_VTK_InfovisBoostGraphAlgorithms:STRING=YES
-DVTK_MODULE_ENABLE_VTK_RenderingFreeTypeFontConfig:STRING=YES
-DVTK_MODULE_USE_EXTERNAL_VTK_doubleconversion:BOOL=ON
-DVTK_MODULE_USE_EXTERNAL_VTK_eigen:BOOL=ON
-DVTK_MODULE_USE_EXTERNAL_VTK_expat:BOOL=ON
-DVTK_MODULE_USE_EXTERNAL_VTK_gl2ps:BOOL=ON
-DVTK_MODULE_USE_EXTERNAL_VTK_glew:BOOL=ON
-DVTK_MODULE_USE_EXTERNAL_VTK_hdf5:BOOL=ON
-DVTK_MODULE_USE_EXTERNAL_VTK_jpeg:BOOL=ON
-DVTK_MODULE_USE_EXTERNAL_VTK_jsoncpp:BOOL=ON
-DVTK_MODULE_USE_EXTERNAL_VTK_libxml2:BOOL=ON
-DVTK_MODULE_USE_EXTERNAL_VTK_lz4:BOOL=ON
-DVTK_MODULE_USE_EXTERNAL_VTK_lzma:BOOL=ON
-DVTK_MODULE_USE_EXTERNAL_VTK_netcdf:BOOL=ON
-DVTK_MODULE_USE_EXTERNAL_VTK_ogg:BOOL=ON
-DVTK_MODULE_USE_EXTERNAL_VTK_png:BOOL=ON
-DVTK_MODULE_USE_EXTERNAL_VTK_pugixml:BOOL=ON
-DVTK_MODULE_USE_EXTERNAL_VTK_sqlite:BOOL=ON
-DVTK_MODULE_USE_EXTERNAL_VTK_theora:BOOL=ON
-DVTK_MODULE_USE_EXTERNAL_VTK_tiff:BOOL=ON
-DVTK_MODULE_USE_EXTERNAL_VTK_utf8:BOOL=ON
-DVTK_MODULE_USE_EXTERNAL_VTK_zlib:BOOL=ON
-DPython3_EXECUTABLE:FILEPATH=#{Formula["python@3.9"].opt_bin}/python3
-DVTK_GROUP_ENABLE_Qt:STRING=YES
]
# https://github.com/Homebrew/linuxbrew-core/pull/21654#issuecomment-738549701
args << "-DOpenGL_GL_PREFERENCE=LEGACY"
args << "-DVTK_USE_COCOA:BOOL=ON" if OS.mac?
mkdir "build" do
system "cmake", "..", *args
system "make"
system "make", "install"
end
end
test do
(testpath/"CMakeLists.txt").write <<~EOS
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
project(Distance2BetweenPoints LANGUAGES CXX)
find_package(VTK REQUIRED COMPONENTS vtkCommonCore CONFIG)
add_executable(Distance2BetweenPoints Distance2BetweenPoints.cxx)
target_link_libraries(Distance2BetweenPoints PRIVATE ${VTK_LIBRARIES})
EOS
(testpath/"Distance2BetweenPoints.cxx").write <<~EOS
#include <cassert>
#include <vtkMath.h>
int main() {
double p0[3] = {0.0, 0.0, 0.0};
double p1[3] = {1.0, 1.0, 1.0};
assert(vtkMath::Distance2BetweenPoints(p0, p1) == 3.0);
return 0;
}
EOS
vtk_dir = Dir[opt_lib/"cmake/vtk-*"].first
system "cmake", "-DCMAKE_BUILD_TYPE=Debug", "-DCMAKE_VERBOSE_MAKEFILE=ON",
"-DVTK_DIR=#{vtk_dir}", "."
system "make"
system "./Distance2BetweenPoints"
(testpath/"Distance2BetweenPoints.py").write <<~EOS
import vtk
p0 = (0, 0, 0)
p1 = (1, 1, 1)
assert vtk.vtkMath.Distance2BetweenPoints(p0, p1) == 3
EOS
system bin/"vtkpython", "Distance2BetweenPoints.py"
end
end