CMake macro across CMakeLists
I have a c++ project which directory structure like below:

    server/
       code/
          BASE/
             Thread/
             Log/
             Memory/
          Net/
       cmake/
          CMakeList.txt
          BASE/
             CMakeList.txt
          Net/
             CMakeList.txt

here is part of /cmake/CMakeList.txt: 

    MACRO(SUBDIRLIST result curdir)
      FILE(GLOB children RELATIVE ${curdir} ${curdir}/*)
      SET(dirlist "")
      FOREACH(child ${children})
        IF(IS_DIRECTORY ${curdir}/${child})
            SET(dirlist ${dirlist} ${child})
        ENDIF()
      ENDFOREACH()
      SET(${result} ${dirlist})
    ENDMACRO()
    
    add_subdirectory(Base)

then use macro in /cmake/Base/CMakeList.txt: 

    SET(SUBDIR, "")
    SUBDIRLIST(SUBDIRS, ${BASE_SRC_DIR})
    message("SUBDIRS : " ${SUBDIRS})

output:
SUBDIRS : 

I check ${dirlist} by output it's value in macro, I get directory list expected,but when message("result " ${result}) after SET(${result} ${dirlist}),I can not get output expected , what's wrong with my CMakeLists.txt?


CMake macro across CMakeLists
===

I have a c++ project which directory structure like below:

    server/
       code/
          BASE/
             Thread/
             Log/
             Memory/
          Net/
       cmake/
          CMakeList.txt
          BASE/
             CMakeList.txt
          Net/
             CMakeList.txt

here is part of /cmake/CMakeList.txt: 

    MACRO(SUBDIRLIST result curdir)
      FILE(GLOB children RELATIVE ${curdir} ${curdir}/*)
      SET(dirlist "")
      FOREACH(child ${children})
        IF(IS_DIRECTORY ${curdir}/${child})
            SET(dirlist ${dirlist} ${child})
        ENDIF()
      ENDFOREACH()
      SET(${result} ${dirlist})
    ENDMACRO()
    
    add_subdirectory(Base)

then use macro in /cmake/Base/CMakeList.txt: 

    SET(SUBDIR, "")
    SUBDIRLIST(SUBDIRS, ${BASE_SRC_DIR})
    message("SUBDIRS : " ${SUBDIRS})

output:
SUBDIRS : 

I check ${dirlist} by output it's value in macro, I get directory list expected,but when message("result " ${result}) after SET(${result} ${dirlist}),I can not get output expected , what's wrong with my CMakeLists.txt?

