<div dir="ltr"><div><div><div><div><div><div><div>Hi Aurelien,<br><br></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><br></div>I can't guarantee that your build will then work however. <br><br></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><br></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><br></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><br></div><div>I hope it helps!<br><br></div><div>Best regards,<br></div><div>Angeliki<br><br>
</div><div><br></div></div></div></div></div><div class="gmail_extra"><br><br><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 link="blue" vlink="purple" 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?<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1f497d" lang="PL">--<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1f497d" lang="PL">Gruesse,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1f497d" lang="PL">Jakub<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></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<u></u><u></u></span></p>
</div>
</div><div><div class="h5">
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal"><span style>Hi,<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style><u></u> <u></u></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.
<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style><u></u> <u></u></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).<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style>Thanks,<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style>Aurélien Richez<u></u><u></u></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>