MACRO(ADD_GLOBALDIR dirname)
        include_directories(${dirname})
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()

MACRO(ADDSUBDIRS_CMAKE)
        SUBDIRLIST(SUBDIRS ${CMAKE_CURRENT_SOURCE_DIR})
        FOREACH(subdir ${SUBDIRS})
                if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/CMakeLists.txt)
                    if(NOT (${subdir} MATCHES "__.+"))
                        ADD_SUBDIRECTORY(${subdir} ${CMAKE_CURRENT_BINARY_DIR}/${subdir})
                    endif()
                endif()
        ENDFOREACH()
ENDMACRO(ADDSUBDIRS_CMAKE)

MACRO(ADDSUBDIRS)
        ADDSUBDIRS_CMAKE()
        get_directory_property(hasParent PARENT_DIRECTORY)
        if(hasParent)
                set (SRC_LIBS ${SRC_LIBS} PARENT_SCOPE)
                set (TEST_LIBS ${TEST_LIBS} PARENT_SCOPE)
        endif()
ENDMACRO()

macro(CREATE_LIBRARY NAME SOURCE_LIST DEFINES)
      add_library(${NAME} STATIC ${SOURCE_LIST})
      list (APPEND SRC_LIBS ${NAME})
      get_directory_property(hasParent PARENT_DIRECTORY)
      if(hasParent)
              set (SRC_LIBS ${SRC_LIBS} PARENT_SCOPE)
      endif()
endmacro()

macro(CREATE_TEST_LIBRARY NAME SOURCE_LIST DEFINES)
      add_library(${NAME} STATIC ${SOURCE_LIST})
      list (APPEND TEST_LIBS ${NAME})
      get_directory_property(hasParent PARENT_DIRECTORY)
      if(hasParent)
              set (TEST_LIBS ${TEST_LIBS} PARENT_SCOPE)
      endif()
endmacro()
