It is presently not possible to iterate over all the targets in CMakeLists.txt unless you maintain your own list of targets. It would be a good feature request to provide the full list of CMake targets using:<div><br></div>
<div>get_cmake_property(var TARGETS) # for all targets from top level all the way down</div><div> or</div><div>get_property(var GLOBAL CMAKE_TARGETS ... # for all targets from top level all the way down</div>
<div> or<br><div>get_property(var DIRECTORY CMAKE_TARGETS ... # for targets just in the current directory</div><div><br></div><div><br></div><div>However, presently, nothing like this is implemented. Wouldn't be too hard, just hasn't been done yet.</div>
<div><br></div><div><br></div><div>HTH,</div><div>David</div><div><br></div><div><br></div><div class="gmail_quote">On Mon, Mar 8, 2010 at 2:11 PM, Oliver Smith <span dir="ltr"><<a href="mailto:osmith@playnet.com">osmith@playnet.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div bgcolor="#ffffff" text="#000000">
On 3/6/2010 8:04 PM, J Decker wrote:
<blockquote type="cite">
<pre>there is a foreach() operator...
</pre>
</blockquote>
Well, thanks for trying, but what I actually want to know is how to add
something to all the current targets <i>automatically</i> - as in
without specifying them by hand, and how to get the compiler flags etc
of a particular target so that I can <i>generate</i> a custom command
that matches the given target.<br>
<br>
get_file_component(pchbase ${PrecompiledHeader} NAME_WE)<br>
get_file_component(pchpath ${PrecompiledHeader} PATH)<br>
<br>
<b> foreach ( target in LISTS CMAKE_TARGET_LIST )</b><br>
<br>
set(pchname "${CMAKE_BINARY_DIR}/${pchbase}.${target}.h")<br>
<br>
get_target_properties(defines ${target} COMPILE_DEFINITIONS)<br>
get_target_properties(flags ${target} COMPILE_FLAGS)<br>
set_target_properties(${target} PROPERTIES COMPILE_FLAGS
"${flags} -include ${pchname} -Winvalid-pch")<br>
<br>
add_custom_command(${target} PRE_BUILD COMMAND<br>
"ln -s ${pchname} ${PrecompiledHeader}" <br>
"g++ ${defines} ${flags} -o ${pchname}.gch ${pchname}")<br>
)<br>
endforeach ()<br>
<br>
Marked in bold is the part I'm struggling with.<br>
<br>
- Oliver<br>
<br>
</div>
<br>_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.cmake.org/mailman/listinfo/cmake" target="_blank">http://www.cmake.org/mailman/listinfo/cmake</a><br></blockquote></div><br></div>