homebrew-core/Formula/cgal.rb

84 lines
3.3 KiB
Ruby

class Cgal < Formula
desc "Computational Geometry Algorithms Library"
homepage "https://www.cgal.org/"
url "https://github.com/CGAL/cgal/releases/download/v5.2/CGAL-5.2.tar.xz"
sha256 "744c86edb6e020ab0238f95ffeb9cf8363d98cde17ebb897d3ea93dac4145923"
license "GPL-3.0-or-later"
bottle do
sha256 cellar: :any_skip_relocation, arm64_big_sur: "f610594b97b512f9dddbf434c3fa68e6de5d2e45a9a9fe27037fb9f189e76fb3"
sha256 cellar: :any_skip_relocation, big_sur: "a5f269116c77b8d520e186595582f5d5e71b4d356d396920287a59b3ae6fea7c"
sha256 cellar: :any_skip_relocation, catalina: "17761c706fb5b039394dd23db164f5749ca348508820de1478f79f3422fd2ba2"
sha256 cellar: :any_skip_relocation, mojave: "7163a4ad9b21491d1d9a10a0c6a126696b8647c4094c3c650dbd44b84274019d"
end
depends_on "cmake" => [:build, :test]
depends_on "qt" => [:build, :test]
depends_on "boost"
depends_on "eigen"
depends_on "gmp"
depends_on "mpfr"
on_linux do
depends_on "openssl@1.1"
end
def install
args = std_cmake_args + %w[
-DCMAKE_CXX_FLAGS='-std=c++14'
-DWITH_CGAL_Qt5=ON
]
system "cmake", ".", *args
system "make", "install"
end
test do
# https://doc.cgal.org/latest/Triangulation_2/Triangulation_2_2draw_triangulation_2_8cpp-example.html and https://doc.cgal.org/latest/Algebraic_foundations/Algebraic_foundations_2interoperable_8cpp-example.html
(testpath/"surprise.cpp").write <<~EOS
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Triangulation_2.h>
#include <CGAL/draw_triangulation_2.h>
#include <CGAL/basic.h>
#include <CGAL/Coercion_traits.h>
#include <CGAL/IO/io.h>
#include <fstream>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Triangulation_2<K> Triangulation;
typedef Triangulation::Point Point;
template <typename A, typename B>
typename CGAL::Coercion_traits<A,B>::Type
binary_func(const A& a , const B& b){
typedef CGAL::Coercion_traits<A,B> CT;
CGAL_static_assertion((CT::Are_explicit_interoperable::value));
typename CT::Cast cast;
return cast(a)*cast(b);
}
int main(int argc, char**) {
std::cout<< binary_func(double(3), int(5)) << std::endl;
std::cout<< binary_func(int(3), double(5)) << std::endl;
std::ifstream in("data/triangulation_prog1.cin");
std::istream_iterator<Point> begin(in);
std::istream_iterator<Point> end;
Triangulation t;
t.insert(begin, end);
if(argc == 3) // do not test Qt5 at runtime
CGAL::draw(t);
return EXIT_SUCCESS;
}
EOS
(testpath/"CMakeLists.txt").write <<~EOS
cmake_minimum_required(VERSION 3.1...3.15)
find_package(CGAL COMPONENTS Qt5)
add_definitions(-DCGAL_USE_BASIC_VIEWER -DQT_NO_KEYWORDS)
add_executable(surprise surprise.cpp)
target_link_libraries(surprise PUBLIC CGAL::CGAL_Qt5)
EOS
system "cmake", "-L", "-DQt5_DIR=#{Formula["qt"].opt_lib}/cmake/Qt5",
"-DCMAKE_BUILD_RPATH=#{HOMEBREW_PREFIX}/lib", "-DCMAKE_PREFIX_PATH=#{prefix}", "."
system "cmake", "--build", ".", "-v"
assert_equal "15\n15", shell_output("./surprise").chomp
end
end