CMakeLists.txt 3.73 KB
Newer Older
1
set(OPENCV_MODULE_IS_PART_OF_WORLD FALSE)
2 3 4 5
set(the_description "SFM algorithms")


### LIBMV LIGHT EXTERNAL DEPENDENCIES ###
6
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
7
find_package(Gflags QUIET)
8
find_package(Ceres QUIET)
9
if(NOT Ceres_FOUND)  # Looks like Ceres find glog on the own, so separate search isn't necessary
10
  find_package(Glog QUIET)
Marc-Stefan Cassola's avatar
Marc-Stefan Cassola committed
11
endif()
edgarriba's avatar
edgarriba committed
12

13
if((gflags_FOUND OR GFLAGS_FOUND OR GFLAGS_INCLUDE_DIRS) AND (glog_FOUND OR GLOG_FOUND OR GLOG_INCLUDE_DIRS))
14 15
  set(_fname "${CMAKE_CURRENT_BINARY_DIR}/test_sfm_deps.cpp")
  file(WRITE "${_fname}" "#include <glog/logging.h>\n#include <gflags/gflags.h>\nint main() { (void)(0); return 0; }\n")
16
  try_compile(SFM_DEPS_OK "${CMAKE_BINARY_DIR}" "${_fname}"
17 18 19 20 21 22
      CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:STRING=${GLOG_INCLUDE_DIRS};${GFLAGS_INCLUDE_DIRS}"
      LINK_LIBRARIES ${GLOG_LIBRARIES} ${GFLAGS_LIBRARIES}
      OUTPUT_VARIABLE OUTPUT
  )
  file(REMOVE "${_fname}")
  message(STATUS "Checking SFM deps... ${SFM_DEPS_OK}")
23 24
else()
  set(SFM_DEPS_OK FALSE)
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
endif()

if(NOT HAVE_EIGEN OR NOT SFM_DEPS_OK)
  set(DISABLE_MSG "Module opencv_sfm disabled because the following dependencies are not found:")
  if(NOT HAVE_EIGEN)
    set(DISABLE_MSG "${DISABLE_MSG} Eigen")
  endif()
  if(NOT SFM_DEPS_OK)
    set(DISABLE_MSG "${DISABLE_MSG} Glog/Gflags")
  endif()
  message(STATUS ${DISABLE_MSG})
  ocv_module_disable(sfm)
endif()


### LIBMV LIGHT DEFINITIONS ###

set(LIBMV_LIGHT_INCLUDES
43
  "${CMAKE_CURRENT_LIST_DIR}/src/libmv_light"
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
  "${OpenCV_SOURCE_DIR}/include/opencv"
  "${GLOG_INCLUDE_DIRS}"
  "${GFLAGS_INCLUDE_DIRS}"
)

set(LIBMV_LIGHT_LIBS
  correspondence
  multiview
  numeric
  ${GLOG_LIBRARIES}
  ${GFLAGS_LIBRARIES}
)

if(Ceres_FOUND)
  add_definitions("-DCERES_FOUND=1")
  list(APPEND LIBMV_LIGHT_LIBS simple_pipeline)
60
  list(APPEND LIBMV_LIGHT_INCLUDES "${CERES_INCLUDE_DIR}")
61 62 63 64 65
else()
  add_definitions("-DCERES_FOUND=0")
  message(STATUS "CERES support is disabled. Ceres Solver for reconstruction API is required.")
endif()

66 67 68 69 70 71 72 73 74
### COMPILE WITH C++11 IF CERES WAS COMPILED WITH C++11

if(Ceres_FOUND)
  list (FIND CERES_COMPILED_COMPONENTS "C++11" _index)
  if (${_index} GREATER -1)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  endif()
endif()

75 76 77 78 79
### DEFINE OPENCV SFM MODULE DEPENDENCIES ###

### CREATE OPENCV SFM MODULE ###

ocv_add_module(sfm
edgarriba's avatar
edgarriba committed
80 81 82 83
  opencv_core
  opencv_calib3d
  opencv_features2d
  opencv_xfeatures2d
84
  opencv_imgcodecs
edgarriba's avatar
edgarriba committed
85
  WRAP python
86 87 88 89
)


ocv_warnings_disable(CMAKE_CXX_FLAGS
edgarriba's avatar
edgarriba committed
90 91 92 93 94 95 96
  -Wundef
  -Wshadow
  -Wsign-compare
  -Wmissing-declarations
  -Wunused-but-set-variable
  -Wunused-parameter
  -Wunused-function
97
  -Wsuggest-override
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
)

if(UNIX)
  if(CMAKE_COMPILER_IS_GNUCXX OR CV_ICC)
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
  endif()
endif()

ocv_include_directories( ${LIBMV_LIGHT_INCLUDES} )
ocv_module_include_directories()

# source files
FILE(GLOB OPENCV_SFM_SRC src/*.cpp)

# define the header files (make the headers appear in IDEs.)
113
FILE(GLOB OPENCV_SFM_HDRS include/opencv2/sfm.hpp include/opencv2/sfm/*.hpp)
114 115 116 117 118 119 120 121 122 123 124 125 126 127

ocv_set_module_sources(HEADERS ${OPENCV_SFM_HDRS}
                       SOURCES ${OPENCV_SFM_SRC})

ocv_create_module()

# build libmv_light
if(NOT CMAKE_VERSION VERSION_LESS 2.8.11) # See ocv_target_include_directories() implementation
  if(TARGET ${the_module})
    get_target_property(__include_dirs ${the_module} INCLUDE_DIRECTORIES)
    include_directories(${__include_dirs})
  endif()
endif()
include_directories(${OCV_TARGET_INCLUDE_DIRS_${the_module}})
128
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/src/libmv_light" "${CMAKE_CURRENT_BINARY_DIR}/src/libmv")
129 130 131 132 133 134 135 136 137 138 139 140 141 142

ocv_target_link_libraries(${the_module} ${LIBMV_LIGHT_LIBS})


### CREATE OPENCV SFM TESTS ###

ocv_add_accuracy_tests()


### CREATE OPENCV SFM SAMPLES ###

if(Ceres_FOUND)
  ocv_add_samples(opencv_viz)
endif ()