OpenSfM
OpenSfM copied to clipboard
Building on macos required cmake changes due to missing header files
When trying to build with python setup.py build
I ran into numerous errors due to not found headers
. However the dependencies were already present and installed using brew, e.g. brew install gflags opencv ..
.
- python 3.7.7
- cmake version 3.17.2
- macos 10.15.4.
Example error:
[ 29%] Building C object third_party/vlfeat/CMakeFiles/vl.dir/vl/kmeans.c.o
/OpenSfM/opensfm/src/third_party/gtest/gmock_main.cc:33:10: fatal error: 'gflags/gflags.h' file not found
#include "gflags/gflags.h"
^~~~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [CMakeFiles/gtest.dir/third_party/gtest/gmock_main.cc.o] Error 1
I had to add include_directories(${GLOG_INCLUDE_DIRS} ${GFLAGS_INCLUDE_DIRS})
after the find_packages
command to fix the build for my setup.
The complete set of changes which I made.
diff --git opensfm/src/CMakeLists.txt opensfm/src/CMakeLists.txt
index 1d5d881..45eb89e 100644
--- opensfm/src/CMakeLists.txt
+++ opensfm/src/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 3.0)
+LINK_DIRECTORIES(/usr/local/Cellar)
project(opensfm C CXX)
@@ -39,6 +39,9 @@ find_package(Eigen REQUIRED)
find_package(Ceres REQUIRED)
find_package(Gflags REQUIRED)
find_package(Glog REQUIRED)
+find_package(gtest REQUIRED)
+
+include_directories(${GLOG_INCLUDE_DIRS} ${GFLAGS_INCLUDE_DIRS})
find_package(OpenCV)
# OpenCV's OpenCVConfig will enforce imgcodecs for < 3.0
I'm not familiar with cmake and the particulars of its build system but the include_directories
command was found via this stackoverflow answer. Using it and other "whack-a-mole" modifications to the CMakeLists.txt allowed a successful build
I spent hours looking for a solution until I saw this issue!
Your diff fixed the build process on macOS Catalina with no problems.