diff --git a/CMakeLists.txt b/CMakeLists.txt index 3574a26..df3cc9f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,19 +1,15 @@ cmake_minimum_required(VERSION 3.10) project(${SKBUILD_PROJECT_NAME} VERSION ${SKBUILD_PROJECT_VERSION}) -find_package(Ceres REQUIRED) -if(NOT TARGET Ceres::ceres) - # Older Ceres versions don't come with an imported interface target. - add_library(Ceres::ceres INTERFACE IMPORTED) - target_include_directories( - Ceres::ceres INTERFACE ${CERES_INCLUDE_DIRS}) - target_link_libraries( - Ceres::ceres INTERFACE ${CERES_LIBRARIES}) -endif() -if(${CERES_VERSION} VERSION_LESS "2.1.0") - message( SEND_ERROR "Ceres version >= 2.1 required, found ${CERES_VERSION}." ) +find_package(glog REQUIRED) +if(DEFINED glog_VERSION_MAJOR) + # Older versions of glog don't export version variables. + add_definitions("-DGLOG_VERSION_MAJOR=${glog_VERSION_MAJOR}") + add_definitions("-DGLOG_VERSION_MINOR=${glog_VERSION_MINOR}") endif() +find_package(Ceres 2.1 REQUIRED) + find_package(Python REQUIRED COMPONENTS Interpreter Development.Module) find_package(pybind11 2.11.1 REQUIRED) diff --git a/_pyceres/logging.h b/_pyceres/logging.h index bf6df04..189f6f2 100644 --- a/_pyceres/logging.h +++ b/_pyceres/logging.h @@ -105,7 +105,12 @@ class LogMessageFatalThrow : public google::LogMessage { prefix_(__MakeExceptionPrefix(file, line)){}; LogMessageFatalThrow(const char* file, int line, +#if defined(GLOG_VERSION_MAJOR) && \ + (GLOG_VERSION_MAJOR > 0 || GLOG_VERSION_MINOR >= 7) + const google::logging::internal::CheckOpString& result) +#else const google::CheckOpString& result) +#endif : google::LogMessage(file, line, google::GLOG_ERROR, &message_), prefix_(__MakeExceptionPrefix(file, line)) { stream() << "Check failed: " << (*result.str_) << " "; @@ -211,7 +216,11 @@ void BindLogging(py::module& m) { .value("ERROR", Logging::LogSeverity::GLOG_ERROR) .value("FATAL", Logging::LogSeverity::GLOG_FATAL) .export_values(); - if (!google::IsGoogleLoggingInitialized()) { +#if defined(GLOG_VERSION_MAJOR) && \ + (GLOG_VERSION_MAJOR > 0 || GLOG_VERSION_MINOR >= 6) + if (!google::IsGoogleLoggingInitialized()) +#endif + { google::InitGoogleLogging(""); google::InstallFailureSignalHandler(); google::InstallFailureFunction(&PyBindLogTermination);