# Central location for TeleSculptor external dependency declaration and resolution
include(ExternalProject)

###
# Option for CUDA
#
option(TELESCULPTOR_ENABLE_CUDA "Build with CUDA support" FALSE)
if (TELESCULPTOR_ENABLE_CUDA)
  find_package( CUDA QUIET REQUIRED )
endif()

###
# Option for Python
#
option(TELESCULPTOR_ENABLE_PYTHON "Build with Python support" FALSE)
if (TELESCULPTOR_ENABLE_PYTHON)
  find_package(PythonInterp 3.4 QUIET REQUIRED )
  find_package(PythonLibs 3.4 QUIET REQUIRED )
endif()

###
# Dependencies
#
include(CMake/telesculptor-external-fletch.cmake)
include(CMake/telesculptor-external-kwiver.cmake)

###
# TELESCULPTOR
#
ExternalProject_Add(telesculptor
  PREFIX ${TELESCULPTOR_BINARY_DIR}
  DEPENDS ${TELESCULPTOR_DEPENDENCIES}
  SOURCE_DIR ${TELESCULPTOR_SOURCE_DIR}
  BINARY_DIR ${TELESCULPTOR_EXTERNAL_DIR}/telesculptor-build
  STAMP_DIR ${TELESCULPTOR_STAMP_DIR}
  CMAKE_CACHE_ARGS
    -Dkwiver_DIR:PATH=${kwiver_DIR}
    -DqtExtensions_DIR:PATH=${qtExtensions_DIR}
    -DBUILD_SHARED_LIBS:BOOL=ON
    -DTELESCULPTOR_SUPERBUILD:BOOL=OFF
    -DTELESCULPTOR_ENABLE_MANUALS:BOOL=${TELESCULPTOR_ENABLE_MANUALS}
    -DTELESCULPTOR_ENABLE_TESTING:BOOL=${TELESCULPTOR_ENABLE_TESTING}
    -DTELESCULPTOR_ENABLE_TOOLS:BOOL=${TELESCULPTOR_ENABLE_TOOLS}
    -DTELESCULPTOR_FIXUP_BUNDLE_ON_PACKAGE:BOOL=ON
    -DCMAKE_PREFIX_PATH:STRING=${CMAKE_PREFIX_PATH}
    -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
    -DCMAKE_CONFIGURATION_TYPES:STRING=${CMAKE_CONFIGURATION_TYPES}
    -DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER}
    -DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS}
    -DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER}
    -DCMAKE_C_FLAGS:STRING=${ep_common_c_flags}
     ${CMAKE_CXX_COMPILER_LAUNCHER_FLAG}
     ${CMAKE_C_COMPILER_LAUNCHER_FLAG}
    -DCMAKE_EXE_LINKER_FLAGS:STRING=${CMAKE_EXE_LINKER_FLAGS}
    -DCMAKE_SHARED_LINKER_FLAGS:STRING=${CMAKE_SHARED_LINKER_FLAGS}
    -DADDITIONAL_C_FLAGS:STRING=${ADDITIONAL_C_FLAGS}
    -DADDITIONAL_CXX_FLAGS:STRING=${ADDITIONAL_CXX_FLAGS}
    -DCPACK_OUTPUT_FILE_PREFIX:STRING=${CMAKE_CURRENT_BINARY_DIR}
  INSTALL_COMMAND ${CMAKE_CPACK_COMMAND}
)

