<div dir="ltr">Thank you for the clarifications Craig! The confusion mainly stemmed from ${Catch2_SOURCE_DIR} where 'Catch2' should have been lowercase. I had originally started with the name 'catch' (which would explain why I accidentally left it unchanged in the _GetProperties function) but when that didn't work, I started assuming that perhaps it was conflicting with the actual library. It was all downhill from there :)<div><br></div><div>After your suggestions, I was successfully able to get it to work. For future reference for anyone stumbling on this answer, here's a minimum example of a working version: <a href="https://github.com/samaursa/cmake_fetch_content" target="_blank">https://github.com/samaursa/cmake_fetch_content</a></div><div dir="ltr"><div dir="ltr"><br></div><div dir="ltr"><span style="color:rgb(33,33,33)">>> I'm a little surprised CMake didn't complain about that, it does for me when I tested this just now</span><br></div><div dir="ltr"><div><br></div></div></div><div dir="ltr"><div dir="ltr"><div><div>CMake did not warn me about it. I am on CMake Version 3.11.0-rc3. It would be great if this warning could be emphasized by CMake as without it, it is difficult to tell what went wrong since `target_link_libraries` also fails and I simply get compile errors for missing headers.</div></div></div></div><div dir="ltr"><br><div class="gmail_quote"><div dir="ltr">On Sun, Mar 11, 2018 at 8:55 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">Thanks for trying out the new FetchContent module. Comments on your question interspersed below.<div><br><div class="gmail_extra"><br><div class="gmail_quote"></div></div></div></div><div dir="ltr"><div><div class="gmail_extra"><div class="gmail_quote">On Mon, Mar 12, 2018 at 11:02 AM, Saad Khattak <span dir="ltr"><<a href="mailto:saadrustam@gmail.com" target="_blank">saadrustam@gmail.com</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 would like to know how to use the FetchContent properly so that I can link against downloaded (CMake enabled) projects. I have looked at the CMake docs, which although are quite thorough, almost always fail to list a complete example which is incredibly crucial to get up and running quickly.</div><div><br></div><div>With ExternalProject_Add, we use add_dependencies(...) but that doesn't seem to be the case for FetchContent. Since I can immediately call add_subdirectory(...), I assumed that I can simply link to the library. But that doesn't seem to do anything.</div></div></blockquote><div><br></div></div></div></div></div><div dir="ltr"><div><div class="gmail_extra"><div class="gmail_quote"><div>This is indeed how it should work. After you've called add_subdirectory(), the targets defined by the project being added should be immediately available just like any other target your own project would define.</div></div></div></div></div><div dir="ltr"><div><div class="gmail_extra"><div class="gmail_quote"><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>Here's my CMakeLists.txt<br></div><div>``````````````````````````````````````````````````````````````</div><div><div>cmake_minimum_required(VERSION 3.5)</div></div></div></blockquote><div><br></div></div></div></div></div><div dir="ltr"><div><div class="gmail_extra"><div class="gmail_quote"><div><div class="gmail_quote">Your minimum CMake version will be 3.11 if you want to use FetchContent, so consider specifying that as the minimum version here.</div></div></div></div></div></div><div dir="ltr"><div><div class="gmail_extra"><div class="gmail_quote"><div><font face="monospace, monospace"><br></font></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><div>project(testProj)<br></div><div><br></div><div>include(FetchContent)</div><div><br></div><div>FetchContent_Declare(</div><div> Catch2</div><div> GIT_REPOSITORY "<a href="https://github.com/catchorg/Catch2" target="_blank">https://github.com/catchorg/Catch2</a>"</div><div> TEST_COMMAND ""</div><div> )</div></div></div></blockquote><div><br></div></div></div></div></div><div dir="ltr"><div><div class="gmail_extra"><div class="gmail_quote"><div>As stated in the docs, TEST_COMMAND will be ignored, so don't set it here. FetchContent only downloads, it doesn't build (you're in control of that, see further comments below). The ExternalProject_Add() docs also recommend you set GIT_TAG to the specific git hash you want to use (apart from being more robust, it saves having to contact the remote each time CMake is run after it has been cloned). FetchContent delegates all downloading to ExternalProject, so the comments apply here as well.</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><div><br></div><div>FetchContent_GetProperties(catch)</div></div></div></blockquote><div><br></div><div>This needs to be the same as the first argument to FetchContent_Declare() above, i.e. Catch2</div></div></div></div></div><div dir="ltr"><div><div class="gmail_extra"><div class="gmail_quote"><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><div>if(NOT Catch2_POPULATED)</div><div> FetchContent_Populate(Catch2)</div><div> add_subdirectory(${Catch2_SOURCE_DIR} ${Catch2_BINARY_DIR})</div></div></div></blockquote><div><br></div></div></div></div></div><div dir="ltr"><div><div class="gmail_extra"><div class="gmail_quote"><div>The documentation for the FetchContent_Populate() function state that the variable names use lowercased names of the content name (i.e. catch2_SOURCE_DIR rather than Catch2_SOURCE_DIR), so both of these variables used here will be empty. I'm a little surprised CMake didn't complain about that, it does for me when I tested this just now. Same for the variable name used in the if test (i.e. use catch2_POPULATED rather than Catch2_POPULATED).</div><div><br></div><div>The reason for the lowercasing is that it was found during the 2 years or so when we were dog-fooding this module that while people usually got the name right, there would be variations in upper/lowercase which made things less reliable.</div></div></div></div></div><div dir="ltr"><div><div class="gmail_extra"><div class="gmail_quote"><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><div>endif()</div><div><br></div><div>add_executable(testExe main.cpp)</div><div><br></div><div>target_link_libraries(testExe Catch2)</div></div></div></blockquote><div><br></div></div></div></div></div><div dir="ltr"><div><div class="gmail_extra"><div class="gmail_quote"><div>If the Catch2 project defines a library called Catch2, then this line should work fine once you fix the above problems. I think you want Catch rather than Catch2 though.</div></div></div></div></div><div dir="ltr"><div><div class="gmail_extra"><div class="gmail_quote"><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>CMake populates Catch2 with Catch2-NOTFOUND.</div><div><br></div><div>So, my question is, how do I link against projects added through FetchContent?</div></div></blockquote><div><br></div><div><br></div><div><br></div></div></div></div></div><div dir="ltr"><div><div class="gmail_extra"><br clear="all"><div><br></div>-- <br><div class="m_-6687787775736403746m_-3620813781744699546m_6324426460027950879gmail_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></div></blockquote></div></div></div>