cmake_minimum_required(VERSION 3.1...3.12 FATAL_ERROR)
macro(SUBDIRLIST_CUSTOM result curdir objDirName)
    file(GLOB children RELATIVE ${curdir} ${curdir}/*)
    set(dirlist "")
    foreach(child ${children})
        if((IS_DIRECTORY ${curdir}/${child}) AND (${child} STREQUAL ${objDirName}))
            aux_source_directory(${OBJ_BASE_PATH}/${child} dirlist)
        endif()
    endforeach()
    list(APPEND ${result} ${dirlist})
endmacro()

function (getSubprojectModule ALL_MODULE OBJ_SRC_LIST OBJ_MODULE_NAME)
    list(LENGTH ARGV argv_len)
    message(STATUS "length of ARGV: ${argv_len}")
    set(i 1)
    while(2 LESS ${argv_len})
    endwhile()
endfunction ()

macro (AddSources)  #遍历工程文件
    file (RELATIVE_PATH _relPath "${CMAKE_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}")
    foreach (_src ${ARGN})
        if (_relPath)
            list (APPEND SRCS "${_relPath}/${_src}")
        else()
            list (APPEND SRCS "${_src}")
        endif()
    endforeach()
    if (_relPath) # propagate SRCS to parent directory
        set (SRCS ${SRCS} PARENT_SCOPE)
    endif()
endmacro()

macro(SUBDIRLIST result curdir)
  file(GLOB children RELATIVE ${curdir} ${curdir}/*)
  set(dirlist "")
  foreach(child ${children})
    if(IS_DIRECTORY ${curdir}/${child})
      list(APPEND dirlist ${child})
    endif()
  endforeach()
  set(${result} ${dirlist})
endmacro()

function(GetModules)
  # message(${CMAKE_CURRENT_SOURCE_DIR})
  SUBDIRLIST(SUBDIRS ${CMAKE_CURRENT_SOURCE_DIR})
  # message(${SUBDIRS})
  foreach(subdir ${SUBDIRS})
    add_subdirectory(${subdir})
    if(subdir STREQUAL "cpp_case")
      add_definitions(-D CPP_LEARN)
    endif()
    # message(${subdir}/include)
    include_directories(${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/include)
  endforeach()
  # include_directories(${CMAKE_CURRENT_SOURCE_DIR}/cpp_case/include)
  include_directories(${CMAKE_SOURCE_DIR}/lib/securec/include)
endfunction(GetModules)