Skip to content

Commit 752e008

Browse files
YanNounfacebook-github-bot
authored andcommitted
Remove build warnings (#1094)
Summary: This PR removes all the annoying build warnings that we had by : - Setting CMake policy - Add C++ warning ignores in third-party libraries only, since we're very unlikely to touch this code ever again - Fix the actual warnings in the rest of OpenSfM code Pull Request resolved: #1094 Test Plan: Imported from GitHub, without a `Test Plan:` line. Rollback Plan: Reviewed By: DodgySpaniard Differential Revision: D77231900 Pulled By: fabianschenk fbshipit-source-id: 49f9f65393af15b2c7b925817898a82399b188e8
1 parent b7150fe commit 752e008

File tree

13 files changed

+40
-33
lines changed

13 files changed

+40
-33
lines changed

opensfm/src/CMakeLists.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ if(NOT CMAKE_BUILD_TYPE)
99
endif()
1010
set(CMAKE_MODULE_PATH ${opensfm_SOURCE_DIR}/cmake)
1111

12+
cmake_policy(SET CMP0063 NEW)
13+
# Re-activate once we can have a decent version of CMake (> 3.27)
14+
# cmake_policy(SET CMP0148 NEW)
15+
1216
if (WIN32)
1317
# Place compilation results in opensfm/ folder, not in Debug/ or Release/
1418
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE "${opensfm_SOURCE_DIR}/..")
@@ -29,8 +33,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
2933

3034
# Enable all warnings
3135
if (NOT WIN32)
32-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
33-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
36+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-sign-compare")
37+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-sign-compare")
3438
endif()
3539

3640
# For compiling VLFeat
@@ -105,6 +109,10 @@ if (OPENSFM_BUILD_TESTS)
105109
include_directories(third_party/gtest)
106110
add_definitions(-DCERES_GFLAGS_NAMESPACE=${GFLAGS_NAMESPACE})
107111

112+
# Gtest if old now and trigger these
113+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-field-initializers")
114+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-copy-with-user-provided-copy")
115+
108116
add_library(gtest
109117
third_party/gtest/gmock_gtest_all.cc
110118
third_party/gtest/gmock_main.cc)

opensfm/src/foundation/python_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <pybind11/numpy.h>
33
#include <pybind11/pybind11.h>
44

5+
#include <cstdint>
56
#include <vector>
67

78
#include "opencv2/core/core.hpp"

