[CMake] Sources from Subdirs

Andy Cedilnik andy.cedilnik at kitware.com
Thu Mar 3 08:29:15 EST 2005


Hi Michael,

At this point there is no good way to do that. This may be solved in the
future with redesigning the way subdirectories are evaluated. For now,
what you can do is to instead of using subdirs, you use include.

For example, you have subdirectory foo with files a.c, b.c, c.c:

Then you would do in toplevel:

INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/foo/sources.cmake)
ADD_LIBRARY(mylib ${sources})

and in file foo/sources.cmake:

SET(sources
  foo/a.c
  foo/b.c
  foo/c.c
)

You could also play with foreach or create a macro that will prepend the
path:

MACRO(import_from_subdir subdir real_sources)
  SET(sources)
  INCLUDE("${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/sources.cmake")
  FOREACH(src ${sources})
    SET(real_sources ${real_sources} "${subdir}/${src}")
  ENDFOREACH(src)
ENDMACRO(import_from_subdir)

now you do:

import_from_subdir(foo my_sources)
ADD_LIBRARY(mylib ${my_sources})

Looks good?

       Andy

Michael Seydl wrote:

> is there a way to set variables in listfile and propagate them to the
> parent where it was called by subdirs?
>
> the reason is i'd like to add this files in a subdir to a add_library
> command without SETting the files in the parent files using relative
> paths.
>
> i'd like to use it with subdirs
>
> greetz,
>
> mingy
> _______________________________________________
> CMake mailing list
> CMake at cmake.org
> http://www.cmake.org/mailman/listinfo/cmake



-- 
Andy Cedilnik
Kitware Inc.



More information about the CMake mailing list