# This file is part of the ACTS project.
#
# Copyright (C) 2016 CERN for the benefit of the ACTS project
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.

# Let the user know what's happening.
message(STATUS "Building 'detray::io' component")

# Set up the I/O utils library.
file(
    GLOB _detray_io_utils_public_headers
    RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
    "include/detray/io/utils/*.hpp"
)
detray_add_library( detray_io_utils io_utils
   ${_detray_io_utils_public_headers}
)

# Set up the core I/O library.
file(
    GLOB _detray_io_public_headers
    RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
    "include/detray/io/backend/*.hpp"
    "include/detray/io/backend/detail/*.hpp"
    "include/detray/io/frontend/*.hpp"
    "include/detray/io/frontend/detail/*.hpp"
    "include/detray/io/frontend/impl/*.hpp"
    "include/detray/io/json/*.hpp"
    "include/detray/io/json/detail/*.hpp"
)
detray_add_library( detray_io io
   ${_detray_io_public_headers}
)
target_link_libraries(
    detray_io
    INTERFACE
        nlohmann_json::nlohmann_json
        vecmem::core
        detray::core
        detray::io_utils
)

# Set up libraries using particular algebra plugins.
detray_add_library( detray_io_array io_array )
target_link_libraries(
    detray_io_array
    INTERFACE detray::io detray::algebra_array
)

if(DETRAY_EIGEN_PLUGIN)
    detray_add_library( detray_io_eigen io_eigen )
    target_link_libraries(
        detray_io_eigen
        INTERFACE detray::io detray::algebra_eigen
    )
endif()

if(DETRAY_SMATRIX_PLUGIN)
    detray_add_library( detray_io_smatrix io_smatrix )
    target_link_libraries(
        detray_io_smatrix
        INTERFACE detray::io detray::algebra_smatrix
    )
endif()

if(DETRAY_VC_AOS_PLUGIN)
    detray_add_library( detray_io_vc_aos io_vc_aos )
    target_link_libraries(
        detray_io_vc_aos
        INTERFACE detray::io detray::algebra_vc_aos
    )
endif()

# Set up the csv data I/O library.
file(
    GLOB _detray_csv_io_public_headers
    RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
    "include/detray/io/csv/*.hpp"
)
detray_add_library( detray_csv_io csv_io
   ${_detray_csv_io_public_headers}
)
target_link_libraries(detray_csv_io INTERFACE detray::io_utils)

# Compile all headers (including the ones under detail/) one-by-one, against
# std::array only, for the reason given in core/CMakeLists.txt.
detray_compile_headers(
    io_array
    detray::io_array
    "include/detray/io/*.hpp"
    "include/detray/io/**/*.hpp"
)

# Clean up.
unset(_detray_io_public_headers)
