project( ms3align )

cmake_minimum_required(VERSION 2.8.11)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

add_subdirectory(mscomplex-tri)

#option(BUILD_MOLPATCH_TOOL "build the molecule skin surface and patch extraction tool" OFF)
#if(BUILD_MOLPATCH_TOOL)
#add_subdirectory(molpatch)
#endif(BUILD_MOLPATCH_TOOL)

option(BUILD_MS3ALIGN_TOOL "build the Multi-Scale MorseSmale Mol Surface alignment tool" ON)

if(BUILD_MS3ALIGN_TOOL)

  find_package(Boost REQUIRED serialization filesystem program_options system thread date_time)
  find_package(VTK REQUIRED)
  find_package(Eigen3 REQUIRED)
  find_package(Qt5 COMPONENTS Widgets REQUIRED)
  
  set ( MS3ALIGN_MEMORY_LIMIT 0 CACHE STRING
           "Execution memory limit (Mb). 0 indicates no limit.")

  add_definitions(-DUSING_VTK)

  add_definitions(-DMS3ALIGN_MEMORY_LIMIT=${MS3ALIGN_MEMORY_LIMIT})

  include(${VTK_USE_FILE})

  include_directories(
    ${EIGEN3_INCLUDE_DIR}
    ${CMAKE_CURRENT_SOURCE_DIR}/mscomplex-tri/
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${Boost_INCLUDE_DIRS})


  set(MS3ALIGN_TOOL_SRCS
    ms3align-tool.cpp

    utl.h
    utl.cpp
    utl_inl.h

    curvature.hpp
    curvature.cpp

    fpalign.h
    fpalign.cpp

    mscomplex-tri/trimesh_mscomplex_vtk.cpp
  )

  if(NOT VTK_LIBRARIES)
    set(VTK_LIBRARIES vtkHybrid)
  endif(NOT VTK_LIBRARIES)

  add_executable(ms3align ${MS3ALIGN_TOOL_SRCS} $<TARGET_OBJECTS:mscomplex-tri>)

  option(MS3ALIGN_USE_OPENMP "Use OpenMP parallelism" ON)

  if(MS3ALIGN_USE_OPENMP)
    find_package(OpenMP REQUIRED)

    set_source_files_properties(${MS3ALIGN_TOOL_SRCS} PROPERTIES
        COMPILE_FLAGS ${OpenMP_CXX_FLAGS})
    set_target_properties(ms3align PROPERTIES
        LINK_FLAGS ${OpenMP_CXX_FLAGS})

  endif(MS3ALIGN_USE_OPENMP)
  
  target_link_libraries(ms3align ${Boost_LIBRARIES} ${VTK_LIBRARIES} GL)

  install(TARGETS ms3align RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})

endif(BUILD_MS3ALIGN_TOOL)
