find_package(Eigen3 REQUIRED)

if(USE_MMTF)
  find_package(MMTF REQUIRED)
  include_directories(SYSTEM "${MMTF_INCLUDE_DIRS}")
  add_definitions(-DAVO_USE_MMTF)
endif()

if(USE_HDF5)
  find_package(HDF5 REQUIRED COMPONENTS C)
  # HDF5 is built in two ways (CMake or its default build system). If we are
  # using the CMake version it makes use of exported targets, hence this check.
  if(NOT DEFINED HDF5_LIBRARIES)
    set(HDF5_LIBRARIES "hdf5")
  endif()
  include_directories(SYSTEM "${HDF5_INCLUDE_DIRS}")
  add_definitions(-DAVO_USE_HDF5)
endif()

# Add as "system headers" to avoid warnings generated by them with
# compilers that support that notion.
include_directories(SYSTEM "${EIGEN3_INCLUDE_DIR}"
  "${AvogadroLibs_SOURCE_DIR}/thirdparty/pugixml"
  "${AvogadroLibs_SOURCE_DIR}/thirdparty/struct"
  "${AvogadroLibs_SOURCE_DIR}/thirdparty")

if(DEFINED AvogadroLibs_MEMORY_INCLUDE_DIRS)
  # The smart pointer classes just require headers.
  include_directories(SYSTEM ${AvogadroLibs_MEMORY_INCLUDE_DIRS})
endif()

set(HEADERS
  cjsonformat.h
  cmlformat.h
  dcdformat.h
  fileformat.h
  fileformatmanager.h
  gromacsformat.h
  mdlformat.h
  vaspformat.h
  pdbformat.h
  xyzformat.h
  trrformat.h
  lammpsformat.h
)

set(SOURCES
  cjsonformat.cpp
  cmlformat.cpp
  dcdformat.cpp
  fileformat.cpp
  fileformatmanager.cpp
  gromacsformat.cpp
  mdlformat.cpp
  vaspformat.cpp
  pdbformat.cpp
  xyzformat.cpp
  trrformat.cpp
  lammpsformat.cpp
)

if(USE_HDF5)
  list(APPEND HEADERS hdf5dataformat.h)
  list(APPEND SOURCES hdf5dataformat.cpp)
endif()

if(USE_MMTF)
  list(APPEND HEADERS mmtfformat.h)
  list(APPEND SOURCES mmtfformat.cpp)
endif()

avogadro_add_library(AvogadroIO ${HEADERS} ${SOURCES})

target_link_libraries(AvogadroIO
  LINK_PUBLIC AvogadroCore
  LINK_PRIVATE struct)
if(USE_HDF5)
  target_link_libraries(AvogadroIO LINK_PRIVATE ${HDF5_LIBRARIES})
endif()
if(WIN32)
  target_link_libraries(AvogadroIO LINK_PRIVATE ws2_32)
endif()
