Skip to content

Commit

Permalink
Handle older versions of glog
Browse files Browse the repository at this point in the history
  • Loading branch information
sarlinpe committed Feb 9, 2024
1 parent 2d70b48 commit af03372
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
13 changes: 8 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
cmake_minimum_required(VERSION 3.10)
project(${SKBUILD_PROJECT_NAME} VERSION ${SKBUILD_PROJECT_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)
Expand All @@ -10,9 +17,5 @@ find_package(pybind11 2.11.1 REQUIRED)
pybind11_add_module(pyceres _pyceres/bindings.cc)
target_include_directories(pyceres PRIVATE ${PROJECT_SOURCE_DIR})
target_link_libraries(pyceres PRIVATE glog::glog Ceres::ceres)
target_compile_definitions(
pyceres
PRIVATE VERSION_INFO="${PROJECT_VERSION}"
GLOG_VERSION_MAJOR=${glog_VERSION_MAJOR}
GLOG_VERSION_MINOR=${glog_VERSION_MINOR})
target_compile_definitions(pyceres PRIVATE VERSION_INFO="${PROJECT_VERSION}")
install(TARGETS pyceres LIBRARY DESTINATION .)
6 changes: 4 additions & 2 deletions _pyceres/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ class LogMessageFatalThrow : public google::LogMessage {
prefix_(__MakeExceptionPrefix(file, line)){};
LogMessageFatalThrow(const char* file,
int line,
#if GLOG_VERSION_MAJOR > 0 || GLOG_VERSION_MINOR >= 7
#if defined(GLOG_VERSION_MAJOR) && \
(GLOG_VERSION_MAJOR > 0 || GLOG_VERSION_MINOR >= 7)
const google::logging::internal::CheckOpString& result)
#else
const google::CheckOpString& result)
Expand Down Expand Up @@ -215,7 +216,8 @@ void BindLogging(py::module& m) {
.value("ERROR", Logging::LogSeverity::GLOG_ERROR)
.value("FATAL", Logging::LogSeverity::GLOG_FATAL)
.export_values();
#if GLOG_VERSION_MAJOR > 0 || GLOG_VERSION_MINOR >= 6
#if defined(GLOG_VERSION_MAJOR) && \
(GLOG_VERSION_MAJOR > 0 || GLOG_VERSION_MINOR >= 6)
if (!google::IsGoogleLoggingInitialized())
#endif
{
Expand Down

0 comments on commit af03372

Please sign in to comment.