Repository: conan-io/conan-center-index

Issue:
[request] ceres-solver/2.0.0
### Package Details
  * Package Name/Version: **ceres-solver/2.0.0**
  * Changelog: **http://ceres-solver.org/version_history.html**

https://github.com/ceres-solver/ceres-solver/tree/2.0.0

The above mentioned version is newly released by the upstream project and not yet available as a recipe. Please add this version.



Discussion:
Hi @AndreyMlashkin,
I already started work to include ceres 2.0 in the ceres conan package. It will probably need me some more days to finish the work. I will post here once I have a proposal for a pull request.

Cheers,
Thomas

Resolving patch:
diff --git a/recipes/ceres-solver/all/conanfile.py b/recipes/ceres-solver/all/conanfile.py
--- a/recipes/ceres-solver/all/conanfile.py
+++ b/recipes/ceres-solver/all/conanfile.py
@@ -6,7 +6,7 @@ class ceressolverConan(ConanFile):
     name = "ceres-solver"
     license = "BSD-3-Clause"
     url = "https://github.com/conan-io/conan-center-index"
-    homepage = "http://ceres-solver.org/r"
+    homepage = "http://ceres-solver.org/"
     description = ("Ceres Solver is an open source C++ library for modeling\
                     and solving large, complicated optimization problems")
     topics = ("optimization","Non-linear Least Squares")
@@ -33,38 +33,31 @@ class ceressolverConan(ConanFile):
                        "use_CXX11": False,
                        "use_schur_specializations": True}
     exports_sources = ["CMakeLists.txt","patches/*"]
-    _source_subfolder = "source_subfolder"
-    _cmake = None
 
-    def _configure_cmake(self):
-        if not self._cmake:
-            self._cmake = CMake(self)       #You can check what these flags do in http://ceres-solver.org/installation.html
-            self._cmake.definitions["GFLAGS"] = self.options.use_gflags
-            self._cmake.definitions["BUILD_EXAMPLES"] = False           #Requires gflags
-            self._cmake.definitions["BUILD_TESTING"] = False            #Requires gflags
-            self._cmake.definitions["BUILD_DOCUMENTATION"] = False      #Requires python modules Sphinx and sphinx-rtd-theme
-            self._cmake.definitions["CUSTOM_BLAS"] = self.options.use_custom_blas
-            self._cmake.definitions["EIGEN_PREFER_EXPORTED_EIGEN_CMAKE_CONFIGURATION"] = False    #Set to false to Force CMake to use the conan-generated dependencies
-            self._cmake.definitions["GLOG_PREFER_EXPORTED_GLOG_CMAKE_CONFIGURATION"] = False      #Set to false to Force CMake to use the conan-generated dependencies
-            self._cmake.definitions["GFLAGS_PREFER_EXPORTED_GFLAGS_CMAKE_CONFIGURATION"] = False  #Set to false to Force CMake to use the conan-generated dependencies
-            self._cmake.definitions["EIGENSPARSE"] = self.options.use_eigen_sparse
-            self._cmake.definitions["SUITESPARSE"] = False  #Optional. Not sufpported right now because SuiteSparse is not part of conan-index
-            self._cmake.definitions["LAPACK"] = False       #Optional. Not supported right now because LAPACK is not part of conan-index
-            self._cmake.definitions["OPENMP"] = False
-            self._cmake.definitions["CXSPARSE"] = False     #Optional. Not supported right now because CXSSPARSE is not part of conan-index
-            self._cmake.definitions["MINIGLOG"] = not self.options.use_glog
-            self._cmake.definitions["TBB"] = self.options.use_TBB
-            self._cmake.definitions["CXX11_THREADS"] = self.options.use_CXX11_threads
-            self._cmake.definitions["CXX11"] = self.options.use_CXX11
-            self._cmake.definitions["SCHUR_SPECIALIZATIONS"] = self.options.use_schur_specializations
-            if self.settings.os == "Windows":
-                self._cmake.definitions["MSVC_USE_STATIC_CRT"] = str(self.settings.compiler.runtime) == "MT" or str(self.settings.compiler.runtime) == "MTd"
-            self._cmake.configure()
-        return self._cmake
+    @property
+    def _source_subfolder(self):
+        return "source_subfolder"
+
+    _cmake = None
 
     def config_options(self):
         if self.settings.os == "Windows":
             del self.options.fPIC
