Quantcast

How to iterator over a set of directories containing projects?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to iterator over a set of directories containing projects?

Peter-21
I have a bunch (50+) of sample programs deep in the hierarchy of my
library project. Each of these samples has a similar CMakeLists.txt
file, like

     add_executable( binning binning.cpp )
     target_link_libraries( binning ${Boost_LIBRARIES} )

where binning would be the name of the sample as well as the name of the
directory. I'm wondering if there would be a way to avoid authoring
these similar CMakeLists.txt files and instead somehow iterate over all
the projects in the CMakeLists.txt file which is one level higher in the
hierarchy?

Peter

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to iterator over a set of directories containing projects?

Alexander Neundorf-3
On Monday 13 July 2009, Peter wrote:

> I have a bunch (50+) of sample programs deep in the hierarchy of my
> library project. Each of these samples has a similar CMakeLists.txt
> file, like
>
>      add_executable( binning binning.cpp )
>      target_link_libraries( binning ${Boost_LIBRARIES} )
>
> where binning would be the name of the sample as well as the name of the
> directory. I'm wondering if there would be a way to avoid authoring
> these similar CMakeLists.txt files and instead somehow iterate over all
> the projects in the CMakeLists.txt file which is one level higher in the
> hierarchy?

Not sure I understand you correctly.
You could write a macro like this:

macro(add_sample _name)
   add_executable( ${_name} ${_name}/${_name}.cpp)
   ... do whatever more is required
endmacro(add_sample)

and then do in the toplevel project file just:

add_sample(binning)
add_sample(foo)
etc.

Does this help ?

Alex
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to iterator over a set of directories containing projects?

Peter-21
Am 14.07.2009 20:22, schrieb Alexander Neundorf:

> On Monday 13 July 2009, Peter wrote:
>    
>> I have a bunch (50+) of sample programs deep in the hierarchy of my
>> library project. Each of these samples has a similar CMakeLists.txt
>> file, like
>>
>>       add_executable( binning binning.cpp )
>>       target_link_libraries( binning ${Boost_LIBRARIES} )
>>
>> where binning would be the name of the sample as well as the name of the
>> directory. I'm wondering if there would be a way to avoid authoring
>> these similar CMakeLists.txt files and instead somehow iterate over all
>> the projects in the CMakeLists.txt file which is one level higher in the
>> hierarchy?
>>      
>
> Not sure I understand you correctly.
> You could write a macro like this:
>
> macro(add_sample _name)
>     add_executable( ${_name} ${_name}/${_name}.cpp)
>     ... do whatever more is required
> endmacro(add_sample)
>
> and then do in the toplevel project file just:
>
> add_sample(binning)
> add_sample(foo)
> etc.
>
> Does this help ?
>
> Alex
>
>    
I finally did this:

set ( samples
     sample1
     ...
     samplen
     )

foreach ( proj ${samples} )
     add_executable ( ${proj} ${proj}/${proj}.cpp )
     target_link_libraries( ${proj} ${Boost_LIBRARIES} )
endforeach ()

This works fine.

The macro approach would work too, I guess, thanks.

Peter


_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Loading...