<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">On 3/28/2019 3:33 PM, Kyle Edwards
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:1553801586.3145.8.camel@kitware.com">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
Using the DEPENDS argument of add_custom_command() will do this.
However, add_custom_command() on its own isn't enough to ensure
that the file is generated before installation. You need to pair
add_custom_command() with add_custom_target(). Example:
<div><br>
</div>
<div><span style="color: rgb(0, 0, 0);">add_custom_command(</span><br
style="color: rgb(0, 0, 0);">
<span style="color: rgb(0, 0, 0);"> OUTPUT mygeneratedfile</span><br
style="color: rgb(0, 0, 0);">
<span style="color: rgb(0, 0, 0);"> COMMAND mytool -o
mygeneratedfile</span><br style="color: rgb(0, 0, 0);">
<span style="color: rgb(0, 0, 0);"> DEPENDS mysourcefile</span><br
style="color: rgb(0, 0, 0);">
<span style="color: rgb(0, 0, 0);">)</span></div>
<div><span style="color: rgb(0, 0, 0);">add_custom_target(mygeneratedtarget</span></div>
<div><span style="color: rgb(0, 0, 0);"> DEPENDS mygeneratedfile</span></div>
<div><span style="color: rgb(0, 0, 0);">)</span></div>
<div><span style="color: rgb(0, 0, 0);"><br>
</span></div>
<div><span style="color: rgb(0, 0, 0);">This is different from:</span></div>
<div><span style="color: rgb(0, 0, 0);"><br>
</span></div>
<div><span style="color: rgb(0, 0, 0);">add_custom_target(mygeneratedtarget</span></div>
<div><span style="color: rgb(0, 0, 0);"> COMMAND mytool -o
mygeneratedfile</span></div>
<div><span style="color: rgb(0, 0, 0);"> BYPRODUCTS
mygeneratedfile</span></div>
<div><span style="color: rgb(0, 0, 0);"> DEPENDS mysourcefile</span></div>
<div><span style="color: rgb(0, 0, 0);">)</span></div>
<div><span style="color: rgb(0, 0, 0);"><br>
</span></div>
<div><span style="color: rgb(0, 0, 0);">because it will only run
mytool when it needs to (when mysourcefile has changed).</span></div>
<br>
</blockquote>
<p>Kyle,</p>
<p>What you say makes sense, and I can even understand why
add_custom_target might do that, but I cannot get this to actually
work. Here is a minimal CMakeLists.txt. mysourcefile is just and
empty file.</p>
<p>I have these files in test/cmake, and I:</p>
<blockquote>
<p>cd test<br>
mkdir build-cmake<br>
cd build-cmake<br>
cmake ../cmake<br>
make</p>
</blockquote>
<p>and there is no sign of mygeneratedfile. I then try</p>
<blockquote>
<p>make install</p>
</blockquote>
<p>and I get:</p>
<blockquote>
<p>$ make install<br>
Install the project...<br>
-- Install configuration: ""<br>
CMake Error at cmake_install.cmake:31 (file):<br>
file INSTALL cannot find
"/home/nort/test/build-cmake/mygeneratedfile".<br>
<br>
<br>
make: *** [Makefile:84: install] Error 1<br>
</p>
</blockquote>
Where is my mistake?<br>
<p><br>
</p>
<p><br>
</p>
</body>
</html>