[CMake] Sources from Subdirs

Michael Seydl mingy at hlw.co.at
Fri Mar 4 05:43:43 EST 2005


thx for this hint! the macro works really well :)

but what i've got to if the directory in which i call this macro is a 
child of another parent...

then i have to move the macro down the the last parent and call all 
subdirs by there relative paths do i?

i'd like to have a smooth way of including subdirs without depending on 
the fact that the file where i include it has to be the last parent... 
because in this case the CURRENT_SOURCE_DIR var would point to the last 
parent...

do u have any ideas how i can solve this problem?

greetz,

mingy


Andy Cedilnik wrote:

>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
>>    
>>
>
>
>
>  
>



More information about the CMake mailing list