Repository: conan-io/conan-center-index

Issue:
[package] cgal/all: review options applied
Comming from https://github.com/conan-io/conan-center-index/pull/965#issuecomment-590802910

Seems that the recipe might require some work regarding the options and flags


Discussion:
cc/ @SpaceIm

Resolving patch:
diff --git a/recipes/cgal/all/conanfile.py b/recipes/cgal/all/conanfile.py
--- a/recipes/cgal/all/conanfile.py
+++ b/recipes/cgal/all/conanfile.py
@@ -1,5 +1,6 @@
 import os
 from conans import ConanFile, CMake, tools
+from conans.errors import ConanInvalidConfiguration
 
 
 class CgalConan(ConanFile):
@@ -13,20 +14,26 @@ class CgalConan(ConanFile):
     settings = "os", "compiler", "build_type", "arch"
     requires = "mpir/3.0.0", "mpfr/4.0.2", "boost/1.72.0", "eigen/3.3.7"
     generators = "cmake"
+    exports_sources = "CMakeLists.txt"
 
     _source_subfolder = "source_subfolder"
+    _build_subfolder = "build_subfolder"
     _cmake = None
 
     options = {
         "with_cgal_core": [True, False],
         "with_cgal_qt5": [True, False],
-        "with_cgal_imageio": [True, False]
+        "with_cgal_imageio": [True, False],
+        "shared": [True, False],
+        "header_only": [True, False]
     }
 
     default_options = {
         "with_cgal_core": True,
         "with_cgal_qt5": False,
-        "with_cgal_imageio": True
+        "with_cgal_imageio": True,
+        "shared": False,
+        "header_only": True
     }
 
     def _configure_cmake(self):
@@ -35,15 +42,19 @@ def _configure_cmake(self):
             self._cmake.definitions["WITH_CGAL_Core"] = self.options.with_cgal_core
             self._cmake.definitions["WITH_CGAL_Qt5"] = self.options.with_cgal_qt5
             self._cmake.definitions["WITH_CGAL_ImageIO"] = self.options.with_cgal_imageio
-            self._cmake.configure(source_folder=self._source_subfolder)
+            self._cmake.definitions["CGAL_HEADER_ONLY"] = self.options.header_only
+            self._cmake.configure(build_folder=self._build_subfolder)
         return self._cmake
 
     def _patch_sources(self):
-        tools.replace_in_file(
-            os.path.join(self._source_subfolder, "CMakeLists.txt"),
-            "project(CGAL CXX C)", '''project(CGAL CXX C)
-include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
-conan_basic_setup()''')
+        tools.replace_in_file(os.path.join(self._source_subfolder, "CMakeLists.txt"),
+                              "CMAKE_SOURCE_DIR", "CMAKE_CURRENT_SOURCE_DIR")
+
+    def configure(self):
+        if self.options.with_cgal_qt5:
+            raise ConanInvalidConfiguration("Qt Conan package is not available yet.")
+        if self.options.header_only:
+            del self.options.shared
 
     def source(self):
         tools.get(**self.conan_data["sources"][self.version])
@@ -61,11 +72,20 @@ def package(self):
         cmake.install()
         tools.rmdir(os.path.join(self.package_folder, "share"))
         tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
-        tools.rmdir(os.path.join(self.package_folder, "bin"))
+        if self.options.get_safe("shared"):
+            for root, _, filenames in os.walk(os.path.join(self.package_folder, "bin")):
+                for filename in filenames:
+                    if not filename.endswith(".dll"):
+                        os.unlink(os.path.join(root, filename))
+        else:
+            tools.rmdir(os.path.join(self.package_folder, "bin"))
 
     def package_info(self):
+        if not self.options.header_only:
+            self.cpp_info.libs = tools.collect_libs(self)
         self.cpp_info.names["cmake_find_package"] = "CGAL"
         self.cpp_info.names["cmake_find_package_multi"] = "CGAL"
 
     def package_id(self):
-        self.info.header_only()
+        if self.options.header_only:
+            self.info.header_only()


Test patch: