FILE (GLOB gamestates "*.c") FOREACH(gamestate ${gamestates}) get_filename_component(gamestate_name ${gamestate} NAME_WE) set(sources "${gamestate_name}.c") FILE (GLOB submodules "${gamestate_name}/*.c") FOREACH(submodule ${submodules}) get_filename_component(submodule_name ${submodule} NAME_WE) list(APPEND sources "${gamestate_name}/${submodule_name}.c") ENDFOREACH(submodule) register_gamestate(${gamestate_name} "${sources}") ENDFOREACH(gamestate)