<div dir="ltr"><div>Starting with CMake v3.11, it is now possible to aliasing an imported target. So you can have something like that:<br></div><div><br></div><div>if (BUILD_MY_LIB)</div><div>  add_library(my_lib SHARED ....)</div><div>  add_library(<span style="color:rgb(33,33,33)">MY_NAMESPACE::mylib</span><span style="color:rgb(33,33,33)"> ALIAS my_lib)</span></div><div>else()</div><div>  add_library(system_lib SHARED IMPORTED GLOBAL)</div><div>  set_property(TARGET system_lib PROPERTY IMPORTED_LOCATION /path/to/system/lib)</div><div>  add_library(<span style="color:rgb(33,33,33)">MY_NAMESPACE::mylib</span><span style="color:rgb(33,33,33)"> ALIAS system_lib)</span> </div><div>endif()<br></div><div><br></div><div>And, after you can use target <span style="color:rgb(33,33,33)">MY_NAMESPACE::mylib transparently...</span></div><div><span style="color:rgb(33,33,33)"><br></span></div></div><br><div class="gmail_quote"><div dir="ltr">Le jeu. 14 juin 2018 à 06:53, Andrew White <<a href="mailto:andrew.white@audinate.com">andrew.white@audinate.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I have a library that needs to be built on some platforms but on others is part of the OS.  I'd like to avoid putting "if platform" conditional code in the places it is used, but instead hide it away in my platform-specific code.<br>
<br>
One way to do this is define a variable mylib_targetname in each platform and add ${mylib_targetname} as a dependency.  It can be defined on some platforms and undefined on others.<br>
<br>
It feels cleaner if I could create an alias target MY_NAMESPACE::mylib and refer to that. This lets me define the dependency without making sure an environment variable is set, which feels more natural.  But in order to make this work I need a way to express that MY_NAMESPACE::mylib might be (legitimately) null on some platforms, and I can't figure out how to do this.<br>
<br>
Any ideas?<br>
<br>
--<br>
Andrew<br>
<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/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" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" 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" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="https://cmake.org/mailman/listinfo/cmake" rel="noreferrer" target="_blank">https://cmake.org/mailman/listinfo/cmake</a><br>
</blockquote></div>