<div dir="ltr"><div><div>Hi Micha.<br><br></div>I understand how the original works, and I know I can work around it with a separate buildsystem (using e.g. ExternalProject_Add() or ctest --build-and-test). I was just wondering: since CMake generates a .sln (or Makefile) in the subdirectory (because I put a project() call in there), does it somehow offer a way to build the 'all' target from that solution (or Makefile)?<br><br></div>Petr<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Dec 5, 2014 at 3:42 PM, Micha Hergarden <span dir="ltr"><<a href="mailto:micha.hergarden@gmail.com" target="_blank">micha.hergarden@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>Hello Petr,<br><br></div>In your example the original make command simply states that it should switch to the example_dir and build an 'all' target there. It does not specify how this target is build. That is the part that should end up in your custom command. You can name the command 'examples', set WORKING_DIR to the example_dir and then perform the steps needed to build. If you want that to be a separate cmake based solution, you may want to take a look at the external_project module.<br><br></div>With kind regards,<br></div>Micha Hergarden<br></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">2014-12-05 11:46 GMT+01:00 Petr Kmoch <span dir="ltr"><<a href="mailto:petr.kmoch@gmail.com" target="_blank">petr.kmoch@gmail.com</a>></span>:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr"><div><div><div><div><div>Hi all.<br><br>I'm converting a small Makefile-based project to CMake. The project is not mine, so I am trying to match its existing buildsystem as closely as possible.<br><br>One of the rules in the original Makefile is (simplified) as follows:<br><br></div>examples: all<br></div>  make -C example_dir all<br><br></div>This gives a target 'examples' in the top-level Makefile, which is not included in 'all', but can be used to build all examples. I would like to achieve something similar with CMake.<br><br></div>I added example_dir/CMakeLists.txt, which includes a project() command and defines all the targets for example executables. In the toplevel CMakeList, I did this:<br><br></div># Add the subdirectory but don't include its targets by default<br><div>add_subdirectory(example_dir EXCLUDE_FROM_ALL)<br><br></div><div># Add a custom target to build all examples<br></div><div>add_custom_target(examples ???)<br><br>I'm stuck at the custom target. What I need for its command is a generator-agnostic equivalent for 'make -C example_dir all' (or 'make -f example_dir/Makefile all').<br><br></div><div>I tried 'cmake --build ${CMAKE_CURRENT_BINARY_DIR}/example_dir ...', but this complains that example_dir does not contain a CMakeCache.txt (which is correct of course, it's not the toplevel directory). Then I remembered that build_command() can be used to get a command line to build a project; unfortunately, in 3.0 and later, this just returns 'cmake --build ...' and so is unusable in my situation.<br><br></div><div>Is there a way to query CMake for the native command line (or something else) I could use to build the CMake-generated buildsystem in the subdirectory? I thought a bit about CMAKE_MAKE_PROGRAM, but that doesn't tell me anything about what arguments I should pass, and it's not even set on Visual Studio generators.<br><br></div><div>As a workaround, I thought of not doing add_subdirectory() at all and instead adding a custom target with 'ctest --build-and-test ...', but I would prefer to configure & generate the two directories together. I plan to eventually add install() rules for the examples as well, and the examples also use one of the targets from the toplevel cmakelist in add_custom_command(OUTPUT ...), so I would really like to keep them as one CMake system. Is there a way to do so?<span><font color="#888888"><br><br></font></span></div><span><font color="#888888"><div>Petr<br></div></font></span></div>
<br></div></div><span class="">--<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></span></blockquote></div><br></div>
</blockquote></div><br></div>