<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">---------- Forwarded message ----------<br>From: John Barbero Unenge <<a href="mailto:john.barbero.unenge@gmail.com">john.barbero.unenge@gmail.com</a>><br>To: <a href="mailto:cmake@cmake.org">cmake@cmake.org</a><br>Cc: <br>Date: Fri, 25 Sep 2015 11:58:03 +0200<br>Subject: [CMake] find_package for both debug and release with Visual Studio<br><div dir="ltr"><div><div><div>I'm tearing my hair out about how to include thrid party libraries in my cmake project. Currently I build Poco and a bunch of others that all generate their respective <LibName>Config.cmake which I use with find_package. I have a wrapping build script that builds all of my dependencies and package them separately for debug and release (I don't want to tweak their cmake-scripts unless I really really really need to because maintanance).<br><br></div>I thought I could just do:<br><br></div><span style="font-family:monospace,monospace">find_package(Foo<br>            HINTS "${CMAKE_SOURCE_DIR}/some/path/debug/libFoo/lib/cmake"<br>            REQUIRED<br>)<br>get_target_property(LIB_FOO_DEBUG lib_foo LOCATION)<br><br>find_package(Foo<br>            HINTS "${CMAKE_SOURCE_DIR}/some/path/release/libFoo/lib/cmake"<br>            REQUIRED<br>)<br>get_target_property(LIB_FOO_RELEASE lib_foo LOCATION)<br><br>set(LIB_FOO_LIBRARIES optimized "${LIB_FOO_RELEASE}" debug "${LIB_FOO_DEBUG}")<br><br>message("LIB_FOO_LIBRARIES: \"${LIB_FOO_LIBRARIES}\"")<br># Gives: </span><span style="font-family:monospace,monospace"><span style="font-family:monospace,monospace">LIB_FOO_LIBRARIES: "</span>optimized;C:/path/to/proj/some/path/debug/libFoo/lib/foo.lib;debug;C:/path/to/proj/some/path/debug/libFoo/lib/foo.lib"</span><br><br></div><div>It seems like the first call to find_package for target Foo is cached, whis I don't really want.<br></div><div><br></div><div>Am I going about this the wrong way? How do I properly work with 3rd party libraries with the Visual Studio generator?<br></div><div><br></div><div>Any pointers are greatly appreciated.<br></div><div><br><div><div><div><div dir="ltr">/ John</div></div></div>
</div></div></div>
</blockquote></div><br>Not sure if it will be relevant for you, but if the third party libraries you want to use are themselves built with CMake, you can make them part of your build directly. This has the following advantages in your scenario:</div><div class="gmail_extra"><br></div><div class="gmail_extra"><ul><li>They will inherit the same debug/release config as your main project.</li><li>No need to explicitly tell CMake where anything is because all targets in the third party library are part of the build. Instead of using find_package, you can just link directly to the targets by CMake target name.</li></ul>The trick for this is to download the source of the third party library at CMake time (caching it so it only downloads once) and then pull it in via add_subdirectory(). The technique is discussed here with GoogleTest as the example:<br></div><div class="gmail_extra"><br></div><div class="gmail_extra"><a href="http://crascit.com/2015/07/25/cmake-gtest/">http://crascit.com/2015/07/25/cmake-gtest/</a></div><div class="gmail_extra"><br></div><div class="gmail_extra">The technique uses ExternalProject to manage the download but it does so by invoking it as a script to get it to do its thing at CMake time rather than build time.<br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div>Craig Scott<br>Melbourne, Australia</div><div><a href="http://crascit.com" target="_blank">http://crascit.com</a></div></div></div>
</div></div>