CMakeLists.txt 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. set(OPENCV_MODULE_IS_PART_OF_WORLD FALSE)
  2. set(the_description "SFM algorithms")
  3. ### LIBMV LIGHT EXTERNAL DEPENDENCIES ###
  4. find_package(Ceres QUIET)
  5. if(NOT Gflags_FOUND) # Ceres find gflags on the own, so separate search isn't necessary
  6. find_package(Gflags QUIET)
  7. endif()
  8. if(NOT Glog_FOUND) # Ceres find glog on the own, so separate search isn't necessary
  9. find_package(Glog QUIET)
  10. endif()
  11. if(NOT Gflags_FOUND OR NOT Glog_FOUND)
  12. # try local search scripts
  13. list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
  14. if(NOT Gflags_FOUND)
  15. find_package(Gflags QUIET)
  16. endif()
  17. if(NOT Glog_FOUND)
  18. find_package(Glog QUIET)
  19. endif()
  20. endif()
  21. if(NOT DEFINED GFLAGS_INCLUDE_DIRS AND DEFINED GFLAGS_INCLUDE_DIR)
  22. set(GFLAGS_INCLUDE_DIRS "${GFLAGS_INCLUDE_DIR}")
  23. endif()
  24. if(NOT GFLAGS_LIBRARIES AND TARGET gflags::gflags)
  25. set(GFLAGS_LIBRARIES gflags::gflags)
  26. endif()
  27. if(NOT DEFINED GLOG_INCLUDE_DIRS AND DEFINED GLOG_INCLUDE_DIR)
  28. set(GLOG_INCLUDE_DIRS "${GLOG_INCLUDE_DIR}")
  29. endif()
  30. if(NOT GLOG_LIBRARIES AND TARGET glog::glog)
  31. set(GLOG_LIBRARIES glog::glog)
  32. endif()
  33. if((gflags_FOUND OR Gflags_FOUND OR GFLAGS_FOUND OR GFLAGS_INCLUDE_DIRS) AND (glog_FOUND OR Glog_FOUND OR GLOG_FOUND OR GLOG_INCLUDE_DIRS))
  34. set(__cache_key "${GLOG_INCLUDE_DIRS} ~ ${GFLAGS_INCLUDE_DIRS} ~ ${GLOG_LIBRARIES} ~ ${GFLAGS_LIBRARIES}")
  35. if(NOT DEFINED SFM_GLOG_GFLAGS_TEST_CACHE_KEY OR NOT (SFM_GLOG_GFLAGS_TEST_CACHE_KEY STREQUAL __cache_key))
  36. set(__fname "${CMAKE_CURRENT_LIST_DIR}/cmake/checks/check_glog_gflags.cpp")
  37. try_compile(
  38. SFM_GLOG_GFLAGS_TEST "${CMAKE_BINARY_DIR}" "${__fname}"
  39. CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:STRING=${GLOG_INCLUDE_DIRS};${GFLAGS_INCLUDE_DIRS}"
  40. LINK_LIBRARIES ${GLOG_LIBRARIES} ${GFLAGS_LIBRARIES}
  41. OUTPUT_VARIABLE __output
  42. )
  43. if(NOT SFM_GLOG_GFLAGS_TEST)
  44. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  45. "Failed compilation check: ${__fname}\n"
  46. "${__output}\n\n"
  47. )
  48. endif()
  49. set(SFM_GLOG_GFLAGS_TEST "${SFM_GLOG_GFLAGS_TEST}" CACHE INTERNAL "")
  50. set(SFM_GLOG_GFLAGS_TEST_CACHE_KEY "${__cache_key}" CACHE INTERNAL "")
  51. message(STATUS "Checking SFM glog/gflags deps... ${SFM_GLOG_GFLAGS_TEST}")
  52. endif()
  53. unset(__cache_key)
  54. set(SFM_DEPS_OK "${SFM_GLOG_GFLAGS_TEST}")
  55. else()
  56. set(SFM_DEPS_OK FALSE)
  57. endif()
  58. if(NOT HAVE_EIGEN OR NOT SFM_DEPS_OK)
  59. set(DISABLE_MSG "Module opencv_sfm disabled because the following dependencies are not found:")
  60. if(NOT HAVE_EIGEN)
  61. set(DISABLE_MSG "${DISABLE_MSG} Eigen")
  62. endif()
  63. if(NOT SFM_DEPS_OK)
  64. set(DISABLE_MSG "${DISABLE_MSG} Glog/Gflags")
  65. endif()
  66. message(STATUS ${DISABLE_MSG})
  67. ocv_module_disable(sfm)
  68. endif()
  69. ### LIBMV LIGHT DEFINITIONS ###
  70. set(LIBMV_LIGHT_INCLUDES
  71. "${CMAKE_CURRENT_LIST_DIR}/src/libmv_light"
  72. "${OpenCV_SOURCE_DIR}/include/opencv"
  73. "${GLOG_INCLUDE_DIRS}"
  74. "${GFLAGS_INCLUDE_DIRS}"
  75. )
  76. set(LIBMV_LIGHT_LIBS
  77. correspondence
  78. multiview
  79. numeric
  80. ${GLOG_LIBRARIES}
  81. ${GFLAGS_LIBRARIES}
  82. )
  83. if(Ceres_FOUND)
  84. add_definitions("-DCERES_FOUND=1")
  85. list(APPEND LIBMV_LIGHT_LIBS simple_pipeline)
  86. if(Ceres_VERSION VERSION_LESS 2.0.0)
  87. list(APPEND LIBMV_LIGHT_INCLUDES "${CERES_INCLUDE_DIRS}")
  88. endif()
  89. else()
  90. add_definitions("-DCERES_FOUND=0")
  91. message(STATUS "CERES support is disabled. Ceres Solver for reconstruction API is required.")
  92. endif()
  93. ### CREATE OPENCV SFM MODULE ###
  94. ocv_add_module(sfm
  95. opencv_core
  96. opencv_calib3d
  97. opencv_features2d
  98. opencv_xfeatures2d
  99. opencv_imgcodecs
  100. WRAP python
  101. )
  102. add_definitions(/DGLOG_NO_ABBREVIATED_SEVERITIES) # avoid ERROR macro conflict in glog (ceres dependency)
  103. if(WIN32)
  104. # Avoid error due to min/max being already defined as a macro
  105. add_definitions(-DNOMINMAX)
  106. endif(WIN32)
  107. ocv_warnings_disable(CMAKE_CXX_FLAGS
  108. -Wundef
  109. -Wshadow
  110. -Wsign-compare
  111. -Wmissing-declarations
  112. -Wunused-but-set-variable
  113. -Wunused-parameter
  114. -Wunused-function
  115. -Wsuggest-override
  116. )
  117. ocv_include_directories( ${LIBMV_LIGHT_INCLUDES} )
  118. ocv_module_include_directories()
  119. # source files
  120. FILE(GLOB OPENCV_SFM_SRC src/*.cpp)
  121. # define the header files (make the headers appear in IDEs.)
  122. FILE(GLOB OPENCV_SFM_HDRS include/opencv2/sfm.hpp include/opencv2/sfm/*.hpp)
  123. ocv_set_module_sources(HEADERS ${OPENCV_SFM_HDRS}
  124. SOURCES ${OPENCV_SFM_SRC})
  125. ocv_create_module()
  126. ### BUILD libmv_light ###
  127. if(NOT CMAKE_VERSION VERSION_LESS 2.8.11) # See ocv_target_include_directories() implementation
  128. if(TARGET ${the_module})
  129. get_target_property(__include_dirs ${the_module} INCLUDE_DIRECTORIES)
  130. include_directories(${__include_dirs})
  131. endif()
  132. endif()
  133. #include_directories(${OCV_TARGET_INCLUDE_DIRS_${the_module}})
  134. add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/src/libmv_light" "${CMAKE_CURRENT_BINARY_DIR}/src/libmv")
  135. ocv_target_link_libraries(${the_module} ${LIBMV_LIGHT_LIBS})
  136. ### CREATE OPENCV SFM TESTS ###
  137. ocv_add_accuracy_tests()
  138. if(Ceres_FOUND AND TARGET opencv_test_sfm)
  139. ocv_target_link_libraries(opencv_test_sfm ${CERES_LIBRARIES})
  140. endif ()
  141. ### CREATE OPENCV SFM SAMPLES ###
  142. if(Ceres_FOUND)
  143. ocv_add_samples(opencv_viz)
  144. endif ()