<html><body><div style="font-family: times new roman, new york, times, serif; font-size: 12pt; color: #000000"><div>Thanks Angeliki. I will try to do something like this. In fact I forgot to mention that my target which collide comes from add_custom target() but I can apply the same principle. </div><div><br></div><div>To be more precise about the context, my projects have a target "unit_test" which is run tests each time I build (included in all) and a target "doc" to generate the documentation.<br></div><div><br></div><div>To answer to Jakub :<br></div><div><br></div><div>There are other subprojects which are modules needing my independent projects. like this:</div><div><br></div><div>Project<br>|--subrojectWithTargetCollision1<br>|--subrojectWithTargetCollision2</div><div>|--someOtherProject1</div><div>`--someOtherProject2</div><div><br></div><div>My independent projects are both under development and not stable yet.So, having a code repository containing both project is a convenient way to work with a fixed version (which will ensure that every project compile) and update when I want to.</div><div><br></div><div>May be add_subdirectory is not the way to go but it was handy to compile every project at once and link my programs with libraries in the project, without installing them (for testing purpose).</div><div><br></div><div>Thanks for your answers.<br></div><div>Regards,<br></div><div><br></div><div>Aurélien<br></div><div><br></div><hr id="zwchr"><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><b>De: </b>"Angeliki Chrysochou" <angeliki.chrysochou@gmail.com><br><b>À: </b>"Jakub Zakrzewski" <jzakrzewski@e2e.ch><br><b>Cc: </b>"Aurelien Richez" <aurelien.richez@inria.fr>, cmake@cmake.org<br><b>Envoyé: </b>Jeudi 27 Mars 2014 16:20:14<br><b>Objet: </b>Re: [CMake] target name collision<br><div><br></div><div dir="ltr"><div><div><div><div><div><div><div>Hi Aurelien,<br><div><br></div></div>Even though it is unsafe and not recommended, you could set policy CMP0002 to old so that cmake silently accepts non-unique target names like this:<br>
<br>cmake_policy(SET CMP0002 OLD)<br><div><br></div></div>I can't guarantee that your build will then work however. <br><div><br></div></div>Another option is to write your own wrapper to include the directory name using a macro or a function providing the name of the root project added by cmake using the variable CMAKE_PROJECT_NAME. Here is an example wrapper of add_library (I used "_" as a delimiter instead of "/"):<br>
<br></div>macro( my_add_library LIB_NAME LIB_TYPE SRC_FILES INC_FILES )<br>     add_library( ${CMAKE_PROJECT_NAME}_${LIB_NAME} ${LIB_TYPE} ${SRC_FILES} ${INC_FILES} )</div>endmacro()<br><div><br></div></div>Invoking it for a project with name ProjectA to create a shared library LibA would look like this, for example:<br>
<br></div>my_add_library(LibA SHARED src.cpp inc.h)<br><div><div><div><div><br></div><div>and would result to library name ProjectA_LibA.<br><div><br></div></div><div>A third solution is to set the target properties after adding the target. Here is an example for shared libraries in case you want to preserve the original prefix too:<br>
</div><div><br>set_target_properties(LibA PROPERTIES PREFIX "${CMAKE_SHARED_LIBRARY_PREFIX}${CMAKE_PROJECT_NAME}_" )<br><div><br></div></div><div>I hope it helps!<br><div><br></div></div><div>Best regards,<br></div><div>Angeliki<br><div><br></div>
</div><div><br></div></div></div></div></div><div class="gmail_extra"><br><div><br></div><div class="gmail_quote">On Thu, Mar 27, 2014 at 3:30 PM, Jakub Zakrzewski <span dir="ltr"><<a href="mailto:jzakrzewski@e2e.ch" target="_blank">jzakrzewski@e2e.ch</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">





<div lang="DE-CH">
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Is there a reason, why you treat your independent projects with add_directory() instead of making them external projects?<span style="text-decoration: underline;" data-mce-style="text-decoration: underline;"></span><span style="text-decoration: underline;" data-mce-style="text-decoration: underline;"></span></span></p>

<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><span style="text-decoration: underline;" data-mce-style="text-decoration: underline;"></span> <span style="text-decoration: underline;" data-mce-style="text-decoration: underline;"></span></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1f497d" lang="PL">--<span style="text-decoration: underline;" data-mce-style="text-decoration: underline;"></span><span style="text-decoration: underline;" data-mce-style="text-decoration: underline;"></span></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1f497d" lang="PL">Gruesse,<span style="text-decoration: underline;" data-mce-style="text-decoration: underline;"></span><span style="text-decoration: underline;" data-mce-style="text-decoration: underline;"></span></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1f497d" lang="PL">Jakub<span style="text-decoration: underline;" data-mce-style="text-decoration: underline;"></span><span style="text-decoration: underline;" data-mce-style="text-decoration: underline;"></span></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><span style="text-decoration: underline;" data-mce-style="text-decoration: underline;"></span> <span style="text-decoration: underline;" data-mce-style="text-decoration: underline;"></span></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><span style="text-decoration: underline;" data-mce-style="text-decoration: underline;"></span> <span style="text-decoration: underline;" data-mce-style="text-decoration: underline;"></span></span></p>
<div>
<div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"" lang="EN-US">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"" lang="EN-US"> CMake [mailto:<a href="mailto:cmake-bounces@cmake.org" target="_blank">cmake-bounces@cmake.org</a>]
<b>On Behalf Of </b>Aurelien Richez<br>
<b>Sent:</b> Donnerstag, 27. März 2014 14:58<br>
<b>To:</b> <a href="mailto:cmake@cmake.org" target="_blank">cmake@cmake.org</a><br>
<b>Subject:</b> [CMake] target name collision<span style="text-decoration: underline;" data-mce-style="text-decoration: underline;"></span><span style="text-decoration: underline;" data-mce-style="text-decoration: underline;"></span></span></p>
</div>
</div><div><div class="h5">
<p class="MsoNormal"><span style="text-decoration: underline;" data-mce-style="text-decoration: underline;"></span> <span style="text-decoration: underline;" data-mce-style="text-decoration: underline;"></span></p>
<div>
<div>
<p class="MsoNormal"><span style="">Hi,<span style="text-decoration: underline;" data-mce-style="text-decoration: underline;"></span><span style="text-decoration: underline;" data-mce-style="text-decoration: underline;"></span></span></p>
</div>
<div>
<p class="MsoNormal"><span style=""><span style="text-decoration: underline;" data-mce-style="text-decoration: underline;"></span> <span style="text-decoration: underline;" data-mce-style="text-decoration: underline;"></span></span></p>
</div>
<div>
<p class="MsoNormal"><span style="">I have two project that are independent and can be compiled on their own. I also have a bigger project which include these two project with add_subdirectory. However, these projects contain targets with the same
 names. As a consequence, cmake 2.8 complains with a message such as "another target with the same name already exists" when I try to generate the makefile.
<span style="text-decoration: underline;" data-mce-style="text-decoration: underline;"></span><span style="text-decoration: underline;" data-mce-style="text-decoration: underline;"></span></span></p>
</div>
<div>
<p class="MsoNormal"><span style=""><span style="text-decoration: underline;" data-mce-style="text-decoration: underline;"></span> <span style="text-decoration: underline;" data-mce-style="text-decoration: underline;"></span></span></p>
</div>
<div>
<p class="MsoNormal"><span style="">Isn't there a way to handle this situation which does not involve renaming the targets in the subproject ? Like an option to automatically add a prefix to target added from add_subdirectory (for instance, target
 "doc" in "subproject1" would become "subproject1/doc" in the upper project).<span style="text-decoration: underline;" data-mce-style="text-decoration: underline;"></span><span style="text-decoration: underline;" data-mce-style="text-decoration: underline;"></span></span></p>
</div>
<div>
<p class="MsoNormal"><span style=""><span style="text-decoration: underline;" data-mce-style="text-decoration: underline;"></span> <span style="text-decoration: underline;" data-mce-style="text-decoration: underline;"></span></span></p>
</div>
<div>
<p class="MsoNormal"><span style="">Thanks,<span style="text-decoration: underline;" data-mce-style="text-decoration: underline;"></span><span style="text-decoration: underline;" data-mce-style="text-decoration: underline;"></span></span></p>
</div>
<div>
<p class="MsoNormal"><span style=""><span style="text-decoration: underline;" data-mce-style="text-decoration: underline;"></span> <span style="text-decoration: underline;" data-mce-style="text-decoration: underline;"></span></span></p>
</div>
<div>
<p class="MsoNormal"><span style="">Aurélien Richez<span style="text-decoration: underline;" data-mce-style="text-decoration: underline;"></span><span style="text-decoration: underline;" data-mce-style="text-decoration: underline;"></span></span></p>
</div>
</div>
</div></div></div>
</div>

<br>--<br>
<br>
Powered by <a href="http://www.kitware.com" 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" 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" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" 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" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.cmake.org/mailman/listinfo/cmake" target="_blank">http://www.cmake.org/mailman/listinfo/cmake</a><br></blockquote></div><br></div>
</blockquote><div><br></div></div></body></html>