# The plugin's own release number. Not the VERSION_* in plugin.h: those fill the info array, where XDS
# requires the major version to be 0 and refuses the plugin otherwise.
SET(JFJOCH_XDS_PLUGIN_VERSION 1.1.0)

ADD_LIBRARY(jfjoch_xds_plugin SHARED plugin.cpp plugin.h)
TARGET_COMPILE_DEFINITIONS(jfjoch_xds_plugin PRIVATE JFJOCH_XDS_PLUGIN_VERSION="${JFJOCH_XDS_PLUGIN_VERSION}")

TARGET_LINK_LIBRARIES(jfjoch_xds_plugin JFJochHDF5Wrappers JFJochVersion Compression hdf5-static)

# The licence texts (licenses/<name>.txt) of the third-party code the plugin links: HDF5 and the zlib
# it uses, Zstandard, and LZ4 + both Bitshuffles from Compression. Keep in step with the line above.
SET(JFJOCH_XDS_PLUGIN_LICENSES hdf5 zlib zstd lz4 bitshuffle bitshuffle-hperf)

set_target_properties(jfjoch_xds_plugin PROPERTIES
        CXX_VISIBILITY_PRESET hidden
        C_VISIBILITY_PRESET hidden
        VISIBILITY_INLINES_HIDDEN YES
        VERSION ${JFJOCH_XDS_PLUGIN_VERSION}
)

# Export the four plugin_* entry points and nothing else, so the statically linked HDF5 cannot clash
# with another copy in the process.
target_link_options(jfjoch_xds_plugin PRIVATE "LINKER:--exclude-libs,ALL")

IF (JFJOCH_PORTABLE_ONLY)
    INSTALL(TARGETS jfjoch_xds_plugin LIBRARY DESTINATION lib COMPONENT xds_plugin)
    LIST(TRANSFORM JFJOCH_XDS_PLUGIN_LICENSES REPLACE "(.+)" "${CMAKE_SOURCE_DIR}/licenses/\\1.txt")
    INSTALL(FILES ${CMAKE_SOURCE_DIR}/LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/THIRD_PARTY_NOTICES.md
            DESTINATION share/doc/jfjoch_xds_plugin COMPONENT xds_plugin)
    INSTALL(FILES ${JFJOCH_XDS_PLUGIN_LICENSES}
            DESTINATION share/doc/jfjoch_xds_plugin/licenses COMPONENT xds_plugin)
ELSE()
    INSTALL(TARGETS jfjoch_xds_plugin DESTINATION ${CMAKE_INSTALL_LIBDIR}/jfjoch COMPONENT viewer)
ENDIF()
