# 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 project-specific CMake utilities and compiler flags
include(${CCGO_CMAKE_DIR}/CMakeUtils.cmake)        # Custom CMake helper functions
include(${CCGO_CMAKE_DIR}/CMakeExtraFlags.cmake)   # Platform-specific compiler flags

## Generate library name from current directory path
# For example: src/ -> {project}-src, src/network/ -> {project}-network
set(TEMPLATE_SUB_LIB_NAME "")
generate_library_name(TEMPLATE_SUB_LIB_NAME ${CMAKE_CURRENT_SOURCE_DIR})

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

# Define project for source directory
project(${TEMPLATE_SUB_LIB_NAME} LANGUAGES C CXX)

## Automatically discover all subdirectories in src/
# This enables modular code organization (e.g., src/network/, src/storage/, src/utils/)
set(TEMP_DIR_LIST "")
get_subdirectories(TEMP_DIR_LIST "${CMAKE_CURRENT_SOURCE_DIR}/")

## For each subdirectory, generate its CMakeLists.txt and add as subproject
# This allows each module to build as an independent static library
foreach(dir IN LISTS TEMP_DIR_LIST)
    # Dynamically generate {dir}/CMakeLists.txt from template
    configure_file(
            ${CCGO_CMAKE_DIR}/template/Src.SubDir.CMakeLists.txt.in
            ${CMAKE_SOURCE_DIR}/src/${dir}/CMakeLists.txt
            NEWLINE_STYLE LF  # Use Unix-style line endings
            @ONLY             # Only replace  syntax
    )
    # Add subdirectory with custom binary directory name
    # Format: {project}-{dir} (e.g., myproject-network, myproject-storage)
    add_subdirectory(${dir} ${PROJECT_NAME}-${dir})
endforeach()
