<div dir="ltr">Isn't it as smiple as <div><br></div><div>add_subdirectory( examples_dir ) which has it's own CMakeLists?</div><div>Does it really have to build as an extra step or would</div><div><br></div><div>OPTION( BUILD_EXAMPLES "Build Examples?" ON )</div><div>....</div><div>if( BUILD_EXAMPLES) </div><div>add_subdirectory( examples_dir) </div><div>endif( BUILD_EXAMPLES) </div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Dec 5, 2014 at 7:41 AM, Petr Kmoch <span dir="ltr"><<a href="mailto:petr.kmoch@gmail.com" target="_blank">petr.kmoch@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div><div><div><div><div>OK, sorry for misunderstanding. But then I don't have a target like this. Basically, I am trying to create a custom target that would do this:<br><br></div># When using Makefile generator<br></div><div>add_custom_target(<br>  examples<br></div>  COMMAND make -C example_dir all<br></div>  VERBATIM<br>)<br><br></div># When using vs2008 generator<br></div>add_custom_target(<br></div>  examples<br></div>  COMMAND devenv Examples.sln /Build /Project:ALL_BUILD /ProjectConfig:$<CONFIG><br></div>  WORKING_DIRECTORY example_dir<br></div>  VERBATIM<br><div><div><div><div>)<br><br></div><div># When using vs2010 generator, use msbuild<br></div><div># etc...<br><br></div><div>without having to hardcode the logic (CMake must have this info inside somewhere). So I am effectively trying to *create* the target 'examples'.<br><br></div><div>My current solution is to make the custom target empty and have it depend on all the targets in example_dir. But this has two consequences I don't like:<br></div><div>1. I have to collect the target names in example_dir/CMakeLists.txt, as it has to communicate them to its parent<br></div><div>2. Being dependecies, the targets from example_dir show up in the toplevel solution file/Makefile. I was trying to prevent that.<br><br></div><div>I looked at the commit message which changed build_command() from returning the native command line to returning cmake --build, at it mentions the fact that sometimes, the native tool has to be selected based on the contents of the solution (devenv instead of msbuild when ifort is involved). So I guess the only way to get what I want would be with a generator expression (one which does not currently exist).<br><br></div><div>I guess I'll stick to my workaround with dependencies. But thanks for your help.<span class="HOEnZb"><font color="#888888"><br></font></span></div><span class="HOEnZb"><font color="#888888"><div><br></div><div>Petr<br></div></font></span></div></div></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Dec 5, 2014 at 4:19 PM, David Cole <span dir="ltr"><<a href="mailto:DLRdave@aol.com" target="_blank">DLRdave@aol.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">No, I meant exactly what I said.<br>
<br>
--target takes a CMake target name.<br>
<br>
<br>
HTH,<br>
D<br>
<div><div><br>
<br>
<br>
On Fri, Dec 5, 2014 at 9:23 AM, Petr Kmoch <<a href="mailto:petr.kmoch@gmail.com" target="_blank">petr.kmoch@gmail.com</a>> wrote:<br>
> I assume you actually meant 'cmake --build . --target example_dir', the name<br>
> of the directory. 'examples' is the name of the custom target; if that<br>
> target's command was to build itself, I believe it would become a fork bomb.<br>
><br>
> Anyway, I tried it with the directory name, it doesn't work. I'm generating<br>
> with VS2008, and devenv was complaining about "Invalid project." Which kind<br>
> of makes sense, there is no 'example_dir' project in the solution.<br>
><br>
> On Fri, Dec 5, 2014 at 2:59 PM, David Cole <<a href="mailto:DLRdave@aol.com" target="_blank">DLRdave@aol.com</a>> wrote:<br>
>><br>
>> Try:<br>
>><br>
>> cmake --build . --target examples<br>
>><br>
>> (where "." represents the current working directory, and assumes<br>
>> you're in the top level build tree...)<br>
>><br>
>><br>
>> On Fri, Dec 5, 2014 at 5:46 AM, Petr Kmoch <<a href="mailto:petr.kmoch@gmail.com" target="_blank">petr.kmoch@gmail.com</a>> wrote:<br>
>> > Hi all.<br>
>> ><br>
>> > I'm converting a small Makefile-based project to CMake. The project is<br>
>> > not<br>
>> > mine, so I am trying to match its existing buildsystem as closely as<br>
>> > possible.<br>
>> ><br>
>> > One of the rules in the original Makefile is (simplified) as follows:<br>
>> ><br>
>> > examples: all<br>
>> >   make -C example_dir all<br>
>> ><br>
>> > This gives a target 'examples' in the top-level Makefile, which is not<br>
>> > included in 'all', but can be used to build all examples. I would like<br>
>> > to<br>
>> > achieve something similar with CMake.<br>
>> ><br>
>> > I added example_dir/CMakeLists.txt, which includes a project() command<br>
>> > and<br>
>> > defines all the targets for example executables. In the toplevel<br>
>> > CMakeList,<br>
>> > I did this:<br>
>> ><br>
>> > # Add the subdirectory but don't include its targets by default<br>
>> > add_subdirectory(example_dir EXCLUDE_FROM_ALL)<br>
>> ><br>
>> > # Add a custom target to build all examples<br>
>> > add_custom_target(examples ???)<br>
>> ><br>
>> > I'm stuck at the custom target. What I need for its command is a<br>
>> > generator-agnostic equivalent for 'make -C example_dir all' (or 'make -f<br>
>> > example_dir/Makefile all').<br>
>> ><br>
>> > I tried 'cmake --build ${CMAKE_CURRENT_BINARY_DIR}/example_dir ...', but<br>
>> > this complains that example_dir does not contain a CMakeCache.txt (which<br>
>> > is<br>
>> > correct of course, it's not the toplevel directory). Then I remembered<br>
>> > that<br>
>> > build_command() can be used to get a command line to build a project;<br>
>> > unfortunately, in 3.0 and later, this just returns 'cmake --build ...'<br>
>> > and<br>
>> > so is unusable in my situation.<br>
>> ><br>
>> > Is there a way to query CMake for the native command line (or something<br>
>> > else) I could use to build the CMake-generated buildsystem in the<br>
>> > subdirectory? I thought a bit about CMAKE_MAKE_PROGRAM, but that doesn't<br>
>> > tell me anything about what arguments I should pass, and it's not even<br>
>> > set<br>
>> > on Visual Studio generators.<br>
>> ><br>
>> > As a workaround, I thought of not doing add_subdirectory() at all and<br>
>> > instead adding a custom target with 'ctest --build-and-test ...', but I<br>
>> > would prefer to configure & generate the two directories together. I<br>
>> > plan to<br>
>> > eventually add install() rules for the examples as well, and the<br>
>> > examples<br>
>> > also use one of the targets from the toplevel cmakelist in<br>
>> > add_custom_command(OUTPUT ...), so I would really like to keep them as<br>
>> > one<br>
>> > CMake system. Is there a way to do so?<br>
>> ><br>
>> > Petr<br>
>> ><br>
>> > --<br>
>> ><br>
>> > Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
>> ><br>
>> > Please keep messages on-topic and check the CMake FAQ at:<br>
>> > <a href="http://www.cmake.org/Wiki/CMake_FAQ" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
>> ><br>
>> > Kitware offers various services to support the CMake community. For more<br>
>> > information on each offering, please visit:<br>
>> ><br>
>> > CMake Support: <a href="http://cmake.org/cmake/help/support.html" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
>> > CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
>> > CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" target="_blank">http://cmake.org/cmake/help/training.html</a><br>
>> ><br>
>> > Visit other Kitware open-source projects at<br>
>> > <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
>> ><br>
>> > Follow this link to subscribe/unsubscribe:<br>
>> > <a href="http://public.kitware.com/mailman/listinfo/cmake" target="_blank">http://public.kitware.com/mailman/listinfo/cmake</a><br>
><br>
><br>
</div></div></blockquote></div><br></div>
</div></div><br>--<br>
<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</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>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
<br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" target="_blank">http://cmake.org/cmake/help/training.html</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>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/cmake" target="_blank">http://public.kitware.com/mailman/listinfo/cmake</a><br></blockquote></div><br></div>