include(CheckCCompilerFlag)

macro(add_c_flags_if_available)
	foreach(ARG ${ARGN})
        string(REPLACE "-" "_" ARG_STRIPPED ${ARG})
        string(REPLACE "/" "_" ARG_STRIPPED ${ARG_STRIPPED})
		CHECK_C_COMPILER_FLAG(${ARG} HAVE_${ARG_STRIPPED})
		if(${HAVE_${ARG}})
			set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARG}")
		endif()
	endforeach()
endmacro()

macro(list_directories 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()