+        if tools.Version(self.version) >= "2.0":
+            del self.options.use_CXX11_threads
+            del self.options.use_CXX11
+
+    def _check_cxx14_supported(self):
+        min_compiler_version = {
+            "gcc": "5",
+            "Visual Studio": "14",
+            "clang": "5",
+            "apple-clang": "5",
+        }.get(str(self.settings.compiler))
+        if not min_compiler_version:
+            self.output.warn("Unknown compiler. Presuming it supports c++14.")
+        elif tools.Version(self.settings.compiler.version) < min_compiler_version:
+            raise ConanInvalidConfiguration("Current compiler version does not support c++14")
 
     def configure(self):
         if self.options.shared:
@@ -73,51 +66,88 @@ def configure(self):
             raise ConanInvalidConfiguration("Ceres-solver only links against the release version of glog")
         if self.options.use_glog and not self.options.use_gflags: #At this stage we can't check the value of self.options["glog"].with_gflags so we asume it is true because is the default value
             raise ConanInvalidConfiguration("To depend on glog built with gflags (Default behavior) set use_gflags=True, otherwise Ceres may fail to link due to missing gflags symbols.")
+        if tools.Version(self.version) >= "2.0":
+            # 1.x uses ceres-solver specific FindXXX.cmake modules
+            self.generators.append("cmake_find_package")
+            if self.settings.compiler.cppstd:
+                tools.check_min_cppstd(self, 14)
+            self._check_cxx14_supported()
 
     def requirements(self):
-        self.requires("eigen/3.3.7")
+        self.requires("eigen/3.3.8")
         if self.options.use_glog:
             self.requires("glog/0.4.0")
         if self.options.use_gflags:
             self.requires("gflags/2.2.2")
             self.options["gflags"].nothreads = False
         if self.options.use_TBB:
-            self.requires("tbb/2020.0")
+            self.requires("tbb/2020.2")
 
     def source(self):
         tools.get(**self.conan_data["sources"][self.version])
         extracted_dir = self.name + "-" + self.version
         os.rename(extracted_dir, self._source_subfolder)
 
+    def _configure_cmake(self):
+        if self._cmake:
+            return self._cmake
+        self._cmake = CMake(self)       #You can check what these flags do in http://ceres-solver.org/installation.html
+        self._cmake.definitions["LIB_SUFFIX"] = ""
+        self._cmake.definitions["GFLAGS"] = self.options.use_gflags
+        self._cmake.definitions["BUILD_EXAMPLES"] = False           #Requires gflags
+        self._cmake.definitions["BUILD_TESTING"] = False            #Requires gflags
+        self._cmake.definitions["BUILD_DOCUMENTATION"] = False      #Requires python modules Sphinx and sphinx-rtd-theme
+        self._cmake.definitions["CUSTOM_BLAS"] = self.options.use_custom_blas
+        self._cmake.definitions["GLOG_PREFER_EXPORTED_GLOG_CMAKE_CONFIGURATION"] = False      #Set to false to Force CMake to use the conan-generated dependencies
+        self._cmake.definitions["EIGENSPARSE"] = self.options.use_eigen_sparse
+        self._cmake.definitions["SUITESPARSE"] = False  #Optional. Not supported right now because SuiteSparse is not part of conan-index
+        self._cmake.definitions["LAPACK"] = False       #Optional. Not supported right now because LAPACK is not part of conan-index
+        self._cmake.definitions["CXSPARSE"] = False     #Optional. Not supported right now because CXSSPARSE is not part of conan-index
+        self._cmake.definitions["MINIGLOG"] = not self.options.use_glog
+        if not self.options.use_TBB:
+            self._cmake.definitions["CMAKE_DISABLE_FIND_PACKAGE_TBB"] = True
+        if tools.Version(self.version) < "2.0":
+            self._cmake.definitions["TBB"] = self.options.use_TBB
+            self._cmake.definitions["OPENMP"] = False
+            self._cmake.definitions["EIGEN_PREFER_EXPORTED_EIGEN_CMAKE_CONFIGURATION"] = False    #Set to false to Force CMake to use the conan-generated dependencies
+            self._cmake.definitions["GFLAGS_PREFER_EXPORTED_GFLAGS_CMAKE_CONFIGURATION"] = False  #Set to false to Force CMake to use the conan-generated dependencies
+            self._cmake.definitions["CXX11_THREADS"] = self.options.use_CXX11_threads
+            self._cmake.definitions["CXX11"] = self.options.use_CXX11
+        self._cmake.definitions["SCHUR_SPECIALIZATIONS"] = self.options.use_schur_specializations
+        if self.settings.compiler == "Visual Studio":
+            self._cmake.definitions["MSVC_USE_STATIC_CRT"] = str(self.settings.compiler.runtime) == "MT" or str(self.settings.compiler.runtime) == "MTd"
+        self._cmake.configure()
+        return self._cmake
+
     def build(self):
