jackett 0.22.1382
[Homebrew/homebrew-core.git] / Formula / c / cgal.rb
blobfa9f57992ca656d5e5f391954405fd01859a5711
1 class Cgal < Formula
2   desc "Computational Geometry Algorithms Library"
3   homepage "https://www.cgal.org/"
4   url "https://github.com/CGAL/cgal/releases/download/v6.0.1/CGAL-6.0.1.tar.xz"
5   sha256 "0acdfbf317c556630dd526f3253780f29b6ec9713ee92903e81b5c93c0f59b7f"
6   license "GPL-3.0-or-later"
8   bottle do
9     sha256 cellar: :any_skip_relocation, all: "f423b392b99b69eff16bdad8309eebfa1e01ef6e569c6c2b50fd20e2fafeab7d"
10   end
12   depends_on "cmake" => [:build, :test]
13   depends_on "qt" => :test
14   depends_on "boost"
15   depends_on "eigen"
16   depends_on "gmp"
17   depends_on "mpfr"
19   on_linux do
20     depends_on "openssl@3"
21   end
23   def install
24     system "cmake", "-S", ".", "-B", "build", *std_cmake_args
25     system "cmake", "--build", "build"
26     system "cmake", "--install", "build"
28     # Ensure that the various `Find*` modules look in HOMEBREW_PREFIX.
29     # This also helps guarantee uniform bottles.
30     inreplace_files = %w[
31       CGAL_Common.cmake
32       FindESBTL.cmake
33       FindGLPK.cmake
34       FindIPE.cmake
35       FindLASLIB.cmake
36       FindMKL.cmake
37       FindOSQP.cmake
38       FindSuiteSparse.cmake
39     ]
40     inreplace inreplace_files.map { |file| lib/"cmake/CGAL"/file }, "/usr/local", HOMEBREW_PREFIX
42     # These cause different bottles to be built between macOS and Linux for some reason.
43     %w[README.md readme.md].each { |file| (buildpath/file).unlink if (buildpath/file).exist? }
44   end
46   test do
47     # 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
48     (testpath/"surprise.cpp").write <<~CPP
49       #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
50       #include <CGAL/Triangulation_2.h>
51       #include <CGAL/draw_triangulation_2.h>
52       #include <CGAL/basic.h>
53       #include <CGAL/Coercion_traits.h>
54       #include <CGAL/IO/io.h>
55       #include <fstream>
56       typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
57       typedef CGAL::Triangulation_2<K>                            Triangulation;
58       typedef Triangulation::Point                                Point;
60       template <typename A, typename B>
61       typename CGAL::Coercion_traits<A,B>::Type
62       binary_func(const A& a , const B& b){
63           typedef CGAL::Coercion_traits<A,B> CT;
64           typename CT::Cast cast;
65           return cast(a)*cast(b);
66       }
68       int main(int argc, char**) {
69         std::cout<< binary_func(double(3), int(5)) << std::endl;
70         std::cout<< binary_func(int(3), double(5)) << std::endl;
71         std::ifstream in("data/triangulation_prog1.cin");
72         std::istream_iterator<Point> begin(in);
73         std::istream_iterator<Point> end;
74         Triangulation t;
75         t.insert(begin, end);
76         if(argc == 3) // do not test Qt6 at runtime
77           CGAL::draw(t);
78         return EXIT_SUCCESS;
79        }
80     CPP
81     (testpath/"CMakeLists.txt").write <<~CMAKE
82       cmake_minimum_required(VERSION 3.1...3.15)
83       find_package(CGAL COMPONENTS Qt6)
84       add_definitions(-DCGAL_USE_BASIC_VIEWER -DQT_NO_KEYWORDS)
85       include_directories(surprise BEFORE SYSTEM #{Formula["qt"].opt_include})
86       add_executable(surprise surprise.cpp)
87       target_include_directories(surprise BEFORE PUBLIC #{Formula["qt"].opt_include})
88       target_link_libraries(surprise PUBLIC CGAL::CGAL_Qt6)
89     CMAKE
90     system "cmake", "-L", "-DQt6_DIR=#{Formula["qt"].opt_lib}/cmake/Qt6",
91            "-DCMAKE_PREFIX_PATH=#{Formula["qt"].opt_lib}",
92            "-DCMAKE_BUILD_RPATH=#{HOMEBREW_PREFIX}/lib", "-DCMAKE_PREFIX_PATH=#{prefix}", "."
93     system "cmake", "--build", ".", "-v"
94     assert_equal "15\n15", shell_output("./surprise").chomp
95   end
96 end