Autodetect gflags namespace.
- At version 2.1, gflags changed from using the google namespace, to
using gflags by default. However, it can be configured at build time
to be something else (which would be google for legacy compatibility
unless you were evil).
- Ceres previously assumed that gflags was in the google namespace.
- Now, FindGFlags.cmake extracts the namespace when gflags.h is found
and saves it in GFLAGS_NAMESPACE.
- When building the tests and examples that require gflags,
CERES_GFLAGS_NAMESPACE is defined to be the detected namespace, and
all tests/examples now use CERES_GFLAGS_NAMESPACE:: instead of
google:: when calling gflags functions.
Change-Id: Ia333df7a7e2f08ba9f26bbd339c3a785b88f04c4
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index e26dc9c..62df0c0 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -70,6 +70,11 @@
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})
diff --git a/examples/bundle_adjuster.cc b/examples/bundle_adjuster.cc
index 7787d93..e44ab78 100644
--- a/examples/bundle_adjuster.cc
+++ b/examples/bundle_adjuster.cc
@@ -333,7 +333,7 @@
} // namespace ceres
int main(int argc, char** argv) {
- google::ParseCommandLineFlags(&argc, &argv, true);
+ CERES_GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true);
google::InitGoogleLogging(argv[0]);
if (FLAGS_input.empty()) {
LOG(ERROR) << "Usage: bundle_adjustment_example --input=bal_problem";
diff --git a/examples/circle_fit.cc b/examples/circle_fit.cc
index 0763806..50bba74 100644
--- a/examples/circle_fit.cc
+++ b/examples/circle_fit.cc
@@ -107,7 +107,7 @@
};
int main(int argc, char** argv) {
- google::ParseCommandLineFlags(&argc, &argv, true);
+ CERES_GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true);
google::InitGoogleLogging(argv[0]);
double x, y, r;
diff --git a/examples/denoising.cc b/examples/denoising.cc
index bfd8118..73ac476 100644
--- a/examples/denoising.cc
+++ b/examples/denoising.cc
@@ -176,8 +176,8 @@
usage("This program denoises an image using Ceres. Sample usage:\n");
usage += argv[0];
usage += " --input=<noisy image PGM file> --foe_file=<FoE file name>";
- google::SetUsageMessage(usage);
- google::ParseCommandLineFlags(&argc, &argv, true);
+ CERES_GFLAGS_NAMESPACE::SetUsageMessage(usage);
+ CERES_GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true);
google::InitGoogleLogging(argv[0]);
if (FLAGS_input.empty()) {
diff --git a/examples/libmv_bundle_adjuster.cc b/examples/libmv_bundle_adjuster.cc
index 4b01202..6135c7f 100644
--- a/examples/libmv_bundle_adjuster.cc
+++ b/examples/libmv_bundle_adjuster.cc
@@ -779,7 +779,7 @@
} // namespace
int main(int argc, char **argv) {
- google::ParseCommandLineFlags(&argc, &argv, true);
+ CERES_GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true);
google::InitGoogleLogging(argv[0]);
if (FLAGS_input.empty()) {
diff --git a/examples/more_garbow_hillstrom.cc b/examples/more_garbow_hillstrom.cc
index d98e57c..471eed4 100644
--- a/examples/more_garbow_hillstrom.cc
+++ b/examples/more_garbow_hillstrom.cc
@@ -337,7 +337,7 @@
} // namespace ceres
int main(int argc, char** argv) {
- google::ParseCommandLineFlags(&argc, &argv, true);
+ CERES_GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true);
google::InitGoogleLogging(argv[0]);
using ceres::examples::UnconstrainedSolve;
diff --git a/examples/nist.cc b/examples/nist.cc
index 607561a..8c91a29 100644
--- a/examples/nist.cc
+++ b/examples/nist.cc
@@ -566,7 +566,7 @@
} // namespace ceres
int main(int argc, char** argv) {
- google::ParseCommandLineFlags(&argc, &argv, true);
+ CERES_GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true);
google::InitGoogleLogging(argv[0]);
ceres::examples::SolveNISTProblems();
return 0;
diff --git a/examples/powell.cc b/examples/powell.cc
index c0cba02..1c2e857 100644
--- a/examples/powell.cc
+++ b/examples/powell.cc
@@ -99,7 +99,7 @@
"Minimizer type to use, choices are: line_search & trust_region");
int main(int argc, char** argv) {
- google::ParseCommandLineFlags(&argc, &argv, true);
+ CERES_GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true);
google::InitGoogleLogging(argv[0]);
double x1 = 3.0;
diff --git a/examples/robot_pose_mle.cc b/examples/robot_pose_mle.cc
index e1a1dd0..13574f1 100644
--- a/examples/robot_pose_mle.cc
+++ b/examples/robot_pose_mle.cc
@@ -271,7 +271,7 @@
int main(int argc, char** argv) {
google::InitGoogleLogging(argv[0]);
- google::ParseCommandLineFlags(&argc, &argv, true);
+ CERES_GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true);
// Make sure that the arguments parsed are all positive.
CHECK_GT(FLAGS_corridor_length, 0.0);
CHECK_GT(FLAGS_pose_separation, 0.0);