ADD_LIBRARY(JFJochHDF5Wrappers STATIC
        HDF5Objects.cpp HDF5Objects.h
        H5FDpoison_sec2.c H5FDpoison_sec2.h
        ../compression/bitshuffle/bshuf_h5filter.c
        ../compression/bitshuffle/bshuf_h5filter.h)
set_target_properties(JFJochHDF5Wrappers PROPERTIES POSITION_INDEPENDENT_CODE ON)

TARGET_LINK_LIBRARIES(JFJochHDF5Wrappers Compression hdf5-static)

ADD_LIBRARY(JFJochWriter STATIC
        HDF5DataFile.h  HDF5DataFile.cpp
        HDF5NXmx.cpp      HDF5NXmx.h
        NXmxModules.cpp   NXmxModules.h
        FileWriter.cpp FileWriter.h
        HDF5DataFilePlugin.cpp
        HDF5DataFilePlugin.h
        HDF5DataFilePluginROI.cpp
        HDF5DataFilePluginROI.h
        HDF5DataFilePluginXFEL.cpp
        HDF5DataFilePluginXFEL.h
        HDF5DataFilePluginMX.cpp
        HDF5DataFilePluginMX.h
        HDF5DataFilePluginAzInt.cpp
        HDF5DataFilePluginAzInt.h
        HDF5DataFilePluginDetector.cpp
        HDF5DataFilePluginDetector.h
        HDF5DataFilePluginImageStats.cpp
        HDF5DataFilePluginImageStats.h
        HDF5DataFilePluginReflection.cpp
        HDF5DataFilePluginReflection.h
        HDF5DataFilePluginPerformance.cpp
        HDF5DataFilePluginPerformance.h
)

# The placed atomic model (mmCIF/PDB) that rugnux writes beside its merged output.
ADD_LIBRARY(JFJochModelWriter STATIC WriteModel.cpp WriteModel.h)
TARGET_LINK_LIBRARIES(JFJochModelWriter JFJochLogger gemmi)

# rugnux's merged MTZ, map-coefficient MTZ and placed model, to and from the structured END-message
# blocks, so that jfjoch_writer writes them with gemmi alone and no analysis library; and the atomic model
# a run is given and the merged reflections --mode refine is given, parsed for it.
ADD_LIBRARY(JFJochRugnuxFiles STATIC WriteRugnuxFiles.cpp WriteRugnuxFiles.h
        RugnuxResultBlocks.cpp RugnuxResultBlocks.h
        RugnuxModelFile.cpp RugnuxModelFile.h
        RugnuxReflectionFile.cpp RugnuxReflectionFile.h)
TARGET_LINK_LIBRARIES(JFJochRugnuxFiles JFJochModelWriter JFJochLogger JFJochVersion gemmi ZLIB::ZLIB)

TARGET_LINK_LIBRARIES(JFJochWriter JFJochPreview JFJochLogger JFJochHDF5Wrappers CBORStream2FrameSerialize
        JFJochRugnuxFiles)

# The streaming writer and the jfjoch_writer service belong to the Linux server stack, not the
# portable viewer subset: JFJochStreamWriter pulls in JFJochImagePuller (not built in a viewer-only
# tree) and jfjoch_writer uses a fork()/waitpid() multi-process design (<sys/wait.h>, no Windows
# equivalent). The portable JFJochWriter library above is what the CLI tools and viewer need; these
# two targets are not. (Windows/macOS force a portable build, so this also excludes them there.)
IF (NOT JFJOCH_PORTABLE_ONLY)
    ADD_LIBRARY(JFJochStreamWriter StreamWriter.cpp StreamWriter.h)
    TARGET_LINK_LIBRARIES(JFJochStreamWriter JFJochWriter JFJochImagePuller)

    ADD_EXECUTABLE(jfjoch_writer jfjoch_writer.cpp)
    TARGET_LINK_LIBRARIES(jfjoch_writer JFJochStreamWriter)
    INSTALL(TARGETS jfjoch_writer RUNTIME COMPONENT writer)
ENDIF()
