Respect FIND_QUIETLY flag in cmake config file
Ensure that Ceres does not print any log messages when somebody has
used 'find_package(Ceres QUIET)' in their CMake project.
Change-Id: Id6b68859cc8a5857f3fa78f29736cb82fd5a0943
diff --git a/cmake/CeresConfig.cmake.in b/cmake/CeresConfig.cmake.in
index ced7daf..94099a9 100644
--- a/cmake/CeresConfig.cmake.in
+++ b/cmake/CeresConfig.cmake.in
@@ -91,6 +91,18 @@
return()
endmacro(CERES_REPORT_NOT_FOUND)
+
+# ceres_message([mode] "message text")
+#
+# Wraps the standard cmake 'message' command, but suppresses output
+# if the QUIET flag was passed to the find_package(Ceres ...) call.
+function(ceres_message)
+ if (NOT Ceres_FIND_QUIETLY)
+ message(${ARGN})
+ endif()
+endfunction()
+
+
# ceres_pretty_print_cmake_list( OUTPUT_VAR [item1 [item2 ... ]] )
#
# Sets ${OUTPUT_VAR} in the caller's scope to a human-readable string
@@ -185,7 +197,7 @@
"Wikipedia article http://en.wikipedia.org/wiki/One_Definition_Rule "
"for more details")
endif ()
- message(STATUS "Found required Ceres dependency: "
+ ceres_message(STATUS "Found required Ceres dependency: "
"Eigen version ${CERES_EIGEN_VERSION} in ${EIGEN3_INCLUDE_DIRS}")
else (EIGEN3_FOUND)
ceres_report_not_found("Missing required Ceres "
@@ -201,7 +213,7 @@
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.
- message("-- Found Ceres compiled with miniglog substitute "
+ 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
@@ -224,7 +236,7 @@
# Search quietly s/t we control the timing of the error message if not found.
find_package(Glog QUIET)
if (GLOG_FOUND)
- message(STATUS "Found required Ceres dependency: glog")
+ ceres_message(STATUS "Found required Ceres dependency: glog")
else()
ceres_report_not_found("Missing required Ceres "
"dependency: glog. Searched using GLOG_INCLUDE_DIR_HINTS: "
@@ -237,7 +249,7 @@
# Search quietly s/t we control the timing of the error message if not found.
find_package(gflags ${CERES_GFLAGS_VERSION} CONFIG QUIET)
if (gflags_FOUND)
- message(STATUS "Found required Ceres dependency: gflags")
+ ceres_message(STATUS "Found required Ceres dependency: gflags")
else()
ceres_report_not_found("Missing required Ceres "
"dependency: gflags.")
@@ -301,7 +313,7 @@
# As we use CERES_REPORT_NOT_FOUND() to abort, if we reach this point we have
# found Ceres and all required dependencies.
-message(STATUS "Found " ${CERES_DETECTED_VERSION_STRING})
+ceres_message(STATUS "Found " ${CERES_DETECTED_VERSION_STRING})
# Set CERES_FOUND to be equivalent to Ceres_FOUND, which is set to
# TRUE by FindPackage() if this file is found and run, and after which
diff --git a/cmake/FindGlog.cmake b/cmake/FindGlog.cmake
index 4fc84da..1a7b6c0 100644
--- a/cmake/FindGlog.cmake
+++ b/cmake/FindGlog.cmake
@@ -109,6 +109,16 @@
return()
endmacro(GLOG_REPORT_NOT_FOUND)
+# glog_message([mode] "message text")
+#
+# Wraps the standard cmake 'message' command, but suppresses output
+# if the QUIET flag was passed to the find_package(Glog ...) call.
+function(GLOG_MESSAGE)
+ if (NOT Glog_FIND_QUIETLY)
+ message(${ARGN})
+ endif()
+endfunction()
+
# Protect against any alternative find_package scripts for this library having
# been called previously (in a client project) which set GLOG_FOUND, but not
# the other variables we require / set here which could cause the search logic
@@ -123,8 +133,8 @@
if (NOT DEFINED GLOG_PREFER_EXPORTED_GLOG_CMAKE_CONFIGURATION
AND NOT GLOG_INCLUDE_DIR_HINTS
AND NOT GLOG_LIBRARY_DIR_HINTS)
- message(STATUS "No preference for use of exported glog CMake configuration "
- "set, and no hints for include/library directories provided. "
+ glog_message(STATUS "No preference for use of exported glog CMake "
+ "configuration set, and no hints for include/library directories provided. "
"Defaulting to preferring an installed/exported glog CMake configuration "
"if available.")
set(GLOG_PREFER_EXPORTED_GLOG_CMAKE_CONFIGURATION TRUE)
@@ -144,7 +154,7 @@
execute_process(COMMAND ${HOMEBREW_EXECUTABLE} --prefix
OUTPUT_VARIABLE HOMEBREW_INSTALL_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE)
- message(STATUS "Detected Homebrew with install prefix: "
+ glog_message(STATUS "Detected Homebrew with install prefix: "
"${HOMEBREW_INSTALL_PREFIX}, adding to CMake search paths.")
list(APPEND GLOG_INCLUDE_DIR_HINTS "${HOMEBREW_INSTALL_PREFIX}/include")
list(APPEND GLOG_LIBRARY_DIR_HINTS "${HOMEBREW_INSTALL_PREFIX}/lib")
@@ -202,11 +212,11 @@
NO_CMAKE_PACKAGE_REGISTRY
NO_CMAKE_BUILDS_PATH)
if (glog_FOUND)
- message(STATUS "Found installed version of glog: ${glog_DIR}")
+ glog_message(STATUS "Found installed version of glog: ${glog_DIR}")
else()
# Failed to find an installed version of glog, repeat search allowing
# exported build directories.
- message(STATUS "Failed to find installed glog CMake configuration, "
+ glog_message(STATUS "Failed to find installed glog CMake configuration, "
"searching for glog build directories exported with CMake.")
# Again pass NO_CMAKE_BUILDS_PATH, as we know that glog is exported and
# do not want to treat projects built with the CMake GUI preferentially.
@@ -215,21 +225,22 @@
NO_MODULE
NO_CMAKE_BUILDS_PATH)
if (glog_FOUND)
- message(STATUS "Found exported glog build directory: ${glog_DIR}")
+ glog_message(STATUS "Found exported glog build directory: ${glog_DIR}")
endif(glog_FOUND)
endif(glog_FOUND)
set(FOUND_INSTALLED_GLOG_CMAKE_CONFIGURATION ${glog_FOUND})
if (FOUND_INSTALLED_GLOG_CMAKE_CONFIGURATION)
- message(STATUS "Detected glog version: ${glog_VERSION}")
+ glog_message(STATUS "Detected glog version: ${glog_VERSION}")
set(GLOG_FOUND ${glog_FOUND})
# glog wraps the include directories into the exported glog::glog target.
set(GLOG_INCLUDE_DIR "")
set(GLOG_LIBRARY glog::glog)
else (FOUND_INSTALLED_GLOG_CMAKE_CONFIGURATION)
- message(STATUS "Failed to find an installed/exported CMake configuration "
- "for glog, will perform search for installed glog components.")
+ glog_message(STATUS "Failed to find an installed/exported CMake "
+ "configuration for glog, will perform search for installed glog "
+ "components.")
endif (FOUND_INSTALLED_GLOG_CMAKE_CONFIGURATION)
endif(GLOG_PREFER_EXPORTED_GLOG_CMAKE_CONFIGURATION)