[CMake] Read multiple path names from filesystem

Michael Wild themiwi at gmail.com
Thu Oct 29 09:00:55 EDT 2009


On 29. Oct, 2009, at 11:11 , Tim Just wrote:

> Hi,
>
> I'm using CMake 2.8 rc3 on Ubuntu to build a modular and extensible  
> project. Therefore I have a directory called 'modules' beneath the  
> project root. In this folder may be an undefined number of  
> subfolders containing module sources and CMakeLists.txt files. In  
> the CMakeLists.txt in project root, I try to find out which modules  
> exist in the modules folder. To do so I'm using find_path:
>
> find_path(MODULE_PATH CMakeLists.txt PATHS modules/* NO_DEFAULT_PATH)
> get_filename_component(MODULE_NAME ${MODULE_PATH} NAME)
>
> This works for ONE module, but I want to find ALL modules in the  
> directory. The number of modules is not known in advance.
>
> Has anyone suggestions how to realize this functionality?
>
> Thanks for your help,
>
> Tim
>

You should be using something like

FILE(GLOB MODULES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "$ 
{CMAKE_CURRENT_SOURCE_DIR}/modules/*")
FOREACH(module ${MODULE_PATHS})
   IF(IS_DIRECTORY "${module}")
     ADD_SUBDIRECTORY("${module}")
   ENDIF()
ENDFOREACH()


HTH

Michael


More information about the CMake mailing list