diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c1b15041..aff40558e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -218,24 +218,69 @@ include_directories( # as system headers. include_directories(SYSTEM ${EIGEN_INCLUDE_DIRS}) + +set(THEIA_USE_SYSTEM_CEREAL OFF CACHE BOOL "Use a system Cereal library") +set(THEIA_USE_SYSTEM_FLANN OFF CACHE BOOL "Use a system Flann library") + +include_directories(libraries) + # 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) +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_SYSTEM_CEREAL) + add_subdirectory(libraries/cereal) + + include_directories(${cereal_SOURCE_DIR} ${cereal_SOURCE_DIR}/include) +else() + find_package(cereal REQUIRED) + + set(_THEIA_CEREAL_LIBRARIES cereal) +endif() + +# Flann for fast approximate nearest neighbor searches. +if(NOT THEIA_USE_SYSTEM_FLANN) + add_subdirectory(libraries/flann) + + include_directories(${flann_SOURCE_DIR} ${flann_SOURCE_DIR}/src/cpp) + set(_THEIA_FLANN_LIBRARIES flann_cpp) +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}) + list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") include(OptimizeTheiaCompilerFlags) diff --git a/cmake/FindFlann.cmake b/cmake/FindFlann.cmake new file mode 100644 index 000000000..5d19ef75f --- /dev/null +++ b/cmake/FindFlann.cmake @@ -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) diff --git a/libraries/CMakeLists.txt b/libraries/CMakeLists.txt deleted file mode 100644 index 84f38298e..000000000 --- a/libraries/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -if (${BUILD_TESTING}) - add_subdirectory(gtest) -endif (${BUILD_TESTING}) - -# AKAZE feature extractor. -add_subdirectory(akaze) - -# Cereal for portable IO. -add_subdirectory(cereal) - -# Flann for fast approximate nearest neighbor searches. -add_subdirectory(flann) - -# Add Optimo. -add_subdirectory(optimo) - -# Add Statx. -add_subdirectory(statx) - -# STLPlus for filepath tools. -add_subdirectory(stlplus3) - -# Add VLFeat. -add_subdirectory(vlfeat) - -# Add VisualSfM files. -add_subdirectory(visual_sfm) \ No newline at end of file diff --git a/src/theia/CMakeLists.txt b/src/theia/CMakeLists.txt index 65787eb51..07c54a421 100644 --- a/src/theia/CMakeLists.txt +++ b/src/theia/CMakeLists.txt @@ -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}