# SPDX-FileCopyrightText: 2022 Copyright contributors to the cppTango project
#
# SPDX-License-Identifier: LGPL-3.0-or-later

add_subdirectory(idl)
add_subdirectory(common)
add_subdirectory(client)
add_subdirectory(server)

# the folder internal is intentionally left out

function(decorate_with_include files prefix_path return_var)

  # remove all path components
  list(TRANSFORM files REPLACE "(.+/)?(.+)" "\\2")

  # create full #include lines
  list(TRANSFORM files PREPEND "#include <${prefix_path}/")
  list(TRANSFORM files APPEND ">")

  # sort predictable
  list(SORT files COMPARE STRING CASE SENSITIVE ORDER ASCENDING)

  # convert list to \n separated entries
  list(JOIN files "\n" files)

  set(${return_var} "${files}" PARENT_SCOPE)
endfunction()

if(WIN32)
    add_subdirectory(windows)
    decorate_with_include("${TANGO_WINDOWS_HEADERS}" "tango/windows" TANGO_WINDOWS_HEADERS_FULL)
else()
    set(TANGO_WINDOWS_HEADERS_FULL "")
endif()

decorate_with_include("${TANGO_COMMON_HEADERS}" "tango/common" TANGO_COMMON_HEADERS_FULL)
decorate_with_include("${TANGO_TELEMETRY_HEADERS}" "tango/common/telemetry" TANGO_TELEMETRY_HEADERS_FULL)
decorate_with_include("${TANGO_CLIENT_HEADERS}" "tango/client" TANGO_CLIENT_HEADERS_FULL)
decorate_with_include("${TANGO_SERVER_HEADERS}" "tango/server" TANGO_SERVER_HEADERS_FULL)

configure_file(tango.h.in tango.h @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/tango.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/tango")
