<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jul 6, 2018 at 9:49 PM, Mads Andreasen <span dir="ltr"><<a href="mailto:temp1@andreasen.cc" target="_blank">temp1@andreasen.cc</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">Hi Craig<div><br></div><div>Thanks for getting back to me. </div><div>I was hoping to be able to build the library with fetch content, so that the FindXXX would automatically work.</div></div></blockquote><div><br></div><div>If you want to use FindXXX, you need to use ExternalProject and a superbuild structure. The things that FindXXX modules look for don't exist until after they have been built. It sounds like a superbuild is really what you should be doing here.</div><div><br></div><div>If you choose to incorporate jsoncpp via add_subdirectory() instead, then instead of using FindXXX modules you can refer directly to the CMake target names that jsoncpp defines. This is one of the main reasons for FetchContent and using add_subdirectory(), since you can directly refer to things that CMake knows about instead of having to find anything.</div><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><br></div><div>If I use your proposed approach:</div><div><span class="">
<pre style="white-space:pre-wrap;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;color:rgb(0,0,0);margin-top:0px;margin-bottom:0px">if(NOT<span style="color:rgb(190,192,194)"> </span><span style="color:rgb(34,34,34);font-family:monospace,monospace;white-space:normal">jsoncpp</span>_POPULATED)</pre><pre style="white-space:pre-wrap;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;color:rgb(0,0,0);margin-top:0px;margin-bottom:0px"><span style="color:rgb(190,192,194)"> </span>FetchContent_Populate(<span style="color:rgb(34,34,34);font-family:monospace,monospace;white-space:normal">jsoncpp</span>)</pre><pre style="white-space:pre-wrap;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;color:rgb(0,0,0);margin-top:0px;margin-bottom:0px"><span style="color:rgb(190,192,194)"> </span>add_subdirectory(${<span style="color:rgb(34,34,34);font-family:monospace,monospace;white-space:normal">jsoncpp</span>_<wbr>SOURCE_DIR}<span style="color:rgb(190,192,194)"> </span>${<span style="color:rgb(34,34,34);font-family:monospace,monospace;white-space:normal">jsoncpp</span>_BINARY_DIR})</pre><pre style="white-space:pre-wrap;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;color:rgb(0,0,0);margin-top:0px;margin-bottom:0px">endif()</pre>
<div><br></div></span>Should I then set the -DJSONCPP_XXX options when running the main cmake configure?</div><div><br clear="all"><div><div dir="ltr" class="m_-6576178401842960890gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>Best regards,<br>Mads</div></div></div></div><br></div></div><div class="HOEnZb"><div class="h5"><br><div class="gmail_quote"><div dir="ltr">On Fri, Jul 6, 2018 at 12:41 PM Craig Scott <<a href="mailto:craig.scott@crascit.com" target="_blank">craig.scott@crascit.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jul 6, 2018 at 8:25 PM, Mads Andreasen <span dir="ltr"><<a href="mailto:temp1@andreasen.cc" target="_blank">temp1@andreasen.cc</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>I am trying to work with FetchContent in cmake 3.11.</div><div>I want to use the jsoncpp library and use FetchContent to get and build it.</div></div></blockquote><div><br></div><div>FetchContent can only download it. You need to build it as a separate step (you should avoid building things during the configure phase as much as possible). The expected pattern is to add the downloaded contents to your existing build via add_subdirectory(). If you want to keep the build isolated from your main build, then use ExternalProject directly rather than FetchContent.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><br></div><div>I also want to configure the jsoncpp build with some cmake arguments and I can't seem to get that right.</div><div><br></div><div>My CMakeLists.txt looks like this:</div><div>******************************<wbr>******************************<wbr>**</div><div><div>cmake_minimum_required(VERSION 3.11)</div><div>project(Foo)</div><div><br></div><div>include(FetchContent)</div><div><br></div><div>FetchContent_Declare(jsoncpp</div><div> <span style="white-space:pre-wrap"> </span>URL "c:/project/jsoncpp-src"</div><div> <span style="white-space:pre-wrap"> </span>CMAKE_ARGS "-DJSONCPP_WITH_CMAKE_PACKAGE=<wbr>ON;-DJSONCPP_WITH_PKGCONFIG_<wbr>SUPPORT=OFF"</div><div>)</div><div><br></div><div>FetchContent_Populate(jsoncpp)</div><div><br></div><div>add_executable(Foo main.cpp)</div></div><div>******************************<wbr>******************************<wbr>**</div></div></blockquote><div><br></div><div>The configure, build, test and install steps of ExternalProject do not apply to FetchContent, that's why CMAKE_ARGS has no effect.</div><div><br></div><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><br></div><div><br></div><div>FetchContent downloads and configures the jsoncpp as an ExternalProject.</div></div></blockquote><div><br></div><div>No, it only downloads, not configures.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>That part looks like this:</div><div>******************************<wbr>***************</div><div><div>ExternalProject_Add(jsoncpp-<wbr>populate</div><div> "UPDATE_DISCONNECTED" "False" "URL" "c:/project/jsoncpp-src" "CMAKE_ARGS" "-DJSONCPP_WITH_CMAKE_PACKAGE=<wbr>ON" "-DJSONCPP_WITH_PKGCONFIG_<wbr>SUPPORT=OFF"</div><div> SOURCE_DIR "C:/temp/foo/build/_deps/<wbr>jsoncpp-src"</div><div> BINARY_DIR "C:/temp/foo/build/_deps/<wbr>jsoncpp-build"</div><div> CONFIGURE_COMMAND ""</div><div> BUILD_COMMAND ""</div><div> INSTALL_COMMAND ""</div><div> TEST_COMMAND ""</div><div>)</div></div><div>******************************<wbr>*************************</div><div><br></div><div>For the external project - the CMAKE_ARGS are no longer a list, but individual arguments.</div><div><br></div><div>I have tried different things, like escaping the ; with \\; and stuff like that, and I can't get it to work.</div><div>I'm thinking there is something obvious I am missing?</div></div></blockquote><div><br></div><div>Assuming jsoncpp doesn't assume it is a top level project (I haven't checked), the canonical pattern as <a href="https://cmake.org/cmake/help/latest/module/FetchContent.html#overview" target="_blank">explained in the docs</a> would be:</div><div><br></div><div><div><font face="monospace, monospace">FetchContent_Declare(jsoncpp</font></div><div><font face="monospace, monospace"> <span style="white-space:pre-wrap"> </span>URL "c:/project/jsoncpp-src"</font></div><div><font face="monospace, monospace">)<br></font></div><div><font face="monospace, monospace"><br></font></div><div><pre style="color:rgb(0,0,0);margin-top:0px;margin-bottom:0px">FetchContent_GetProperties(<span style="color:rgb(34,34,34);font-family:monospace,monospace;white-space:normal">jso<wbr>ncpp</span>)</pre><pre style="color:rgb(0,0,0);margin-top:0px;margin-bottom:0px">if(NOT<span style="color:rgb(190,192,194)"> </span><span style="color:rgb(34,34,34);font-family:monospace,monospace;white-space:normal">jsoncpp</span>_POPULATED)</pre><pre style="color:rgb(0,0,0);margin-top:0px;margin-bottom:0px"><span style="color:rgb(190,192,194)"> </span>FetchContent_Populate(<span style="color:rgb(34,34,34);font-family:monospace,monospace;white-space:normal">jsoncpp</span>)</pre><pre style="color:rgb(0,0,0);margin-top:0px;margin-bottom:0px"><span style="color:rgb(190,192,194)"> </span>add_subdirectory(${<span style="color:rgb(34,34,34);font-family:monospace,monospace;white-space:normal">jsoncpp</span>_<wbr>SOURCE_DIR}<span style="color:rgb(190,192,194)"> </span>${<span style="color:rgb(34,34,34);font-family:monospace,monospace;white-space:normal">jsoncpp</span>_BINARY_DIR})</pre><pre style="color:rgb(0,0,0);margin-top:0px;margin-bottom:0px">endif()</pre><pre style="color:rgb(0,0,0);margin-top:0px;margin-bottom:0px"><br></pre></div></div></div><div>The reason why FetchContent has all but download steps disabled is the projects should avoid doing time-consuming things during the configure stage. A configure stage will be inherently non-parallel as well, so it hurts you twice. Build steps should be deferred to the build stage as much as possible. If you find yourself wanting to pull some external project's build earlier into the configure stage, chances are you really should be using a superbuild if you truly need a build to be complete before the configure logic of a different project is executed.</div><div><br></div>-- <br><div class="m_-6576178401842960890m_4235703368256638002gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr">Craig Scott<br><div>Melbourne, Australia</div><div><a href="https://crascit.com" target="_blank">https://crascit.com</a><br></div></div></div></div></div></div></div>
</div></div>
</blockquote></div>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr">Craig Scott<br><div>Melbourne, Australia</div><div><a href="https://crascit.com" target="_blank">https://crascit.com</a><br></div></div></div></div></div></div></div>
</div></div>