# - PNeXus library ------------------------------------------------------------

include_directories(${NEXUS_INCLUDE_DIR}) # to get the nexus headers

#--- create pkg-config info ---------------------------------------------------
set(prefix "${CMAKE_INSTALL_PREFIX}")   
set(exec_prefix "\$\{prefix\}")
set(libdir "\$\{exec_prefix\}/lib")
set(includedir "\$\{prefix\}/include")   
set(PNEXUS_VERSION "1.0.0")
set(PNEXUS_LIBRARY_NAME "PNeXus")
configure_file("PNeXus.pc.in" "PNeXus.pc" @ONLY)

#--- lib creation -------------------------------------------------------------
add_library(PNeXus SHARED
  PNeXus.cpp
)

#--- set target properties, e.g. version --------------------------------------
set_target_properties(PNeXus
  PROPERTIES
    VERSION ${PNEXUS_VERSION}
)

#--- make sure that the include directory is found ----------------------------
target_include_directories(
  PNeXus BEFORE PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
)

#--- add library dependencies -------------------------------------------------
if (HAVE_HDF4)
  set(HDF_LIBS ${HDF4_LIBRARIES} ${HDF5_LIBRARIES})
else (HAVE_HDF4)   
  set(HDF_LIBS ${HDF5_LIBRARIES})
endif (HAVE_HDF4)
message(STATUS "++>> HDF_LIBS: ${HDF_LIBS}")
target_link_libraries(PNeXus ${HDF_LIBS} ${ROOT_LIBRARIES})

#--- install PNeXus solib -----------------------------------------------------
install(TARGETS PNeXus DESTINATION lib)

#--- install PNeXus header ----------------------------------------------------
install(FILES PNeXus.h DESTINATION include)

#--- install pkg-config info --------------------------------------------------
install(
  FILES ${CMAKE_CURRENT_BINARY_DIR}/PNeXus.pc
  DESTINATION lib/pkgconfig
)
