<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p style="margin-top:0;margin-bottom:0">Thanks Craig,</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">we are already doing roughly that, plus some custom logic we built around options to be able to forward them to the second CMake process.
<br>
</p>
<p style="margin-top:0;margin-bottom:0">It's a bit more complex for us, but the concepts are the same.</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">The problem is just being able to use targets for the version of the executables compiled for the host, instead of using find_program or hardcoding paths like you do at step (e) in your StackOverflow answer.</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">It wouldn't be that important if all people using our internal CMake API were also CMake experts, but unfortunately we have lots of baffled developers by having to call "find_program()" and then variables, instead of
 "find_package(pkg REQUIRED<span class="n"> NO_CMAKE_FIND_ROOT_PATH</span>)" and then use an imported target. Also, this is asymmetrical when non-crosscompiling, which adds more logic than necessary in several places.</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">Cheers,<br>
</p>
<p style="margin-top:0;margin-bottom:0">Matteo Settenvini<br>
</p>
<div id="Signature"><br>
</div>
</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Craig Scott <craig.scott@crascit.com><br>
<b>Sent:</b> Thursday, July 12, 2018 12:00:18 AM<br>
<b>To:</b> Settenvini, Matteo<br>
<b>Cc:</b> cmake@cmake.org<br>
<b>Subject:</b> Re: [CMake] Cannot import a project twice when cross compiling (as host-tool and for the target arch)</font>
<div> </div>
</div>
<meta content="text/html; charset=utf-8">
<div>
<div dir="ltr">Not quite sure if it fits your use case, but we use a technique at work basically as described in the following:
<div><br>
</div>
<div><a href="https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F36084785%2Fbuilding-a-tool-immediately-so-it-can-be-used-later-in-same-cmake-run&data=01%7C01%7C%7C19358ac4692f4ef2cce208d5e779b1f5%7C6d4034cd72254f72b85391feaea64919%7C1&sdata=xJ%2FHdGlj4O%2FRulWQNQY6nWhpodk3sBpiDM6EucQJXZk%3D&reserved=0" originalsrc="https://stackoverflow.com/questions/36084785/building-a-tool-immediately-so-it-can-be-used-later-in-same-cmake-run" shash="E4Xhz69vkQSaL8JOQGTRRe3XqrO992+f2tSmOf1mklMZx9POI+9AHQ7cM070V10ZeqLbi2NJwM8qPTQkngpJENBjD2+BPiyWgeH3xlwr34sldP7zDW7HRGmyDAqHvr+Yp3Na08XGeT1U3OtK7Uc5H+kXy7g8QeZR+betkq5BFK4=">https://stackoverflow.com/questions/36084785/building-a-tool-immediately-so-it-can-be-used-later-in-same-cmake-run</a></div>
<div><br>
</div>
<div>Your case sounds more complicated, but maybe the above technique might help if you can organise things that way.<br>
<div><br>
</div>
<div><br>
</div>
</div>
</div>
<div class="x_gmail_extra"><br>
<div class="x_gmail_quote">On Wed, Jul 11, 2018 at 10:54 PM, Settenvini, Matteo <span dir="ltr">
<<a href="mailto:matteo.settenvini@here.com" target="_blank">matteo.settenvini@here.com</a>></span> wrote:<br>
<blockquote class="x_gmail_quote" style="margin:0 0 0 .8ex; border-left:1px #ccc solid; padding-left:1ex">
Dear all,<br>
<br>
I have the following problem which I don't know how to best solve.<br>
Any help is appreciated.<br>
<br>
============== Use Case ==============<br>
<br>
Consider the following use case:<br>
<br>
* We are cross-compiling.<br>
* A certain project A depends on project B in two different ways:<br>
  - it uses an executable target from B to generate some files, e.g. a compiler.<br>
  - one of its libraries links against a library of B.<br>
<br>
We would like to be able to do (not possible with CMake at the moment):<br>
<br>
<br>
  find_package(B REQUIRED)<br>
  # use B::lib normally. When crosscompiling, it will be the one compiled for the target.<br>
<br>
  find_package(B REQUIRED NO_CMAKE_FIND_ROOT_PATH)<br>
  # use B::exe knowing that it will always run from the host system.<br>
