<div dir="ltr">I assume you actually meant 'cmake --build . --target example_dir', the name of the directory. 'examples' is the name of the custom target; if that 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 with VS2008, and devenv was complaining about "Invalid project." Which kind of makes sense, there is no 'example_dir' project in the solution.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Dec 5, 2014 at 2:59 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">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>
<div><div class="h5"><br>
<br>
On Fri, Dec 5, 2014 at 5:46 AM, Petr Kmoch <<a href="mailto:petr.kmoch@gmail.com">petr.kmoch@gmail.com</a>> wrote:<br>
> Hi all.<br>
><br>
> I'm converting a small Makefile-based project to CMake. The project is 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 to<br>
> achieve something similar with CMake.<br>
><br>
> I added example_dir/CMakeLists.txt, which includes a project() command and<br>
> defines all the targets for example executables. In the toplevel 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 is<br>
> correct of course, it's not the toplevel directory). Then I remembered 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 ...' 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 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 plan to<br>
> eventually add install() rules for the examples as well, and the 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 one<br>
> CMake system. Is there a way to do so?<br>
><br>
> Petr<br>
><br>
</div></div>> --<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>
</blockquote></div><br></div>