# CCGO generated file: DO NOT EDIT!
# Generated by "CCGO" Template Generator of CMake, CCGO Template Version 1.0.0
#
# Copyright 2024 zhlinh and ccgo Project Authors. All rights reserved.
# Use of this source code is governed by a MIT-style
# license that can be found at
#
# https://opensource.org/license/MIT
#
# The above copyright notice and this permission
# notice shall be included in all copies or
# substantial portions of the Software.

cmake_minimum_required(VERSION 3.14)

include(${CCGO_CMAKE_DIR}/CMakeUtils.cmake)
include(${CCGO_CMAKE_DIR}/CMakeExtraFlags.cmake)

set(TEMPLATE_SUB_LIB_NAME "" CACHE STRING "A string variable of this sub library name")
generate_library_name(TEMPLATE_SUB_LIB_NAME ${CMAKE_CURRENT_SOURCE_DIR})

message(STATUS "Generating Src library [${TEMPLATE_SUB_LIB_NAME}]")

project(${TEMPLATE_SUB_LIB_NAME})

set(TEMPLATE_SUB_DEPS "")

# loop map
list(LENGTH CCGO_CONFIG_DEPS_MAP deps_map_len)
# loop the list and get the index of each element
foreach(index RANGE 0 ${deps_map_len})
    math(EXPR is_odd "${index} % 2")
    if(is_odd EQUAL 1)
        continue()
    endif()
    # get next index
    math(EXPR next_index "${index} + 1")
    if(next_index GREATER_EQUAL ${deps_map_len})
        continue()
    endif()
    # get the value of current element
    list(GET CCGO_CONFIG_DEPS_MAP ${index} key)
    list(GET CCGO_CONFIG_DEPS_MAP ${next_index} value)
    # split each key-value pair into key and value
    string(REPLACE "," ";" list_value "${value}")
    if ("${MAIN_PROJECT_NAME}-${key}" STREQUAL ${TEMPLATE_SUB_LIB_NAME})
        foreach(item IN LISTS list_value)
            # add prefix
            set(new_item "${MAIN_PROJECT_NAME}::${MAIN_PROJECT_NAME}-${item}")
            # add new element to the list
            list(APPEND list_deps ${new_item})
        endforeach()
        set(TEMPLATE_SUB_DEPS ${list_deps})
        break()
    endif()
endforeach()

list(LENGTH TEMPLATE_SUB_DEPS TEMP_SUB_DEPS_LEN)
if(${TEMP_SUB_DEPS_LEN} GREATER 0)
    message(STATUS "CCGO_CONFIG_DEPS_MAP [${TEMPLATE_SUB_LIB_NAME}] get TEMPLATE_SUB_DEPS: ${TEMPLATE_SUB_DEPS}")
endif()

add_cc_library(
        NAME
        ${TEMPLATE_SUB_LIB_NAME}
        DIRS
        ${CMAKE_CURRENT_SOURCE_DIR}
        DEPS
        ${TEMPLATE_SUB_DEPS}
        PUBLIC
)
