(#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
This commit is contained in:
SpaceIm
2023-12-11 16:38:53 +01:00
committed by GitHub
parent ee0c6ff8c0
commit bd8cd040e2
5 changed files with 133 additions and 9 deletions

View File

@@ -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"

View File

@@ -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")

View File

@@ -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.

View File

@@ -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.

View File

@@ -1,4 +1,6 @@
versions:
"2.2.0":
folder: all
"2.1.0":
folder: all
"2.0.0":