diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c5f5c6..df3cc9f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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 .) diff --git a/_pyceres/logging.h b/_pyceres/logging.h index 21eec4c..189f6f2 100644 --- a/_pyceres/logging.h +++ b/_pyceres/logging.h @@ -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) @@ -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 {