# CMakeLists for Catalyst

include("cmake/CMakeBasics.cmake")
include("cmake/BasicTypeChecks.cmake")
include("cmake/BitwidthMapping.cmake")

configure_file(conduit_config.h.in conduit_config.h)
configure_file(conduit_bitwidth_style_types.h.in conduit_bitwidth_style_types.h)
configure_file(conduit_exports.h.in conduit_exports.h)


set(conduit_core_headers
    conduit_endianness_types.h
    ${CMAKE_CURRENT_BINARY_DIR}/conduit_exports.h
    ${CMAKE_CURRENT_BINARY_DIR}/conduit_config.h
    ${CMAKE_CURRENT_BINARY_DIR}/conduit_bitwidth_style_types.h
  )
#
# Specify conduit cpp headers
#
set(conduit_headers
    conduit.hpp
    conduit_core.hpp
    conduit_endianness.hpp
    conduit_data_array.hpp
    conduit_data_type.hpp
    conduit_node.hpp
    conduit_generator.hpp
    conduit_error.hpp
    conduit_node_iterator.hpp
    conduit_schema.hpp
    conduit_log.hpp
    conduit_utils.hpp
    )

#
# Specify conduit c interface headers
#
set(conduit_c_headers
    c/conduit.h
    c/conduit_datatype.h
    c/conduit_node.h
    c/conduit_cpp_to_c.hpp
    c/conduit_utils.h
    c/catalyst_conduit_mangle.h
    )

#
# Specify conduit cpp sources
#
set(conduit_sources
    conduit_core.cpp
    conduit_error.cpp
    conduit_endianness.cpp
    conduit_data_type.cpp
    conduit_data_array.cpp
    conduit_generator.cpp
    conduit_node.cpp
    conduit_node_iterator.cpp
    conduit_schema.cpp
    conduit_log.cpp
    conduit_utils.cpp
    )

#
# Specify conduit c interface sources
#
set(conduit_c_sources
    c/conduit_c.cpp
    c/conduit_datatype_c.cpp
    c/conduit_node_c.cpp
    c/conduit_cpp_to_c.cpp
    c/conduit_utils_c.cpp
    )

#-------------------------------------------------------------------------
# an interface target to simply setup include paths.
add_library(conduit_headers INTERFACE)
add_library(catalyst::conduit_headers ALIAS conduit_headers)
target_include_directories(conduit_headers
  INTERFACE
    $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
    $<INSTALL_INTERFACE:${CATALYST_INSTALL_INCLUDE_DIR}>)
c_install_headers(
  HEADERS ${conduit_core_headers}
          ${conduit_headers})
c_install_headers(
  SUBDIR "c"
  HEADERS ${conduit_c_headers})
c_install_targets(conduit_headers)

#-------------------------------------------------------------------------
# build conduit library
add_library(conduit STATIC
    ${conduit_sources}
    ${conduit_c_sources})
set_target_properties(conduit
    PROPERTIES
      # change name to avoid conflict
      # with standard conduit
      OUTPUT_NAME "catalyst_conduit"
      VERSION     "${CATALYST_ABI_VERSION}"
      SOVERSION   "${CATALYST_ABI_VERSION}")
target_link_libraries(conduit
  PUBLIC
    catalyst::core
    catalyst::conduit_headers
  PRIVATE
    libyaml
    b64
    rapidjson)
add_library(catalyst::conduit ALIAS conduit)
c_install_targets(conduit)

#-------------------------------------------------------------------------
# Add subdirectories for third-party dependencies of conduit
add_subdirectory(libyaml)
add_subdirectory(libb64)
add_subdirectory(rapidjson)