<br>
<br>
This is for instance a use case we have for flatbuffers / protobuf.<br>
<br>
IMPORTED and ALIAS targets should not be global, or it should be<br>
possible to override them. Or else, it should be possible to<br>
dynamically specify a namespace when importing targets through<br>
find_package().<br>
<br>
I opened a bug at <a href="https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgitlab.kitware.com%2Fcmake%2Fcmake%2Fissues%2F18169&data=01%7C01%7C%7C19358ac4692f4ef2cce208d5e779b1f5%7C6d4034cd72254f72b85391feaea64919%7C1&sdata=O2F%2BX4iOCnF7HYxPFBkSobsrqxkyTIhkcFJ3fjeP81k%3D&reserved=0" originalsrc="https://gitlab.kitware.com/cmake/cmake/issues/18169" shash="lOrzgGksWR0JiW5Z2ulY5VVwD0Kxsn8oq7aaJdS3mHBCyPl2desKXReNwGlYIYFgdt0gxAt7B0T1FV+aNbszbzu92YV+8vGms3gSiO3pxewKrFgqhYSQgwwK2VIT0MwVLhfOxMv0ycriGG5L9hOJzsfUTNjNTOjpy7Fub/8vJaE=" rel="noreferrer" target="_blank">
https://gitlab.kitware.com/<wbr>cmake/cmake/issues/18169</a>,<br>
but it got closed as there are no plans to change the way CMake works.<br>
<br>
The issue contains also a test case, if you'd like to try it out.<br>
<br>
============== Problem ==============<br>
<br>
The user cannot import a project twice to get the appropriate targets<br>
when cross-compiling: once for the host architecture and once for the<br>
target architecture.<br>
<br>
Right now, the user needs to manually use e.g. find_program() instead<br>
of relying on installed locations, which can be annoying if the<br>
binaries are installed outside the environment PATH. This can be<br>
worked around, but we would like to use targets in place of<br>
find_program() or find_library() calls.<br>
<br>
The problem is much more apparent in big superbuilds where you have<br>
hundreds of projects brought together in one build and no control over<br>
components outside your own. It is too hard to ensure a stable<br>
configuration order (so that find_package() is always called for the<br>
host version before the target version, or vice-versa).<br>
<br>
============== Help needed ==============<br>
<br>
How would you solve the issue, so that different targets are available<br>
for both the version built for the host and target architectures?<br>
<br>
Note that sometimes these external projects are not under our control,<br>
and they come directly from upstream as git submodules. So we would<br>
like to touch them as little as possible.<br>
<br>
Bests,<br>
Matteo Settenvini<br>
-- <br>
<br>
Powered by <a href="https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.kitware.com&data=01%7C01%7C%7C19358ac4692f4ef2cce208d5e779b1f5%7C6d4034cd72254f72b85391feaea64919%7C1&sdata=Kii%2Bk7gLL8hCJ1ekpXIKmzjgSU1Gu76eciezF1YX8Yw%3D&reserved=0" originalsrc="http://www.kitware.com" shash="FpC0sx01niiFjZF7nFXZw/aANHVGyqN8sCQdmaWPi7gfXyBjwfAgb53Qw4luM/eFk6FedaOAnZFp5Ko7MmceM4YSA2mtXBD5YkSaLjTJEr/nSuoO1jMz9m9NMYUQw7fb9aN2RLvv2o8M9etnjT1zbqBWFoSIkHrZ+x0+DzNGPBY=" rel="noreferrer" target="_blank">
www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.cmake.org%2FWiki%2FCMake_FAQ&data=01%7C01%7C%7C19358ac4692f4ef2cce208d5e779b1f5%7C6d4034cd72254f72b85391feaea64919%7C1&sdata=VEtz1dYyQ3I82TmCoFiKFodBsgpirKbi6fHL9TePiGc%3D&reserved=0" originalsrc="http://www.cmake.org/Wiki/CMake_FAQ" shash="hemEMFwbjQlP80WNDGLlAHzpxgQd9MhQK75MjiFWgH7RSftKekfmQk0wueYSvl/VzVbB7fDXCZvK9NGip40hhyLSl8RS/6ab+qO8Vr2ox0Ov7et01TTZJlZHyyPisIFNHtR9KK4CPFJovhG4agIwQOCNGf9MBfZbnhSrp6gyWVU=" rel="noreferrer" target="_blank">
http://www.cmake.org/Wiki/<wbr>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="https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fcmake.org%2Fcmake%2Fhelp%2Fsupport.html&data=01%7C01%7C%7C19358ac4692f4ef2cce208d5e779b1f5%7C6d4034cd72254f72b85391feaea64919%7C1&sdata=vPD2YmT%2FnYsPmE7qZgv7jJVWyZu%2FtyzbGREeajdz8HM%3D&reserved=0" originalsrc="http://cmake.org/cmake/help/support.html" shash="Z6tZ6lGplv0J9tLHglv43A6IEUnh+H3dxbk0VN22GU2wMPQZOEKYnDB+joyC3kYdNAgv7qIz7707LyQGjUUgujTMhAnM73fpu9c5F41WGbtTIaBNPzGD9vjGHrOt1I0pvBLGThI5empowt6ORy/PeBxExca4t2e8O39cyI113EU=" rel="noreferrer" target="_blank">
http://cmake.org/cmake/help/<wbr>support.html</a><br>
CMake Consulting: <a href="https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fcmake.org%2Fcmake%2Fhelp%2Fconsulting.html&data=01%7C01%7C%7C19358ac4692f4ef2cce208d5e779b1f5%7C6d4034cd72254f72b85391feaea64919%7C1&sdata=WswwDS4Qm2H4%2ByA1xn5QyqZFoEaQmqXAw2lOEk1gC5Q%3D&reserved=0" originalsrc="http://cmake.org/cmake/help/consulting.html" shash="xQhXFLnu/G0Q0mPqVNkNh3pjdR4vRJ7wh9d6sa6slBIbqF1HTWB9Fiw2zDaQIUVoFy/54swjiq5P2B+YAc+ZFmLq8OIcpmaSyIWKjXG/2MyLvluEaIK7rghkNWk/p9FTviNpebbcP5xd3ie/hp3740IdpHZYi7e6yMah4UMDg8E=" rel="noreferrer" target="_blank">
http://cmake.org/cmake/help/<wbr>consulting.html</a><br>
CMake Training Courses: <a href="https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fcmake.org%2Fcmake%2Fhelp%2Ftraining.html&data=01%7C01%7C%7C19358ac4692f4ef2cce208d5e779b1f5%7C6d4034cd72254f72b85391feaea64919%7C1&sdata=ZGAGTZ33EWW3H5ZPxC1iYekX0NSJJwIWXmR0ewrzUgE%3D&reserved=0" originalsrc="http://cmake.org/cmake/help/training.html" shash="ZH7areSVXDmen6MzU9SoXJhKfrltBoQ5LmGbuNaeMRm0tAU79+E+3YYNWIn5ACkaV8qnVcqxqY/FPylYGwQW6uMbZXCaOw8qhnbd9LVgqRHbb/Je518owDfGLo2xiOTR4lWZ0JIl3JmEQekQUz37dgGQuTIJVglfdFecPzkdscs=" rel="noreferrer" target="_blank">
http://cmake.org/cmake/help/<wbr>training.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.kitware.com%2Fopensource%2Fopensource.html&data=01%7C01%7C%7C19358ac4692f4ef2cce208d5e779b1f5%7C6d4034cd72254f72b85391feaea64919%7C1&sdata=jEPvMIis0QoqujH%2BAJ%2F8enyVInFAFAkDl%2FVw4QYJI2k%3D&reserved=0" originalsrc="http://www.kitware.com/opensource/opensource.html" shash="inn8lthP/cKLVY3N5AWRwWIrsA6XoAvAr331B3HGg9ltbKohAwMFQGSPZXNQ/ktt89VMnkdWmUfSLXV3GHKEds1ifGEWt7I6/e6O3CrE8gUWIG5x1Qtnh3uQYXu2TzcptA6Ect+bsQ7Rs1LgcIBrtwc1Htw7VrA+OhUaTst3luY=" rel="noreferrer" target="_blank">
http://www.kitware.com/<wbr>opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fcmake.org%2Fmailman%2Flistinfo%2Fcmake&data=01%7C01%7C%7C19358ac4692f4ef2cce208d5e779b1f5%7C6d4034cd72254f72b85391feaea64919%7C1&sdata=WeNcJxyEZQw8kw2ifdsDbW6uVBlNVSs2pmV%2BieHstnY%3D&reserved=0" originalsrc="https://cmake.org/mailman/listinfo/cmake" shash="XGGs8NcTKL+p0ypw4Y7aLGsnLDF4vWqM4idQYklZ+loPwXYAYEYQtLAD8OXt3NA6rcnBBUAaTjis4i1cpOdcUC9S5n4xKbwdKAJtHU6Ah7pDqsoyyxkR4QzgitSSbnVQ7vxEDhUmUUz0OQ5+yVrdHn/EdNezDLj5DSyuwX85/W8=" rel="noreferrer" target="_blank">https://cmake.org/mailman/<wbr>listinfo/cmake</a><br>
</blockquote>
</div>
<br>
<br clear="all">
<div><br>
</div>
-- <br>
<div class="x_gmail_signature">
<div dir="ltr">
<div>
<div dir="ltr">
<div>
<div dir="ltr">Craig Scott<br>
<div>Melbourne, Australia</div>
<div><a href="https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fcrascit.com&data=01%7C01%7C%7C19358ac4692f4ef2cce208d5e779b1f5%7C6d4034cd72254f72b85391feaea64919%7C1&sdata=HZ7nPd1P%2Fgd8SrsysnKG%2BHa5sxd1H5BDJWfiqt%2FJvNg%3D&reserved=0" originalsrc="https://crascit.com" shash="USVeNMVd8B03OGARcAWqLzMlsxfFq+wweHpaFkW1U3FNSzqRqRVDEpQV9qyDJzcjvk2+8FIa4hirr4xellixMAXlAIzVwILZX+pgEPviOWdqJ/JtgZxIQCDrfF85UsIJo2rAeLWu/cRU7pndZaqebvcPySJmtSWjlkg5a0x+OI0=" target="_blank">https://crascit.com</a><br>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>