diff --git a/CMakeLists.txt b/CMakeLists.txt index 97a172664..89d0bf035 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -348,6 +348,7 @@ if (GFLAGS) if (GFLAGS_FOUND) message("-- Found Google Flags header in: ${GFLAGS_INCLUDE_DIRS}, " "in namespace: ${GFLAGS_NAMESPACE}") + add_definitions(-DCERES_GFLAGS_NAMESPACE=${GFLAGS_NAMESPACE}) else (GFLAGS_FOUND) message("-- Did not find Google Flags (gflags), Building without gflags " "- no tests or tools will be built!") @@ -386,6 +387,18 @@ else (MINIGLOG) "GLOG_LIBRARY or enable MINIGLOG option to use minimal glog " "implementation.") endif(NOT GLOG_FOUND) + # 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. " + "This will make gflags a public dependency of Ceres.") + if (NOT GFLAGS_FOUND) + set(GLOG_GFLAGS_DEPENDENCY_MESSAGE + " Assuming glog was NOT built with gflags support as gflags was " + "not found. If glog was built with gflags, please set the " + "gflags search locations such that it can be found by Ceres. " + "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) if (NOT SCHUR_SPECIALIZATIONS) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index b589b458c..eef5e5e12 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -73,11 +73,6 @@ add_executable(simple_bundle_adjuster simple_bundle_adjuster.cc) target_link_libraries(simple_bundle_adjuster ceres) if (GFLAGS) - # The CERES_GFLAGS_NAMESPACE compile definition is NOT stored in - # CERES_COMPILE_OPTIONS (and thus config.h) as Ceres itself does not - # require gflags, only the tests and examples do. - add_definitions(-DCERES_GFLAGS_NAMESPACE=${GFLAGS_NAMESPACE}) - add_executable(powell powell.cc) target_link_libraries(powell ceres ${GFLAGS_LIBRARIES}) @@ -115,4 +110,4 @@ if (GFLAGS) endif (GFLAGS) add_subdirectory(sampled_function) -add_subdirectory(slam) \ No newline at end of file +add_subdirectory(slam) diff --git a/internal/ceres/CMakeLists.txt b/internal/ceres/CMakeLists.txt index c352e0ef7..bdcbdd117 100644 --- a/internal/ceres/CMakeLists.txt +++ b/internal/ceres/CMakeLists.txt @@ -132,6 +132,14 @@ endif (SCHUR_SPECIALIZATIONS) # Build the list of dependencies for Ceres based on the current configuration. if (NOT MINIGLOG AND GLOG_FOUND) list(APPEND CERES_LIBRARY_PUBLIC_DEPENDENCIES ${GLOG_LIBRARIES}) + if (GFLAGS_FOUND) + # 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). + # As glog #includes gflags/gflags.h in glog/logging.h if compiled with + # gflags, it is thus a public dependency for Ceres in this case. + list(APPEND CERES_LIBRARY_PUBLIC_DEPENDENCIES ${GFLAGS_LIBRARIES}) + endif() endif (NOT MINIGLOG AND GLOG_FOUND) if (SUITESPARSE AND SUITESPARSE_FOUND) @@ -242,11 +250,6 @@ install(TARGETS ceres ARCHIVE DESTINATION lib${LIB_SUFFIX}) if (BUILD_TESTING AND GFLAGS) - # The CERES_GFLAGS_NAMESPACE compile definition is NOT stored in - # CERES_COMPILE_OPTIONS (and thus config.h) as Ceres itself does not - # require gflags, only the tests and examples do. - add_definitions(-DCERES_GFLAGS_NAMESPACE=${GFLAGS_NAMESPACE}) - add_library(gtest gmock_gtest_all.cc gmock_main.cc) if (BUILD_SHARED_LIBS) # Define gtest-specific shared library flags for compilation.