-        #Make sure that cmake finds gflags is use_gflags=True
-        tools.replace_in_file(os.path.join(self._source_subfolder, "CMakeLists.txt"),
-                              "find_package(Gflags)",
-                              "find_package(Gflags REQUIRED)")
-        #On windows the library names can be gflags.dll or gflags_static.lib
-        tools.replace_in_file(os.path.join(self._source_subfolder, "cmake", "FindGflags.cmake"),
-                              "find_library(GFLAGS_LIBRARY NAMES gflags",
-                              "find_library(GFLAGS_LIBRARY NAMES gflags gflags_static")
-        for patch in self.conan_data["patches"][self.version]:
+        for patch in self.conan_data.get("patches", {}).get(self.version, []):
             tools.patch(**patch)
         cmake = self._configure_cmake()
         cmake.build()
 
     def package(self):
+        self.copy("LICENSE", src=self._source_subfolder, dst="licenses")
         cmake = self._configure_cmake()
         cmake.install()
-        self.copy("LICENSE", src=self._source_subfolder, dst="licenses")
-        tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
         tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
         tools.rmdir(os.path.join(self.package_folder, "CMake"))
 
     def package_info(self):
+        libsuffix = ""
+        if self.settings.build_type == "Debug":
+            libsuffix = "-debug"
         self.cpp_info.names["cmake_find_package"] = "Ceres"
         self.cpp_info.names["cmake_find_package_multi"] = "Ceres"
-        self.cpp_info.components["ceres"].libs = tools.collect_libs(self)
+        self.cpp_info.components["ceres"].libs = ["ceres{}".format(libsuffix)]
         self.cpp_info.components["ceres"].includedirs = ["include", os.path.join("include","ceres")]
         if not self.options.use_glog:
             self.cpp_info.components["ceres"].includedirs.append(os.path.join("include","ceres", "internal", "miniglog"))
+        if self.settings.os == "Linux":
+            if self.options.get_safe("use_CXX11_threads", True):
+                self.cpp_info.components["ceres"].system_libs.append("pthread")
+        elif tools.is_apple_os(self.settings.os):
+            if tools.Version(self.version) >= "2":
+                self.cpp_info.components["ceres"].frameworks = ["Accelerate"]
         self.cpp_info.components["ceres"].requires = ["eigen::eigen"]
         if self.options.use_glog:
             self.cpp_info.components["ceres"].requires.append("glog::glog")
@@ -125,3 +155,6 @@ def package_info(self):
             self.cpp_info.components["ceres"].requires.append("gflags::gflags")
         if self.options.use_TBB:
             self.cpp_info.components["ceres"].requires.append("tbb::tbb")
+        libcxx = tools.stdcpp_library(self)
+        if libcxx:
+            self.cpp_info.components["ceres"].system_libs.append(libcxx)


Test patch:
diff --git a/recipes/ceres-solver/all/test_package/CMakeLists.txt b/recipes/ceres-solver/all/test_package/CMakeLists.txt
--- a/recipes/ceres-solver/all/test_package/CMakeLists.txt
+++ b/recipes/ceres-solver/all/test_package/CMakeLists.txt
@@ -2,9 +2,9 @@ cmake_minimum_required(VERSION 3.1)
 project(test_package)
 
 include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
-conan_basic_setup()
+conan_basic_setup(TARGETS)
 
 find_package(Ceres REQUIRED CONFIG)
 
-add_executable(${PROJECT_NAME} test_package.cpp)
+add_executable(${PROJECT_NAME} test_package.c)
 target_link_libraries(${PROJECT_NAME} Ceres::ceres)
diff --git a/recipes/ceres-solver/all/test_package/test_package.cpp b/recipes/ceres-solver/all/test_package/test_package.c
similarity index 99%
rename from recipes/ceres-solver/all/test_package/test_package.cpp
rename to recipes/ceres-solver/all/test_package/test_package.c
--- a/recipes/ceres-solver/all/test_package/test_package.cpp
+++ b/recipes/ceres-solver/all/test_package/test_package.c
@@ -31,10 +31,11 @@
  * This is a port of curve_fitting.cc to the minimal C API for Ceres.
  */
 
+#include "ceres/c_api.h"
+
 #include <math.h>
 #include <stdio.h>
 #include <string.h>  // For NULL
-#include "ceres/c_api.h"
 
 /* Data generated using the following octave code.
  *