From bd8cd040e287712bd674f16793142db600644ba6 Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Mon, 11 Dec 2023 16:38:53 +0100 Subject: [PATCH] (#21222) ceres-solver: add 2.2.0 + define several extra CMake vars in CMakeDeps * add legacy ceres alias target and define several upstream CMake vars - Add ceres target as an alias target. It's the old target, defined in upstream config file for backward compatibility - Define several CMake vars which are defined upstream: CERES_LIBRARIES, CERES_VERSION and CERES_FOUND * add ceres-solver/2.2.0 --- recipes/ceres-solver/all/conandata.yml | 10 +++ recipes/ceres-solver/all/conanfile.py | 64 ++++++++++++++++--- .../2.2.0-0001-find-libraries-conan.patch | 54 ++++++++++++++++ .../patches/2.2.0-0002-fix-mingw-build.patch | 12 ++++ recipes/ceres-solver/config.yml | 2 + 5 files changed, 133 insertions(+), 9 deletions(-) create mode 100644 recipes/ceres-solver/all/patches/2.2.0-0001-find-libraries-conan.patch create mode 100644 recipes/ceres-solver/all/patches/2.2.0-0002-fix-mingw-build.patch diff --git a/recipes/ceres-solver/all/conandata.yml b/recipes/ceres-solver/all/conandata.yml index 47afe48e93..7118801d3a 100644 --- a/recipes/ceres-solver/all/conandata.yml +++ b/recipes/ceres-solver/all/conandata.yml @@ -1,4 +1,7 @@ sources: + "2.2.0": + url: "http://ceres-solver.org/ceres-solver-2.2.0.tar.gz" + sha256: "48b2302a7986ece172898477c3bcd6deb8fb5cf19b3327bc49969aad4cede82d" "2.1.0": url: "http://ceres-solver.org/ceres-solver-2.1.0.tar.gz" sha256: "f7d74eecde0aed75bfc51ec48c91d01fe16a6bf16bce1987a7073286701e2fc6" @@ -9,6 +12,13 @@ sources: url: "http://ceres-solver.org/ceres-solver-1.14.0.tar.gz" sha256: "4744005fc3b902fed886ea418df70690caa8e2ff6b5a90f3dd88a3d291ef8e8e" patches: + "2.2.0": + - patch_file: "patches/2.2.0-0001-find-libraries-conan.patch" + patch_description: "Robust dependencies handling" + patch_type: "conan" + - patch_file: "patches/2.2.0-0002-fix-mingw-build.patch" + patch_description: "Fix MinGW build" + patch_type: "portability" "2.1.0": - patch_file: "patches/2.1.0-0001-find-libraries-conan.patch" patch_description: "Robust dependencies handling" diff --git a/recipes/ceres-solver/all/conanfile.py b/recipes/ceres-solver/all/conanfile.py index e4ca7cba34..10d2f4e9f0 100644 --- a/recipes/ceres-solver/all/conanfile.py +++ b/recipes/ceres-solver/all/conanfile.py @@ -3,10 +3,11 @@ from conan.errors import ConanInvalidConfiguration from conan.tools.apple import is_apple_os from conan.tools.build import check_min_cppstd, stdcpp_library from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout -from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rmdir +from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rmdir, save from conan.tools.microsoft import is_msvc, is_msvc_static_runtime from conan.tools.scm import Version import os +import textwrap required_conan_version = ">=1.54.0" @@ -51,7 +52,11 @@ class CeressolverConan(ConanFile): @property def _min_cppstd(self): - return "98" if Version(self.version) < "2.0.0" else "14" + if Version(self.version) >= "2.2.0": + return "17" + if Version(self.version) >= "2.0.0": + return "14" + return "98" @property def _compilers_minimum_version(self): @@ -63,6 +68,13 @@ class CeressolverConan(ConanFile): "msvc": "190", "Visual Studio": "14", }, + "17": { + "apple-clang": "10", + "clang": "7", + "gcc": "8", + "msvc": "191", + "Visual Studio": "15", + }, }.get(self._min_cppstd, {}) def export_sources(self): @@ -105,6 +117,10 @@ class CeressolverConan(ConanFile): f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support.", ) + def build_requirements(self): + if Version(self.version) >= "2.2.0": + self.tool_requires("cmake/[>=3.16 <4]") + def source(self): get(self, **self.conan_data["sources"][self.version], strip_root=True) @@ -113,7 +129,6 @@ class CeressolverConan(ConanFile): tc.variables["MINIGLOG"] = not self.options.use_glog tc.variables["GFLAGS"] = False # useless for the lib itself, gflags is not a direct dependency tc.variables["SUITESPARSE"] = False - tc.variables["CXSPARSE"] = False tc.variables["LAPACK"] = False tc.variables["SCHUR_SPECIALIZATIONS"] = self.options.use_schur_specializations tc.variables["CUSTOM_BLAS"] = self.options.use_custom_blas @@ -122,17 +137,25 @@ class CeressolverConan(ConanFile): tc.variables["BUILD_DOCUMENTATION"] = False tc.variables["BUILD_EXAMPLES"] = False tc.variables["BUILD_BENCHMARKS"] = False - if is_msvc(self): - tc.variables["MSVC_USE_STATIC_CRT"] = is_msvc_static_runtime(self) - if Version(self.version) >= "2.1.0": + + ceres_version = Version(self.version) + if ceres_version >= "2.2.0": + tc.variables["USE_CUDA"] = False + elif ceres_version >= "2.1.0": tc.variables["CUDA"] = False - if Version(self.version) >= "2.0.0": + if ceres_version >= "2.2.0": + tc.variables["EIGENMETIS"] = False + if ceres_version >= "2.0.0": tc.variables["PROVIDE_UNINSTALL_TARGET"] = False if is_apple_os(self): tc.variables["ACCELERATESPARSE"] = True - if Version(self.version) < "2.1.0": + if ceres_version < "2.2.0": + tc.variables["CXSPARSE"] = False + if is_msvc(self): + tc.variables["MSVC_USE_STATIC_CRT"] = is_msvc_static_runtime(self) + if ceres_version < "2.1.0": tc.variables["LIB_SUFFIX"] = "" - if Version(self.version) < "2.0": + if ceres_version < "2.0.0": tc.variables["CXX11"] = self.options.use_CXX11 tc.variables["OPENMP"] = False tc.variables["TBB"] = self.options.use_TBB @@ -153,10 +176,31 @@ class CeressolverConan(ConanFile): cmake.install() rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) rmdir(self, os.path.join(self.package_folder, "CMake")) + self._create_cmake_module_variables(os.path.join(self.package_folder, self._module_variables_file_rel_path)) + + def _create_cmake_module_variables(self, module_file): + # Define several variables of upstream CMake config file which are not + # defined out of the box by CMakeDeps. + # See https://github.com/ceres-solver/ceres-solver/blob/master/cmake/CeresConfig.cmake.in + content = textwrap.dedent(f"""\ + set(CERES_FOUND TRUE) + set(CERES_VERSION {self.version}) + if(NOT DEFINED CERES_LIBRARIES) + set(CERES_LIBRARIES Ceres::ceres) + endif() + """) + save(self, module_file, content) + + @property + def _module_variables_file_rel_path(self): + return os.path.join("lib", "cmake", f"conan-official-{self.name}-variables.cmake") def package_info(self): self.cpp_info.set_property("cmake_file_name", "Ceres") self.cpp_info.set_property("cmake_target_name", "Ceres::ceres") + # see https://github.com/ceres-solver/ceres-solver/blob/2.2.0/cmake/CeresConfig.cmake.in#L334-L340 + self.cpp_info.set_property("cmake_target_aliases", ["ceres"]) + self.cpp_info.set_property("cmake_build_modules", [self._module_variables_file_rel_path]) libsuffix = "" if self.settings.build_type == "Debug": @@ -186,4 +230,6 @@ class CeressolverConan(ConanFile): # TODO: to remove in conan v2 once cmake_find_package* generators removed self.cpp_info.names["cmake_find_package"] = "Ceres" self.cpp_info.names["cmake_find_package_multi"] = "Ceres" + self.cpp_info.components["ceres"].build_modules["cmake_find_package"] = [self._module_variables_file_rel_path] + self.cpp_info.components["ceres"].build_modules["cmake_find_package_multi"] = [self._module_variables_file_rel_path] self.cpp_info.components["ceres"].set_property("cmake_target_name", "Ceres::ceres") diff --git a/recipes/ceres-solver/all/patches/2.2.0-0001-find-libraries-conan.patch b/recipes/ceres-solver/all/patches/2.2.0-0001-find-libraries-conan.patch new file mode 100644 index 0000000000..aabc47a84c --- /dev/null +++ b/recipes/ceres-solver/all/patches/2.2.0-0001-find-libraries-conan.patch @@ -0,0 +1,54 @@ +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -433,13 +433,14 @@ else (MINIGLOG) + unset(MINIGLOG_MAX_LOG_LEVEL CACHE) + # Don't search with REQUIRED so that configuration continues if not found and + # we can output an error messages explaining MINIGLOG option. +- find_package(Glog) +- if (NOT GLOG_FOUND) ++ find_package(glog REQUIRED CONFIG) ++ if (0) + message(FATAL_ERROR "Can't find Google Log (glog). Please set either: " + "glog_DIR (newer CMake built versions of glog) or GLOG_INCLUDE_DIR & " + "GLOG_LIBRARY or enable MINIGLOG option to use minimal glog " + "implementation.") +- endif(NOT GLOG_FOUND) ++ endif() ++ if(0) + # By default, assume gflags was found, updating the message if it was not. + set(GLOG_GFLAGS_DEPENDENCY_MESSAGE + " Assuming glog was built with gflags support as gflags was found. " +@@ -452,7 +453,8 @@ else (MINIGLOG) + "Otherwise, Ceres may fail to link due to missing gflags symbols.") + endif(NOT gflags_FOUND) + message("-- Found Google Log (glog)." ${GLOG_GFLAGS_DEPENDENCY_MESSAGE}) +-endif (MINIGLOG) ++ endif() ++endif () + + if (NOT SCHUR_SPECIALIZATIONS) + list(APPEND CERES_COMPILE_OPTIONS CERES_RESTRICT_SCHUR_SPECIALIZATION) +--- a/internal/ceres/CMakeLists.txt ++++ b/internal/ceres/CMakeLists.txt +@@ -85,9 +85,9 @@ endif (SCHUR_SPECIALIZATIONS) + set_source_files_properties(${CERES_INTERNAL_SCHUR_FILES} PROPERTIES + SKIP_UNITY_BUILD_INCLUSION ON) + +-if (NOT MINIGLOG AND GLOG_FOUND) +- list(APPEND CERES_LIBRARY_PUBLIC_DEPENDENCIES ${GLOG_LIBRARIES}) +- if (gflags_FOUND) ++if (NOT MINIGLOG) ++ list(APPEND CERES_LIBRARY_PUBLIC_DEPENDENCIES glog::glog) ++ if (0) + # If glog & gflags are both found, we assume that glog was built with + # gflags, as it is awkward to perform a try_compile() to verify this + # when gflags is an imported target (as it is in newer versions). +@@ -95,7 +95,7 @@ if (NOT MINIGLOG AND GLOG_FOUND) + # gflags, it is thus a public dependency for Ceres in this case. + list(APPEND CERES_LIBRARY_PUBLIC_DEPENDENCIES gflags) + endif() +-endif (NOT MINIGLOG AND GLOG_FOUND) ++endif () + + if (SUITESPARSE AND SuiteSparse_FOUND) + # Define version information for use in Solver::FullReport. diff --git a/recipes/ceres-solver/all/patches/2.2.0-0002-fix-mingw-build.patch b/recipes/ceres-solver/all/patches/2.2.0-0002-fix-mingw-build.patch new file mode 100644 index 0000000000..2978c914e5 --- /dev/null +++ b/recipes/ceres-solver/all/patches/2.2.0-0002-fix-mingw-build.patch @@ -0,0 +1,12 @@ +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -514,6 +514,9 @@ if (MINGW) + "to a MinGW bug: http://eigen.tuxfamily.org/bz/show_bug.cgi?id=556") + string(REPLACE "-O3" "-O2" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") + update_cache_variable(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") ++ # Add the equivalent of /bigobj for MSVC for MinGW to fix 'too many sections' ++ # compile errors due to extensive use of templates. ++ add_compile_options(-Wa,-mbig-obj) + endif (MINGW) + + # After the tweaks for the compile settings, disable some warnings on MSVC. diff --git a/recipes/ceres-solver/config.yml b/recipes/ceres-solver/config.yml index 95ff77359e..c6e7e2c924 100644 --- a/recipes/ceres-solver/config.yml +++ b/recipes/ceres-solver/config.yml @@ -1,4 +1,6 @@ versions: + "2.2.0": + folder: all "2.1.0": folder: all "2.0.0":