Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Flann and Cereal from external dependencies #167

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 80 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -218,24 +218,71 @@ include_directories(
# as system headers.
include_directories(SYSTEM ${EIGEN_INCLUDE_DIRS})


set(THEIA_USE_EXTERNAL_CEREAL OFF CACHE BOOL "Use a system Cereal library")
set(THEIA_USE_EXTERNAL_FLANN OFF CACHE BOOL "Use a system Flann library")

# build Third party libraries included in distro.
add_subdirectory(libraries)
include_directories(
libraries
libraries/spectra
${akaze_SOURCE_DIR}
${akaze_INCLUDE_DIR}
${cereal_SOURCE_DIR}
${cereal_SOURCE_DIR}/include
${flann_SOURCE_DIR}
${flann_SOURCE_DIR}/src/cpp
${gtest_SOURCE_DIR}/include
${gtest_SOURCE_DIR}
${optimo_SOURCE_DIR}
${statx_SOURCE_DIR}
${stlplus3_SOURCE_DIR}
${vlfeat_SOURCE_DIR}
${visual_sfm_SOURCE_DIR})
if (${BUILD_TESTING})
add_subdirectory(libraries/gtest)
include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
endif (${BUILD_TESTING})

# AKAZE feature extractor.
add_subdirectory(libraries/akaze)
include_directories(${akaze_SOURCE_DIR} ${akaze_INCLUDE_DIR})

# Cereal for portable IO.
if(NOT THEIA_USE_EXTERNAL_CEREAL)
add_subdirectory(libraries/cereal)

include_directories(${cereal_SOURCE_DIR} ${cereal_SOURCE_DIR}/include)
set(THEIA_INTERNAL_CEREAL_LIB ${THEIA_INTERNAL_LIB_PREFIX}/cereal ${THEIA_INTERNAL_LIB_PREFIX}/cereal/include)
else()
find_package(cereal REQUIRED)

set(_THEIA_CEREAL_LIBRARIES cereal)
endif()

# Flann for fast approximate nearest neighbor searches.
if(NOT THEIA_USE_EXTERNAL_FLANN)
add_subdirectory(libraries/flann)

include_directories(${flann_SOURCE_DIR} ${flann_SOURCE_DIR}/src/cpp)
set(_THEIA_FLANN_LIBRARIES flann_cpp)
set(THEIA_INTERNAL_FLANN_LIB ${THEIA_INTERNAL_LIB_PREFIX}/flann)
else()
find_package(Flann REQUIRED)

include_directories(${FLANN_INCLUDE_DIR})
set(_THEIA_FLANN_LIBRARIES ${FLANN_LIBRARY})
endif()

# Add Optimo.
add_subdirectory(libraries/optimo)
include_directories(${optimo_SOURCE_DIR})

# Add Spectra.
include_directories(libraries/spectra)

# Add Statx.
add_subdirectory(libraries/statx)
include_directories(${statx_SOURCE_DIR})

# STLPlus for filepath tools.
add_subdirectory(libraries/stlplus3)
include_directories(${stlplus3_SOURCE_DIR})

# Add VLFeat.
add_subdirectory(libraries/vlfeat)
include_directories(${vlfeat_SOURCE_DIR})

# Add VisualSfM files.
add_subdirectory(libraries/visual_sfm)
include_directories(${visual_sfm_SOURCE_DIR})

include_directories(libraries)


list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
include(OptimizeTheiaCompilerFlags)
Expand All @@ -260,7 +307,19 @@ install(FILES ${THEIA_HDRS} DESTINATION include/theia)
file(GLOB_RECURSE THEIA_INTERNAL_HDRS ${CMAKE_SOURCE_DIR}/src/theia/*.h)
install(DIRECTORY src/theia/ DESTINATION include/theia FILES_MATCHING PATTERN "*.h")

install(DIRECTORY libraries/ DESTINATION include/theia/libraries FILES_MATCHING PATTERN "*.h*")
install(DIRECTORY libraries/akaze/ DESTINATION include/theia/libraries/akaze FILES_MATCHING PATTERN "*.h*")
if(NOT THEIA_USE_EXTERNAL_CEREAL)
install(DIRECTORY libraries/cereal/ DESTINATION include/theia/libraries/cereal FILES_MATCHING PATTERN "*.h*")
endif()
if(NOT THEIA_USE_EXTERNAL_FLANN)
install(DIRECTORY libraries/flann/ DESTINATION include/theia/libraries/flann FILES_MATCHING PATTERN "*.h*")
endif()
install(DIRECTORY libraries/optimo/ DESTINATION include/theia/libraries/optimo FILES_MATCHING PATTERN "*.h*")
install(DIRECTORY libraries/spectra/ DESTINATION include/theia/libraries/spectra FILES_MATCHING PATTERN "*.h*")
install(DIRECTORY libraries/statx/ DESTINATION include/theia/libraries/statx FILES_MATCHING PATTERN "*.h*")
install(DIRECTORY libraries/stlplus3/ DESTINATION include/theia/libraries/stlplus3 FILES_MATCHING PATTERN "*.h*")
install(DIRECTORY libraries/visual_sfm/ DESTINATION include/theia/libraries/visual_sfm FILES_MATCHING PATTERN "*.h*")
install(DIRECTORY libraries/vlfeat/ DESTINATION include/theia/libraries/vlfeat FILES_MATCHING PATTERN "*.h*")

# Add an uninstall target to remove all installed files.
configure_file("${CMAKE_SOURCE_DIR}/cmake/uninstall.cmake.in"
Expand Down Expand Up @@ -320,8 +379,9 @@ configure_file("${CMAKE_SOURCE_DIR}/cmake/TheiaConfigVersion.cmake.in"
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/TheiaConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/TheiaConfigVersion.cmake"
"${CMAKE_SOURCE_DIR}/cmake/FindEigen.cmake"
"${CMAKE_SOURCE_DIR}/cmake/FindGlog.cmake"
"${CMAKE_SOURCE_DIR}/cmake/FindFlann.cmake"
"${CMAKE_SOURCE_DIR}/cmake/FindGflags.cmake"
"${CMAKE_SOURCE_DIR}/cmake/FindOpenImageIO.cmake"
"${CMAKE_SOURCE_DIR}/cmake/FindGlog.cmake"
"${CMAKE_SOURCE_DIR}/cmake/FindOpenImageIO.cmake"
"${CMAKE_SOURCE_DIR}/cmake/FindSuiteSparse.cmake"
DESTINATION ${CMAKECONFIG_INSTALL_DIR})
63 changes: 63 additions & 0 deletions cmake/FindFlann.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
###############################################################################
# Find FLANN
#
# This sets the following variables:
# FLANN_FOUND - True if FLANN was found.
# FLANN_INCLUDE_DIRS - Directories containing the FLANN include files.
# FLANN_LIBRARIES - Libraries needed to use FLANN.
# FLANN_DEFINITIONS - Compiler flags for FLANN.
# If FLANN_USE_STATIC is specified and then look for static libraries ONLY else
# look for shared ones

if(FLANN_USE_STATIC)
set(FLANN_RELEASE_NAME flann_cpp_s flann_cpp)
set(FLANN_DEBUG_NAME flann_cpp_s-gd flann_cpp-gd)
else(FLANN_USE_STATIC)
set(FLANN_RELEASE_NAME flann_cpp)
set(FLANN_DEBUG_NAME flann_cpp-gd)
endif(FLANN_USE_STATIC)

find_package(PkgConfig QUIET)
if (FLANN_FIND_VERSION)
pkg_check_modules(PC_FLANN flann>=${FLANN_FIND_VERSION})
else(FLANN_FIND_VERSION)
pkg_check_modules(PC_FLANN flann)
endif(FLANN_FIND_VERSION)

set(FLANN_DEFINITIONS ${PC_FLANN_CFLAGS_OTHER})

find_path(FLANN_INCLUDE_DIR flann/flann.hpp
HINTS ${PC_FLANN_INCLUDEDIR} ${PC_FLANN_INCLUDE_DIRS} "${FLANN_ROOT}" "$ENV{FLANN_ROOT}"
PATHS "$ENV{PROGRAMFILES}/Flann" "$ENV{PROGRAMW6432}/Flann"
PATH_SUFFIXES include)

find_library(FLANN_LIBRARY
NAMES ${FLANN_RELEASE_NAME}
HINTS ${PC_FLANN_LIBDIR} ${PC_FLANN_LIBRARY_DIRS} "${FLANN_ROOT}" "$ENV{FLANN_ROOT}"
PATHS "$ENV{PROGRAMFILES}/Flann" "$ENV{PROGRAMW6432}/Flann"
PATH_SUFFIXES lib)

find_library(FLANN_LIBRARY_DEBUG
NAMES ${FLANN_DEBUG_NAME} ${FLANN_RELEASE_NAME}
HINTS ${PC_FLANN_LIBDIR} ${PC_FLANN_LIBRARY_DIRS} "${FLANN_ROOT}" "$ENV{FLANN_ROOT}"
PATHS "$ENV{PROGRAMFILES}/Flann" "$ENV{PROGRAMW6432}/Flann"
PATH_SUFFIXES lib)

if(NOT FLANN_LIBRARY_DEBUG)
set(FLANN_LIBRARY_DEBUG ${FLANN_LIBRARY})
endif(NOT FLANN_LIBRARY_DEBUG)

set(FLANN_INCLUDE_DIRS ${FLANN_INCLUDE_DIR})
set(FLANN_LIBRARIES optimized ${FLANN_LIBRARY} debug ${FLANN_LIBRARY_DEBUG})

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(FLANN DEFAULT_MSG FLANN_LIBRARY FLANN_INCLUDE_DIR)

mark_as_advanced(FLANN_LIBRARY FLANN_LIBRARY_DEBUG FLANN_INCLUDE_DIR)

if(FLANN_FOUND)
message(STATUS "Flann found (include: ${FLANN_INCLUDE_DIRS}, lib: ${FLANN_LIBRARIES})")
if(FLANN_USE_STATIC)
add_definitions(-DFLANN_STATIC)
endif(FLANN_USE_STATIC)
endif(FLANN_FOUND)
38 changes: 32 additions & 6 deletions cmake/TheiaConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ else (GFLAGS_FOUND)
endif (GFLAGS_FOUND)
list(APPEND THEIA_INCLUDE_DIRS ${GFLAGS_INCLUDE_DIRS})

# OpenImageIO
# OpenImageIO.
find_package(OpenImageIO QUIET)
if (OPENIMAGEIO_FOUND)
message(STATUS "Found Theia dependency: OpenImageIO in ${OPENIMAGEIO_INCLUDE_DIRS}")
Expand All @@ -173,6 +173,7 @@ else (OPENIMAGEIO_FOUND)
endif (OPENIMAGEIO_FOUND)
list(APPEND THEIA_INCLUDE_DIRS ${OPENIMAGEIO_INCLUDE_DIRS})

# SuiteSparse.
find_package(SuiteSparse QUIET)
if (SUITESPARSE_FOUND)
# On Ubuntu the system install of SuiteSparse (v3.4.0) up to at least
Expand Down Expand Up @@ -207,22 +208,47 @@ endif (NOT TARGET theia AND NOT Theia_BINARY_DIR)
# Set the expected XX_LIBRARIES variable for FindPackage().
set(THEIA_LIBRARIES theia)

set(THEIA_USE_EXTERNAL_CEREAL @THEIA_USE_EXTERNAL_CEREAL@)
set(THEIA_USE_EXTERNAL_FLANN @THEIA_USE_EXTERNAL_FLANN@)

# Cereal.
if (THEIA_USE_EXTERNAL_CEREAL)
find_package(cereal QUIET)
if (TARGET cereal)
message(STATUS "Found required Theia dependency: Cereal")
else (TARGET cereal)
theia_report_not_found("Missing required Theia dependency: Cereal.")
endif (TARGET cereal)
list(APPEND THEIA_LIBRARIES cereal)
endif (THEIA_USE_EXTERNAL_CEREAL)

# Flann.
if (THEIA_USE_EXTERNAL_FLANN)
find_package(Flann QUIET)
if (FLANN_FOUND)
message(STATUS "Found required Theia dependency: Flann")
else (FLANN_FOUND)
theia_report_not_found("Missing required Theia dependency: Flann.")
endif (FLANN_FOUND)
list(APPEND THEIA_INCLUDE_DIRS ${FLANN_INCLUDE_DIR})
list(APPEND THEIA_LIBRARIES ${FLANN_LIBRARY})
endif (THEIA_USE_EXTERNAL_FLANN)

# Add the libraries included with the distribution.
set(THEIA_INTERNAL_LIB_PREFIX ${THEIA_INCLUDE_DIR}/theia/libraries)
set(THEIA_INTERNAL_LIBS_INCLUDES
${THEIA_INTERNAL_LIB_PREFIX}
${THEIA_INTERNAL_LIB_PREFIX}/akaze
${THEIA_INTERNAL_LIB_PREFIX}/cereal
${THEIA_INTERNAL_LIB_PREFIX}/cereal/include
${THEIA_INTERNAL_LIB_PREFIX}/flann
@THEIA_INTERNAL_CEREAL_LIB@
@THEIA_INTERNAL_FLANN_LIB@
${THEIA_INTERNAL_LIB_PREFIX}/gtest
${THEIA_INTERNAL_LIB_PREFIX}/gtest/include
${THEIA_INTERNAL_LIB_PREFIX}/optimo
${THEIA_INTERNAL_LIB_PREFIX}/spectra
${THEIA_INTERNAL_LIB_PREFIX}/statx
${THEIA_INTERNAL_LIB_PREFIX}/stlplus3
${THEIA_INTERNAL_LIB_PREFIX}/vlfeat
${THEIA_INTERNAL_LIB_PREFIX}/visual_sfm)
${THEIA_INTERNAL_LIB_PREFIX}/visual_sfm
${THEIA_INTERNAL_LIB_PREFIX}/vlfeat)

list(APPEND THEIA_INCLUDE_DIRS ${THEIA_INTERNAL_LIBS_INCLUDES})

Expand Down
27 changes: 0 additions & 27 deletions libraries/CMakeLists.txt

This file was deleted.

9 changes: 5 additions & 4 deletions src/theia/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,15 @@ set(THEIA_LIBRARY_DEPENDENCIES
${CERES_LIBRARIES}
${GFLAGS_LIBRARIES}
${GLOG_LIBRARIES}
${SUITESPARSE_LIBRARIES}
${OPENIMAGEIO_LIBRARIES}
${SUITESPARSE_LIBRARIES}
${_THEIA_CEREAL_LIBRARIES}
${_THEIA_FLANN_LIBRARIES}
akaze
flann_cpp
statx
stlplus3
vlfeat
visual_sfm)
visual_sfm
vlfeat)

set(THEIA_LIBRARY_SOURCE
${THEIA_SRC}
Expand Down