<div dir="ltr">You can only add commands to a target that was defined in the current directory?  So, I would have to have a new target for each directory and then have a target that depends on all of those targets?</div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Apr 16, 2015 at 1:08 PM, Nils Gladitz <span dir="ltr"><<a href="mailto:nilsgladitz@gmail.com" target="_blank">nilsgladitz@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span>On 16.04.2015 22:01, Daniel Dilts wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid">
I have the following in my lists:<br>
if(TARGET CustomTarget)<br>
  message("TARGET CustomTarget")<br>
else()<br>
  message("NOT TARGET CustomTarget")<br>
endif()<br>
add_custom_command(TARGET CustomTarget PRE_BUILD<br>
  COMMAND CustomCommand.exe<br>
  USES_TERMINAL<br>
  )<br>
<br>
In my output I get:<br>
TARGET CustomTarget<br>
CMake Error at Some/Path/CMakeLists.txt:52 (add_custom_command<br>
):<br>
  The target name "CustomTarget" is unknown in this context.<br>
<br>
It seems like the if() shows that there is a target with the desired name.  Am I missing something?<br>
</blockquote>
<br></span>
You can only modify a target after it has been defined and in the directory (CMakeLists.txt) that defined it.<br>
The same goes for appending commands to targets.<span class="HOEnZb"><font color="#888888"><br>
<br>
Nils<br>
<br>
</font></span></blockquote></div><br></div>