<div dir="ltr"><div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Sun, Sep 30, 2018 at 2:28 AM Jan Wielemaker <<a href="mailto:jan@swi-prolog.org">jan@swi-prolog.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">Hi<br>
<br>
I'm converting a big project (SWI-Prolog) to cmake. Still a newbie wrt.<br>
cmake, but quite happy. There is one thing that I can't get done:<br>
install the system using symbolic links to the source tree. This is in<br>
this case really handy for developers.<br></blockquote><div><br></div><div>This would be very unusual. An installed project should not generally require that the sources it was built from remain around.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<br>
I've come as far as understanding:<br>
<br>
- The generator creates cmake_install.cmake<br>
- make/ninja/... install calls cmake -P cmake_install.cmake<br>
- This calls file(INSTALL ....)<br>
<br>
So, I thought I can<br>
<br>
- Add a file cmake_ln_install.cmake that<br>
- redefines file()<br>
- includes cmake_install.cmake<br></blockquote><div><br></div><div>You will likely find it more convenient to use <a href="https://cmake.org/cmake/help/latest/command/install.html#code">install(CODE)</a> or <a href="https://cmake.org/cmake/help/latest/command/install.html#script">install(SCRIPT)</a> to define commands to add to the install process rather than trying to work with cmake_install.cmake directly. Those two forms of the install() command are the recommended way to get your own code into the cmake_install.cmake file that CMake generates. At the moment, you would need to use execute_process() to invoke <font face="monospace, monospace">cmake -E create_symlink</font> to create the actual link within that code or script (see further below for state of the file() command for this).</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<br>
To redefine file(), I tried this to see whether this works:<br>
<br>
function(file)<br>
message("Calling file(${ARGN})")<br>
_file(${ARGN})<br>
endfunction()<br></blockquote><div><br></div><div>Overriding built-in functions is strongly discouraged. Apart from relying on undocumented CMake behavior, the above has the potential to result in infinite recursion. I recently wrote a blog article about this which explains in more detail:</div><div><br></div><div><a href="https://crascit.com/2018/09/14/do-not-redefine-cmake-commands/">https://crascit.com/2018/09/14/do-not-redefine-cmake-commands/</a><br></div><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<br>
But ... some of the file() calls contain empty strings ("") in the<br>
argument vector. All the rest works fine.<br>
<br>
On stack overflow [1], the suggestion was to use "${ARGN}", which<br>
indeed keeps the empty lists and works fine if the receiver is a<br>
function iterating over its argument vector. After downloading<br>
the cmake source it turns out file() is builtin (C++) and complains<br>
to require at least 2 arguments. I tried passing the first two<br>
as file(${arg1} ${arg2} "${ARGN}"), which would (I think) work for<br>
a user function, but doesn't for a builtin.<br>
<br>[1] <a href="https://stackoverflow.com/questions/52480737/pass-empty-strings-in-cmake" rel="noreferrer" target="_blank">https://stackoverflow.com/questions/52480737/pass-empty-strings-in-cmake</a> </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><br>
So, my question is<br>
<br>
- Is there a way to redefine a builtin function that passes<br>
empty strings correctly to the original?<br>
- If not, should this be considered a bug ...<br></blockquote><div><br></div><div>Builtin functions should not be redefined, so no, it is not considered a bug. ;)</div><div><br></div><div>I have a follow-up "part 2" article to the above one I linked, but it is still in preparation. It discusses other problems with trying to forward arguments using ARGN or ARGV, but some of the observations you've made here and in the linked stackoverflow article may also be relevant. If I get time, I'll try to see if I can incorporate some of the observations and behaviors you've raised.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">P.s. I'd also like to see the possibility to create symlinks<br>
in cmake, other than calling cmake -E ...<br></blockquote><div><br></div><div>There is already a feature request with discussion for that here:</div><div><br></div><div><a href="https://gitlab.kitware.com/cmake/cmake/issues/16926">https://gitlab.kitware.com/cmake/cmake/issues/16926</a><br></div><div><br></div><div> </div></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr">Craig Scott<br><div>Melbourne, Australia</div><div><a href="https://crascit.com" target="_blank">https://crascit.com</a><br></div><div><br></div><div>New book released: <a href="https://crascit.com/professional-cmake/" target="_blank">Professional CMake: A Practical Guide</a><br></div></div></div></div></div></div></div></div></div>