opensfm/src/geometry/absolute_pose.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Eigen::Matrix3d RotationMatrixAroundAxis(const double cos_theta,
1515
// Perspective-Three-Point Problem" from Ke and al.
1616
template <class IT>
1717
std::vector<Eigen::Matrix<double, 3, 4>> AbsolutePoseThreePoints(IT begin,
18-
IT end) {
18+
IT /* end */) {
1919
std::vector<Eigen::Matrix<double, 3, 4>> RTs;
2020

2121
const Eigen::Vector3d b1 = begin->first;

opensfm/src/geometry/python/pybind.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ PYBIND11_MODULE(pygeometry, m) {
282282
py::return_value_policy::copy)
283283
.def(
284284
"__deepcopy__",
285-
[](const geometry::Camera& c, const py::dict& d) { return c; },
285+
[](const geometry::Camera& c, const py::dict& /* d */) { return c; },
286286
py::return_value_policy::copy);
287287
m.def("compute_camera_mapping", geometry::ComputeCameraMapping,
288288
py::call_guard<py::gil_scoped_release>());
@@ -375,7 +375,7 @@ PYBIND11_MODULE(pygeometry, m) {
375375
py::return_value_policy::copy)
376376
.def(
377377
"__deepcopy__",
378-
[](const geometry::Pose& p, const py::dict& d) { return p; },
378+
[](const geometry::Pose& p, const py::dict& /* d */) { return p; },
379379
py::return_value_policy::copy)
380380
.def("inverse", [](const geometry::Pose& p) {
381381
geometry::Pose new_pose;

opensfm/src/geometry/transformations_functions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ struct Normalize : Functor<3, 0, 3> {
304304
}
305305
};
306306

307-
static Mat3d VectorToRotationMatrix(const Vec3d& r) {
307+
inline Mat3d VectorToRotationMatrix(const Vec3d& r) {
308308
const auto n = r.norm();
309309
if (n == 0) // avoid division by 0
310310
{
@@ -313,7 +313,7 @@ static Mat3d VectorToRotationMatrix(const Vec3d& r) {
313313
return Eigen::AngleAxisd(n, r / n).toRotationMatrix();
314314
}
315315
}
316-
static Vec3d RotationMatrixToVector(const Mat3d& R) {
316+
inline Vec3d RotationMatrixToVector(const Mat3d& R) {
317317
Eigen::AngleAxisd tmp(R);
318318
return tmp.axis() * tmp.angle();
319319
}

opensfm/src/map/shot.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ class Shot {
7171

7272
// Pose
7373
void SetPose(const geometry::Pose& pose);
74-
const geometry::Pose* const GetPose() const;
75-
geometry::Pose* const GetPose();
74+
const geometry::Pose* GetPose() const;
75+
geometry::Pose* GetPose();
7676
Mat4d GetWorldToCam() const { return GetPose()->WorldToCamera(); }
7777
Mat4d GetCamToWorld() const { return GetPose()->CameraToWorld(); }
7878

@@ -134,7 +134,7 @@ class Shot {
134134
bool operator<=(const Shot& shot) const { return id_ <= shot.id_; }
135135
bool operator>(const Shot& shot) const { return id_ > shot.id_; }
136136
bool operator>=(const Shot& shot) const { return id_ >= shot.id_; }
137-
const geometry::Camera* const GetCamera() const { return shot_camera_; }
137+
const geometry::Camera* GetCamera() const { return shot_camera_; }
138138

139139
// Camera-related
140140
Vec2d Project(const Vec3d& global_pos) const;

opensfm/src/map/src/shot.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,15 @@ geometry::Pose Shot::GetPoseInRig() const {
152152
return rig_camera_pose.Compose(pose_instance);
153153
}
154154

155-
const geometry::Pose* const Shot::GetPose() const {
155+
const geometry::Pose* Shot::GetPose() const {
156156
*pose_ = GetPoseInRig();
157157
if (IsSingleShotRig(rig_instance_, rig_camera_)) {
158158
return &rig_instance_->GetPose();
159159
}
160160
return pose_.get();
161161
}
162162

163-
geometry::Pose* const Shot::GetPose() {
163+
geometry::Pose* Shot::GetPose() {
164164
*pose_ = GetPoseInRig();
165165
if (IsSingleShotRig(rig_instance_, rig_camera_)) {
166166
return &rig_instance_->GetPose();

opensfm/src/map/test/tracks_manager_test.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ namespace {
77
class TempFile {
88
public:
99
TempFile() {
10-
char tmpname[L_tmpnam];
11-
tmpnam(tmpname);
12-
filename = std::string(tmpname);
10+
char filenameTmp[] = "/tmp/opensfm_tracks_manager_test_XXXXXX";
11+
int fd = mkstemp(filenameTmp);
12+
if (fd == -1) {
13+
std::runtime_error("Could not create temporary file");
14+
}
15+
filename = std::string(filenameTmp);
1316
}
1417

1518
~TempFile() { remove(filename.c_str()); }

opensfm/src/robust/line_model.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Line : public Model<Line, 1, 1> {
99
static const int MINIMAL_SAMPLES = 2;
1010

1111
template <class IT>
12-
static int Estimate(IT begin, IT end, Type* models) {
12+
static int Estimate(IT begin, IT /* end */, Type* models) {
1313
const auto x1 = *begin;
1414
const auto x2 = *(++begin);
1515
const auto b = (x1[0] * x2[1] - x1[1] * x2[0]) / (x1[0] - x2[0]);

opensfm/src/robust/scorer.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ class RansacScoring {
2323
RansacScoring(double threshold) : threshold_(threshold) {}
2424

2525
template <class IT, class T>
26-
ScoreInfo<T> Score(IT begin, IT end, const ScoreInfo<T>& best_score) const {
26+
ScoreInfo<T> Score(IT begin, IT end,
27+
const ScoreInfo<T>& /* best_score */) const {
2728
ScoreInfo<T> score;
2829
for (IT it = begin; it != end; ++it) {
2930
if (it->norm() < threshold_) {
@@ -62,7 +63,8 @@ class MSacScoring {
6263
MSacScoring(double threshold) : threshold_(threshold) {}
6364

6465
template <class IT, class T>
65-
ScoreInfo<T> Score(IT begin, IT end, const ScoreInfo<T>& best_score) const {
66+
ScoreInfo<T> Score(IT begin, IT end,
67+
const ScoreInfo<T>& /* best_score */) const {
6668
ScoreInfo<T> score;
6769
for (IT it = begin; it != end; ++it) {
6870
const auto v = (*it).norm();
@@ -87,7 +89,8 @@ class LMedSScoring : public MedianBasedScoring {
8789
: MedianBasedScoring(0.5), multiplier_(multiplier) {}
8890

8991
template <class IT, class T>
90-
ScoreInfo<T> Score(IT begin, IT end, const ScoreInfo<T>& best_score) const {
92+
ScoreInfo<T> Score(IT begin, IT end,
93+
const ScoreInfo<T>& /* best_score */) const {
9194
const auto median = this->ComputeMedian(begin, end);
9295
const auto mad = 1.4826 * median;
9396
const auto threshold = this->multiplier_ * mad;

0 commit comments

Comments
 (0)