diff --git a/CMakeLists.txt b/CMakeLists.txt index 2a6b37606..ea39ad48c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -759,8 +759,13 @@ install(FILES "${Ceres_BINARY_DIR}/CeresConfig-install.cmake" RENAME CeresConfig.cmake DESTINATION ${RELATIVE_CMAKECONFIG_INSTALL_DIR}) install(FILES "${Ceres_BINARY_DIR}/CeresConfigVersion.cmake" - "${Ceres_SOURCE_DIR}/cmake/FindGlog.cmake" DESTINATION ${RELATIVE_CMAKECONFIG_INSTALL_DIR}) +if (GLOG_FOUND AND NOT FOUND_INSTALLED_GLOG_CMAKE_CONFIGURATION) + # Version of glog detected was not built with CMake, install our glog module + # file to enable detection in CeresConfig. + install(FILES "${Ceres_SOURCE_DIR}/cmake/FindGlog.cmake" + DESTINATION ${RELATIVE_CMAKECONFIG_INSTALL_DIR}) +endif() if (PROVIDE_UNINSTALL_TARGET) # Create an uninstall target to remove all installed files. diff --git a/cmake/CeresConfig.cmake.in b/cmake/CeresConfig.cmake.in index 7ad5bedf8..81c051134 100644 --- a/cmake/CeresConfig.cmake.in +++ b/cmake/CeresConfig.cmake.in @@ -178,6 +178,13 @@ set(CERES_VERSION @CERES_VERSION@ ) include(CMakeFindDependencyMacro) find_dependency(Threads) +# As imported CMake targets are not re-exported when a dependent target is +# exported, we must invoke find_package(XXX) here to reload the definition +# of their targets. Without this, the dependency target names (e.g. +# 'gflags-shared') which will be present in the ceres target would not be +# defined, and so CMake will assume that they refer to a library name and +# fail to link correctly. + # Eigen. # Flag set during configuration and build of Ceres. set(CERES_EIGEN_VERSION @EIGEN3_VERSION_STRING@) @@ -205,42 +212,41 @@ else (EIGEN3_FOUND) "Eigen3_DIR.") endif (EIGEN3_FOUND) -# Glog. -# Flag set during configuration and build of Ceres. +# glog (and maybe gflags). +# +# Flags set during configuration and build of Ceres. set(CERES_USES_MINIGLOG @MINIGLOG@) +set(CERES_GLOG_VERSION @glog_VERSION@) +set(CERES_GLOG_WAS_BUILT_WITH_CMAKE @FOUND_INSTALLED_GLOG_CMAKE_CONFIGURATION@) + set(CERES_USES_GFLAGS @GFLAGS@) set(CERES_GFLAGS_VERSION @gflags_VERSION@) + if (CERES_USES_MINIGLOG) # Output message at standard log level (not the lower STATUS) so that # the message is output in GUI during configuration to warn user. ceres_message("-- Found Ceres compiled with miniglog substitute " "for glog, beware this will likely cause problems if glog is later linked.") else(CERES_USES_MINIGLOG) - # As imported CMake targets are not re-exported when a dependent target is - # exported, we must invoke find_package(XXX) here to reload the definition - # of their targets. Without this, the dependency target names (e.g. - # 'gflags-shared') which will be present in the ceres target would not be - # defined, and so CMake will assume that they refer to a library name and - # fail to link correctly. - - # Append the locations of glog when Ceres was built to the search path hints. - set(GLOG_WAS_BUILT_WITH_CMAKE @FOUND_INSTALLED_GLOG_CMAKE_CONFIGURATION@) - if (GLOG_WAS_BUILT_WITH_CMAKE) - set(glog_DIR "@glog_DIR@") - set(GLOG_PREFER_EXPORTED_GLOG_CMAKE_CONFIGURATION TRUE) + if (CERES_GLOG_WAS_BUILT_WITH_CMAKE) + find_package(glog ${CERES_GLOG_VERSION} CONFIG QUIET) + set(GLOG_FOUND ${glog_FOUND}) else() + # Version of glog against which Ceres was built was not built with CMake, + # use the exported glog find_package() module from Ceres to find it again. + # Append the locations of glog when Ceres was built to the search path hints. list(APPEND GLOG_INCLUDE_DIR_HINTS "@GLOG_INCLUDE_DIR@") get_filename_component(CERES_BUILD_GLOG_LIBRARY_DIR "@GLOG_LIBRARY@" PATH) list(APPEND GLOG_LIBRARY_DIR_HINTS ${CERES_BUILD_GLOG_LIBRARY_DIR}) + + # Search quietly s/t we control the timing of the error message if not found. + find_package(Glog QUIET) endif() - # Search quietly s/t we control the timing of the error message if not found. - find_package(Glog QUIET) + if (GLOG_FOUND) ceres_message(STATUS "Found required Ceres dependency: glog") else() - ceres_report_not_found("Missing required Ceres " - "dependency: glog. Searched using GLOG_INCLUDE_DIR_HINTS: " - "${GLOG_INCLUDE_DIR_HINTS} and glog_DIR: ${glog_DIR}.") + ceres_report_not_found("Missing required Ceres dependency: glog.") endif() # gflags is only a public dependency of Ceres via glog, thus is not required