<div dir="ltr"><div class="gmail_default" style="font-family:"trebuchet ms",sans-serif;font-size:small"><div class="gmail_default">I found this solution helpful: </div><div class="gmail_default">  <a href="https://crascit.com/2015/07/25/cmake-gtest" target="_blank">https://crascit.com/2015/07/<wbr>25/cmake-gtest</a></div><div class="gmail_default">It is unfortunate that CMake doesn't have a proper way to accomplish this.</div></div><div class="gmail_extra">--James</div><div class="gmail_extra"><br></div><div class="gmail_extra">
<br><div class="gmail_quote">On Thu, Jan 5, 2017 at 12:21 PM, Matthew Woehlke <span dir="ltr"><<a href="mailto:matthew.woehlke@kitware.com" target="_blank">matthew.woehlke@kitware.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span>On 2017-01-05 05:10, aishwarya selvaraj wrote:<br>
> Thanks for feedback :<br>
><br>
>> IF (${ARMADILLO} STREQUAL “ARMADILLO-NOTFOUND”)<br>
>>   # do what you want<br>
>> ENDIF ()<br>
> ​<br>
> I tried this way of writing :<br>
><br>
> IF (${ARMADILLO} STREQUAL "ARMADILLO-NOTFOUND")<br>
>     include(ExternalProject)<br>
>     ExternalProject_Add(armadillo<br>
>     URL <a href="https://github.com/lsolanka/armadillo/archive/master.zip" rel="noreferrer" target="_blank">https://github.com/lsolanka/ar<wbr>madillo/archive/master.zip</a><br>
>      PREFIX ${CMAKE_CURRENT_BINARY_DIR}/ar<wbr>madillo-latest)<br>
> ENDIF()<br>
><br>
> and<br>
><br>
> IF (ARMADILLO STREQUAL ARMADILLO-NOTFOUND)<br>
>    include(ExternalProject)<br>
>    MESSAGE(STATUS "Trying to install armadillo...")<br>
>     ExternalProject_Add(armadillo<br>
>     URL <a href="https://github.com/lsolanka/armadillo/archive/master.zip" rel="noreferrer" target="_blank">https://github.com/lsolanka/ar<wbr>madillo/archive/master.zip</a><br>
>     PREFIX ${CMAKE_CURRENT_BINARY_DIR}/ar<wbr>madillo-latest)<br>
> ENDIF()<br>
<br>
</span>`if(NOT ARMADILLO)` is probably better...<br>
<span><br>
> ​But both of them gave me an error :<br>
</span><span>>   CMake Error: The following variables are used in this project, but<br>
>   they are set to NOTFOUND. Please set them or make sure they are set<br>
>   and tested correctly in the CMake files:<br>
>   ARMADILLO<br>
>     linked by target "tsm" in directory /home/computing9/TSM_cmake<br>
>   SNDFILE<br>
>     linked by target "tsm" in directory /home/computing9/TSM_cmake<br>
<br>
</span>Ah... I was mostly replying to Parag; I hadn't actually looked that<br>
closely at your original problem.<br>
<br>
What you're trying to do is similar to a "superbuild" with optional<br>
components. The usual way to do this is to treat *your own project* as<br>
one of several external projects, so that the "superbuild" consists<br>
solely of external projects. Something like:<br>
<br>
  set(mydeps)<br>
  if(NOT armadillo)<br>
    externalproject_add(armadillo ...)<br>
    list(APPEND mydeps armadillo<br>
  endif()<br>
  # similar for other externals<br>
  externalproject_add(myproject ... DEPENDS ${mydeps})<br>
<br>
This way, by the time your project configures, the library exists.<br>
(You'll probably end up looking for the library twice; once in the<br>
superbuild to decide whether to build it, and again in your project<br>
proper where you'll a) assume it exists and hard error otherwise, and b)<br>
want to specify as an additional search path where the superbuild will<br>
produce it.)<br>
<br>
Without this, trying to set up the rules so that you can both link the<br>
library that will be created, and also get the dependencies correct so<br>
that the build knows how to produce it when needed, is probably going to<br>
be tricky. (Read: I'm not convinced it's impossible, but I've never seen<br>
someone actually doing this and wouldn't recommend it.)<br>
<br>
An alternative that may work is to set up the externals as subprojects<br>
and have CMake fetch them at configure time if they are needed, and then<br>
incorporate their builds directly in your own build (i.e. using<br>
add_subdirectory rather than externalproject_add); then you can link to<br>
the library target names when you build them yourself, and everything<br>
will work.<br>
<br>
p.s. I don't recommend always obtaining the current master of externals.<br>
It's usually safer to pick a SHA and bump it as needed, so that you are<br>
insulated against breaking changes upstream. I'm also not sure why you<br>
are fetching snapshots instead of just using the git repositories directly.<br>
<br>
--<br>
Matthew<br>
--<br>
<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" 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" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/CMak<wbr>e_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" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/su<wbr>pport.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/co<wbr>nsulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/tr<wbr>aining.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensou<wbr>rce/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/cmake" rel="noreferrer" target="_blank">http://public.kitware.com/mail<wbr>man/listinfo/cmake</a></blockquote></div><br></div></div>