From 9790212844e547d92dea6cd5fb94e10f638d6ae5 Mon Sep 17 00:00:00 2001 From: Esteban DUGUEPEROUX Date: Sat, 6 Apr 2024 13:28:11 +0200 Subject: [PATCH] Add geogram --- recipes/geogram/all/conandata.yml | 5 + recipes/geogram/all/conanfile.py | 175 ++++++++++++++++++ ...E_BUILD_DYNAMIC-to-BUILD_SHARED_LIBS.patch | 0 .../geogram/all/test_package/CMakeLists.txt | 11 ++ recipes/geogram/all/test_package/conanfile.py | 27 +++ .../geogram/all/test_package/test_package.cpp | 29 +++ recipes/geogram/config.yml | 3 + 7 files changed, 250 insertions(+) create mode 100644 recipes/geogram/all/conandata.yml create mode 100644 recipes/geogram/all/conanfile.py create mode 100644 recipes/geogram/all/patches/0001-Map-VORPALINE_BUILD_DYNAMIC-to-BUILD_SHARED_LIBS.patch create mode 100644 recipes/geogram/all/test_package/CMakeLists.txt create mode 100644 recipes/geogram/all/test_package/conanfile.py create mode 100644 recipes/geogram/all/test_package/test_package.cpp create mode 100644 recipes/geogram/config.yml diff --git a/recipes/geogram/all/conandata.yml b/recipes/geogram/all/conandata.yml new file mode 100644 index 00000000000000..fbdf31a1bb81ab --- /dev/null +++ b/recipes/geogram/all/conandata.yml @@ -0,0 +1,5 @@ +sources: + "1.9.0": + url: + - "https://github.com/BrunoLevy/geogram/archive/refs/tags/v1.9.0.tar.gz" + sha256: "22baa50539a56f0f88ce84adfc8bea50a379caf7120f03d3df834c4bd607a1d0" diff --git a/recipes/geogram/all/conanfile.py b/recipes/geogram/all/conanfile.py new file mode 100644 index 00000000000000..8568488478c006 --- /dev/null +++ b/recipes/geogram/all/conanfile.py @@ -0,0 +1,175 @@ +from conan import ConanFile +from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout +from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, replace_in_file, rm, rmdir +from conan.tools.microsoft import is_msvc +import os + +required_conan_version = ">=1.53.0" + +class GeogramConan(ConanFile): + name = "geogram" + description = "A programming library with geometric algorithms" + license = "BSD-3-Clause" + url = "https://github.com/conan-io/conan-center-index" + homepage = "https://github.com/BrunoLevy/geogram" + topics = ("graphics programming", "mesh generation", "geometry processing", "graphics libraries", "mesh processing") + settings = "os", "arch", "compiler", "build_type" + options = { + "shared": [True, False], + "fPIC": [True, False], + "with_graphics": [True, False], + } + default_options = { + "shared": False, + "fPIC": True, + "with_graphics": False, + } + + package_type = "library" + short_paths = True + + def export_sources(self): + export_conandata_patches(self) + + def config_options(self): + if self.settings.os == "Windows": + del self.options.fPIC + + def configure(self): + if self.options.shared: + self.options.rm_safe("fPIC") + + def layout(self): + cmake_layout(self, src_folder="src") + + def requirements(self): + self.requires("zlib/[>=1.2.11 <2]") + self.requires("libmeshb/7.80", transitive_libs=True) + self.requires("rply/1.1.4", transitive_libs=True) + self.requires("amgcl/1.4.4") + + if self.options.with_graphics: + self.requires("xorg/system") + self.requires("glfw/3.3.8") + self.requires("imgui/1.91.0") + + def source(self): + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + def generate(self): + tc = CMakeToolchain(self) + tc.variables["VORPALINE_BUILD_DYNAMIC"] = self.options.shared + tc.variables["GEOGRAM_WITH_GRAPHICS"] = self.options.with_graphics + tc.variables["GEOGRAM_LIB_ONLY"] = True + tc.variables["GEOGRAM_WITH_LEGACY_NUMERICS"] = False + tc.variables["GEOGRAM_WITH_HLBFGS"] = False + tc.variables["GEOGRAM_WITH_TETGEN"] = False + tc.variables["GEOGRAM_WITH_TRIANGLE"] = False + tc.variables["GEOGRAM_WITH_LUA"] = False + tc.variables["GEOGRAM_WITH_FPG"] = False + # To use glfw from conan dependencies + tc.variables["GEOGRAM_USE_SYSTEM_GLFW3"] = True + tc.variables["GEOGRAM_WITH_GARGANTUA"] = False + tc.variables["GEOGRAM_WITH_TBB"] = False + tc.generate() + + tc = CMakeDeps(self) + tc.generate() + + def _patch_sources(self): + apply_conandata_patches(self) + # Remove gitmodules dependencies + rmdir(self, os.path.join(self.source_folder, "src/lib/geogram/third_party/amgcl")) + rmdir(self, os.path.join(self.source_folder, "src/lib/third_party/glfw")) + rmdir(self, os.path.join(self.source_folder, "src/lib/geogram_gfx/third_party/imgui")) + # rmdir(self, os.path.join(self.source_folder, "src/lib/geogram/third_party/libMeshb")) + rmdir(self, os.path.join(self.source_folder, "src/lib/geogram/third_party/rply")) + replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"), "add_subdirectory(src/lib/third_party)", "") + replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"), "add_subdirectory(doc)", "") + replace_in_file(self, os.path.join(self.source_folder, "src", "lib", "geogram", "CMakeLists.txt"), "add_subdirectory(third_party)", + """ + add_subdirectory(third_party) + + find_package(libMeshb REQUIRED CONFIG) + find_package(rply REQUIRED CONFIG) + find_package(amgcl REQUIRED CONFIG) + """) + replace_in_file(self, os.path.join(self.source_folder, "src", "lib", "geogram", "CMakeLists.txt"), "add_library(geogram ${SOURCES} $)", + """ + add_library(geogram ${SOURCES} $) + + target_link_libraries(geogram libMeshb::Meshb.7) + target_link_libraries(geogram rply::rply) + target_link_libraries(geogram amgcl::amgcl) + """) + + # Rework cpp includes to works with libmeshb conan dependency + replace_in_file(self, os.path.join(self.source_folder, "src/lib/geogram/mesh/mesh_io.cpp"), "#include ", "#include ") + replace_in_file(self, os.path.join(self.source_folder, "src/lib/geogram/mesh/mesh_io.cpp"), "#include ", "#include ") + + # Disable cmake specific stuff in favor of CMakeDeps generated ones + replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"), "include(cmake/geo_detect_platform.cmake)", "") + # replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"), "include(cmake/geogram.cmake)", "include(cmake/utilities.cmake)") + replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"), 'string(REGEX REPLACE "-[^-]+$" "" VORPALINE_OS ${VORPALINE_PLATFORM})', "") + replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"), 'set(CPACK_SYSTEM_NAME ${VORPALINE_OS})', "") + replace_in_file(self, os.path.join(self.source_folder, "src/bin/fpg/CMakeLists.txt"), "vor_reset_warning_level()", "") + replace_in_file(self, os.path.join(self.source_folder, "src/lib/geogram/third_party/CMakeLists.txt"), "vor_reset_warning_level()", "") + replace_in_file(self, os.path.join(self.source_folder, "src/lib/geogram_gfx/third_party/CMakeLists.txt"), "vor_reset_warning_level()", "") + replace_in_file(self, os.path.join(self.source_folder, "src/lib/third_party/CMakeLists.txt"), "vor_reset_warning_level()", "") + replace_in_file(self, os.path.join(self.source_folder, "src/lib/third_party/numerics/CMakeLists.txt"), "vor_reset_warning_level()", "") + + replace_in_file(self, os.path.join(self.source_folder, "cmake/geogram.cmake"), "if(NOT VORPALINE_PLATFORM)", "if(0)") + replace_in_file(self, os.path.join(self.source_folder, "cmake/geogram.cmake"), "include(${GEOGRAM_SOURCE_DIR}/cmake/platforms/${VORPALINE_PLATFORM}/config.cmake)", "") + + def build(self): + self._patch_sources() + + cmake = CMake(self) + cmake.configure() + cmake.build() + + def package(self): + copy(self, pattern="LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) + cmake = CMake(self) + cmake.install() + + # some files extensions and folders are not allowed. Please, read the FAQs to get informed. + rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) + rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) + rmdir(self, os.path.join(self.package_folder, "share")) + rm(self, "*.la", os.path.join(self.package_folder, "lib")) + rm(self, "*.pdb", os.path.join(self.package_folder, "lib")) + rm(self, "*.pdb", os.path.join(self.package_folder, "bin")) + + def package_info(self): + self.cpp_info.set_property("cmake_file_name", "Geogram") + + if self.options.with_graphics: + self.cpp_info.components["geogram_gfx"].includedirs = ["include/geogram1"] + self.cpp_info.components["geogram_gfx"].libs = ["geogram_gfx"] + self.cpp_info.components["geogram_gfx"].requires = ["geogram", "glfw::glfw"] + self.cpp_info.components["geogram_gfx"].set_property("cmake_target_name", "Geogram::geogram") + + # self.cpp_info.components["geogram_num_3rdparty"].includedirs = ["include/geogram1"] + # self.cpp_info.components["geogram_num_3rdparty"].libs = ["geogram_num_3rdparty"] + # self.cpp_info.components["geogram_num_3rdparty"].set_property("cmake_target_name", "Geogram::geogram_num_3rdparty") + + self.cpp_info.components["geogram"].includedirs = ["include/geogram1"] + self.cpp_info.components["geogram"].libs = ["geogram"] + self.cpp_info.components["geogram"].set_property("cmake_target_name", "Geogram::geogram") + if not self.options.shared: + openmp_flags = [] + if is_msvc(self): + openmp_flags = ["-openmp"] + elif self.settings.compiler in ("gcc", "clang"): + openmp_flags = ["-fopenmp"] + elif self.settings.compiler == "apple-clang": + openmp_flags = ["-Xpreprocessor", "-fopenmp"] + self.cpp_info.components["geogram"].sharedlinkflags = openmp_flags + self.cpp_info.components["geogram"].exelinkflags = openmp_flags + + # If they are needed on Linux, m, pthread and dl are usually needed on FreeBSD too + if self.settings.os in ["Linux", "FreeBSD"]: + self.cpp_info.system_libs.append("m") + self.cpp_info.system_libs.append("pthread") + self.cpp_info.system_libs.append("dl") diff --git a/recipes/geogram/all/patches/0001-Map-VORPALINE_BUILD_DYNAMIC-to-BUILD_SHARED_LIBS.patch b/recipes/geogram/all/patches/0001-Map-VORPALINE_BUILD_DYNAMIC-to-BUILD_SHARED_LIBS.patch new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/recipes/geogram/all/test_package/CMakeLists.txt b/recipes/geogram/all/test_package/CMakeLists.txt new file mode 100644 index 00000000000000..5ac37a6f45e89b --- /dev/null +++ b/recipes/geogram/all/test_package/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.15) + +project(test_package CXX) + +find_package(Geogram REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} test_package.cpp) +# don't link to ${CONAN_LIBS} or CONAN_PKG::package +target_link_libraries(${PROJECT_NAME} PRIVATE Geogram::geogram) +# In case the target project need a specific C++ standard +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) \ No newline at end of file diff --git a/recipes/geogram/all/test_package/conanfile.py b/recipes/geogram/all/test_package/conanfile.py new file mode 100644 index 00000000000000..296c5a17cba666 --- /dev/null +++ b/recipes/geogram/all/test_package/conanfile.py @@ -0,0 +1,27 @@ +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import cmake_layout, CMake +import os + + +# It will become the standard on Conan 2.x +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" + test_type = "explicit" + + def requirements(self): + self.requires(self.tested_reference_str) + + def layout(self): + cmake_layout(self) + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if can_run(self): + bin_path = os.path.join(self.cpp.build.bindir, "test_package /dev/null") + self.run(bin_path, env="conanrun") diff --git a/recipes/geogram/all/test_package/test_package.cpp b/recipes/geogram/all/test_package/test_package.cpp new file mode 100644 index 00000000000000..df205473dffcb3 --- /dev/null +++ b/recipes/geogram/all/test_package/test_package.cpp @@ -0,0 +1,29 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char** argv) { + + GEO::initialize(); + GEO::Logger::instance()->set_quiet(false); + GEO::CmdLine::import_arg_group("standard"); + GEO::CmdLine::import_arg_group("algo"); + GEO::CmdLine::declare_arg_percent("size", 10.0, "elements size, in bbox diagonal percent"); + GEO::CmdLine::declare_arg("shrink", 0.9, "cells shrink"); + GEO::CmdLine::declare_arg("border_only", false, "output only RVC facets on the border"); + + std::vector filenames; + GEO::CmdLine::parse(argc, argv, filenames, "points_filename "); + + return 0; +} \ No newline at end of file diff --git a/recipes/geogram/config.yml b/recipes/geogram/config.yml new file mode 100644 index 00000000000000..81634fc799e565 --- /dev/null +++ b/recipes/geogram/config.yml @@ -0,0 +1,3 @@ +versions: + "1.9.0": + folder: all